Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize selenium UI Automation

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "how to achieve selenium UI automation". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

one。 Preface 1.1 Project Framework

How the project uses the framework: this project uses the unitest framework

How to apply the design pattern: this project adopts the pageobject design pattern

The thought of UI object library

Project design

A module (the page of the project under test) corresponds to a py file and a test class (test file)

Each test page (the page of the system) stores page elements and the functions involved in this page

Each use case is combined into a test class to generate a py file

Project goal

When we write an automated test project, we must think about the functions of your script, whether a large number of scripts need to be modified when page elements are changed, and whether scripts should be modified when testing different data. So we can think of these initial goals are almost there.

1. Generate test case execution results report

two。 Generate test case execution log

3. Use case execution fails or automatically sends an e-mail report after the execution is completed

Capture the picture when the use case execution fails or succeeds

5. Data driven (reading test data, reducing script maintenance costs)

1.2 Project directory structure

Retail_TestPro

Docs# stores documents related to the project

01 test plan

02 Test outline

03 test case

04 test report

05 test progress

06 technical documentation

07 test application

Package# stores third-party plug-ins

HTMLTestRunner.py

Retail

Config

_ _ init__.py

Conf.py# read the configuration file to get the project and directory paths and get the paths to all the directory files you want to use

The path where Config.ini# stores projects and directories

Data

TestData

_ _ init__.py

ElementDate.xlsx# stores all the element information and test data in the project.

Email_receiver.txt# stores the recipient information of email

Report# test report

Image

Fail# stores screenshots of failed use case execution

Pass# stores screenshots of successful use case execution.

Log# stores log information during the execution of the use case

TestReport# stores the test report generated after the test case execution is completed.

Test_case# test case information

Models # stores some public methods

Doconfini.py# read profile

Doexcel.py# reads excel files

Driver.py# stores driver

Log.py# generates log

Myunit.py# inherits unittest.Testcase

Sendmail.py# sends mail

Strhandle.py# string processing

Basic information of Tcinfo.py# test cases

Testreport.py# test report

Page_obj# test module

Activerule_page.py

Base_page.py

Company_page.py

Createrule_page.py

Memberquery_page.py

Modifypw_page.py

Pointquery_page.py

ActiveRuleTc.py

CompanyQueryTc.py

CreateRuleTc.py

LoginTc.py

MemberQueryTc.py

ModifyPwTc.py

PointQueryTc.py

RunTc.py# executes test cases

< 4 and item[2] !='': # 新密码长度校验 text = menu.errorDialog(menu.closeBtn) try: self.assertEqual('密码长度至少 4 位!',text,'the message incorrect!') except Exception: menu.saveScreenShot('fail_密码长度.png') raise elif item[0] != '' and len(item[1]) >

= 4 and item [2]! ='': # New password strength check ['qwert',' qwert'], lowercase, uppercase, number Other=strhandle (item [1]) if lowercase > 0 and uppercase > 0 and number = = 0 and other= = 0: # lowercase text = menu.errorDialog (menu.closeBtn) self.assertIn ('password strength is not strong enough Please re-enter the password!' , text, 'password strength is not enough, please re-enter the password!') Elif uppercase > 0 and other > 0 and number = = 0 and lowercase = = 0: # uppercase special character text = menu.errorDialog (menu.closeBtn) self.assertIn ('password is not strong enough, please re-enter the password!' , text, 'password strength is not enough, please re-enter the password!') Elif lowercase > 0 and other > 0 and number = = 0 and uppercase = = 0: # lowercase special character text = menu.errorDialog (menu.closeBtn) self.assertIn ('password is not strong enough, please re-enter the password!' , text, 'password strength is not enough, please re-enter the password!') Elif lowercase = = 0 and other = = 0 and number > 0 and uppercase > 0: # uppercase text = menu.errorDialog (menu.closeBtn) self.assertIn ('password is not strong enough, please re-enter the password!' , text, 'password strength is not enough, please re-enter the password!') Elif lowercase > 0 and other = = 0 and number > 0 and uppercase = 0: # lowercase digit text = menu.errorDialog (menu.closeBtn) self.assertIn ('password strength is not strong enough, please re-enter the password!' , text, 'password strength is not enough, please re-enter the password!') Elif lowercase > 0 and other = = 0 and number = = 0 and uppercase = = 0: text = menu.errorDialog (menu.closeBtn) self.assertIn ('password strength is not enough, please re-enter the password!' , text, 'password strength is not enough, please re-enter the password!') Elif lowercase = = 0 and other > 0 and number = = 0 and uppercase = = 0: text = menu.errorDialog (menu.closeBtn) self.assertIn ('password strength is not enough, please re-enter the password!' , text, 'password strength is not enough, please re-enter the password!') Elif lowercase = = 0 and other = = 0 and number > 0 and uppercase = = 0: text = menu.errorDialog (menu.closeBtn) self.assertIn ('password strength is not enough, please re-enter the password!' , text, 'password strength is not enough, please re-enter the password!') Elif lowercase = = 0 and other = = 0 and number = = 0 and uppercase > 0: text = menu.errorDialog (menu.closeBtn) self.assertIn ('password strength is not enough, please re-enter the password!' , text, 'password strength is not enough, please re-enter the password!') Elif item [0]! = 'qwert1234 lowercase' and item [1] = = item [2]: # > = 4 lowercase, uppercase, number Other = strhandle (item [1]) if (lowercase > 0 and uppercase > 0 and number > 0) or (lowercase > 0 and uppercase > 0 and other > 0) or (number > 0 and other > 0 and lowercase > 0) or (number > 0 and other > 0 and uppercase > 0): text = menu.errorDialog (menu.closeBtn) self.assertIn ('old password entered incorrectly!' , text, 'old password entered incorrectly!') # New password and confirmation code do not assert the prompt message elif item [0] = = 'qwert1234 confirmation codes' and item [1]! = item [2]: # and item [1] > = 4: lowercase, uppercase, number Other = strhandle (item [1]) if (lowercase > 0 and uppercase > 0 and number > 0) or (lowercase > 0 and uppercase > 0 and other > 0) or (number > 0 and other > 0 and lowercase > 0) or ( Number > 0 and other > 0 and uppercase > 0): text = menu.errorDialog (menu.closeBtn) self.assertIn ('the new password entered twice is different!' , text, 'the new password entered twice is different!') Else: print ('test value incorrect! please check it') elif item [0] =''or item [1] =''or item [2] = ='': # input is empty check text = menu.errorDialog (menu.closeBtn) self.assertIn ('the value of this entry cannot be empty!' , text, 'the value of this entry cannot be empty!') # all passwords are empty assertion prompt else: self.assertTrue (menu.isElementExist (menu.errMessage), 'error fram not exist, please check the test value or file bug') if _ _ name__=='__main__': pass10.RunTc.py (execute test case) #! User/bin/python''Code description:auto run test case Create time: Developer:' 'import unittest import time from BeautifulReport import BeautifulReport from retail.config.conf import * from retail.test_case.models.testreport import testreport # TODO: will be use jenkins continuous intergration teachnology manage the auto project if _ _ name__ = =' _ _ main__': # currTime = time.strftime ('% Y-%m-%d% Houses% mom% S') # filename = currTime + '.html' # # the first test report # test_suite = unittest.defaultTestLoader.discover (tcPath Pattern='*Tc.py') # result = BeautifulReport (test_suite) # result.report (filename= filename, description='test report', log_path=reportPath) # # second test report runner, fp, fileName = testreport () test_suite = unittest.defaultTestLoader.discover (tcPath, pattern='LoginTc.py') runner.run (test_suite) fp.close () 11. Remarks

From BeautifulReport import BeautifulReport this report needs to be found online by yourself (many similar test report source codes, not necessarily using the report template in this case)

twelve。 Output result display

1. Take a screenshot when creating a rule fails

two。 Login successful screenshot

3. Use case execution log

4. Test report

This is the end of the content of "how to achieve selenium UI Automation". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report