Selenium and automated testing

\u674e\u80b2\u6b22 2021-11-25 14:31:58

One . The concept of automated testing

1. What is automated testing

Automated testing refers to the automation of software testing , Run the application or system in the preset state , Preset conditions include normal and abnormal , Finally, evaluate the operation results , The process of transforming human driven test behavior into machine execution

2. Introduction to common automated test tools

1.Selenium( important !!!)

Selenium It's a web Automated test tool
Its main advantages :

  • free , Open source , light
  • Support for multiple languages :Java ,C#,python,ruby
  • Support for multiple platforms :Chrome,IE,Firefox,Safari,edge,Opera, Different operating systems
  • Support distributed

2.jmeter

Performance testing tools , Interface test can be carried out

3.loadrunner

Performance testing tools

4.soupui,postman

The interface test

5.appium

APP automated testing (IOS,Andrio),Macaca( Ali )

3. The difference between automation tools and automation frameworks

Automated testing framework can generally be divided into two levels

  • The upper layer is to manage the development of the whole automatic test , Perform... And maintenance , In a relatively large project , It plays an important role , He can manage the entire automated test , Including the sequence of automated test case execution , Maintenance of test scripts , And several management test cases , Test report and test task, etc
  • The lower layer is mainly the development of test scripts , Make full use of relevant testing tools , Build test driven , And complete the test business logic

4. The evolution of automated testing

Testing tools —> Data driven —> Keyword Driven —> The test framework —> Test platform

5. Automated test methods

  • Test object :UI, Interface , Code
  • Testing process : The system test , Integration testing , unit testing
  • Executive : Testers , Developer

Be careful :

  • Automated testing can be implemented at any stage of the entire testing process , The premise function is relatively stable
  • Testers usually perform automated testing during system testing
  • In the integration test phase, automatic construction is often carried out , Deploy , And automation of smoke testing
  • Unit testing tests at the code level , You can check static code , Or execute unit test cases , Typical frameworks, such as junit,jmock etc. , This part is mostly implemented by developers

6.UI Automation and interface automation

1.UI automation

implementation phase : After the front-end development is completed

  • The maintenance of use cases is large
  • Ye Nian has a strong correlation , Must intervene later
  • UI The test is suitable for projects with small interface changes

2. Interface automation

implementation phase : After the completion of the back-end test method ( The function is relatively stable )

  • Can intervene in the early stage of the product
  • Use case maintenance is small
  • Page relevance is small
  • Suitable for small interface changes , Items with frequent interface changes

7. The advantages of automated testing

Reduce the manpower investment of large-scale system due to change or multi-phase development , This is probably the main task of automated testing , Especially when the program is modified frequently , The effect is very obvious , There is a lot of manpower investment in the early stage of automatic testing , But after entering the maintenance period later , It can save a lot of manpower , In the later stage of manual testing, a lot of manpower needs to be added for regression testing

  • Reduce the time to repeat tests , Achieve rapid regression testing
  • Create a good and reliable test process , Reduce human error
  • You can run more and more tedious tests
  • You can perform tests that are difficult or impossible to do by hand
  • Better use of resources
  • The test has consistency and repeatability
  • Test script reusability

Two . How to implement automated testing

1. Applicable objects of automated testing

Implement automated testing Prerequisite Demand changes infrequently 、 Project cycle long enough 、 Automated test scripts are reusable
1、 Projects with frequent demand changes , Automated scripts cannot be reused , Maintenance costs are too high , Low cost performance
2、 The project cycle is short , The automatic script is not used much after preparation , Low cost performance
3、 Projects with strong interaction , Projects requiring human intervention , Automation cannot be implemented
Suitable for automation projects :
1、 Product type project . Product based projects , The new version is an improvement on the old version , Items with little function , But the new and old functions of the project must
The regression test must be repeated . Regression testing is the strength of automated testing , It can be a good way to verify whether you have introduced new defects , Whether the old defect is repaired
It's changed . To some extent, automated testing tools can be called regression testing tools .
2、 Mechanical and frequent testing . You need to enter the same... Each time 、 A lot of data , And it takes a long time to run in a project

2. When to implement automated testing

 Insert picture description here

3. How to implement automated testing

Simply speaking , The concrete implementation of automated testing , It should include the following seven processes .

  1. analysis : Overall grasp the system logic , Analyze the core architecture of the system .
  2. Design : Design test cases , Test cases should be clear enough , Wide coverage and excellent
  3. Realization : Implementation script , There are two requirements. One is to assert , The second is the rational use of parameterization .
  4. perform : Executing scripts is far from as simple as we think . We need to carefully analyze the causes of exceptions during script execution .
  5. summary : Analysis of test results , And the summary of testing process is the key to automatic testing .
  6. maintain : The maintenance of automated test scripts is a difficult but necessary problem .
  7. analysis : In the process of automated testing, deeply analyze the coverage risk of automated use cases and the cost of script maintenance
     Insert picture description here

4. Failure factors in automated testing

  • Expectations are too high . Just as managers require complete testing , expect 100% Test automation , It is also an unrealistic demand .
     Insert picture description here

  • Unclear understanding of benefits and costs . Regardless of the development or purchase cost of tools and training cost , The cost of automated testing should also include two parts ( The test preparation cost is also implied in the implementation cost ):
    cost = Realize the cost + Operation and maintenance costs
    The benefit of automated testing is determined by the number of repeated runs of the test script , Or the utilization of automated test scripts

5. The skills needed to automate testing

  • Understand the basic business
  • Understand the technical framework of the business
  • Understand functional testing
  • Know a programming language
  • I know the database 、 operating system
  • Learn about common test frameworks

3、 ... and .Selenium Toolset

1.selenium1:selenium RC,selenium IDE( Record automated test scripts ),selenium DRID( Distributed )
2.selenium 2:webdriver(Google)
3.selenium3: Added some native drivers for browsers ,Safari,edge(MS)

Four .Webriver principle

 Insert picture description here
 Insert picture description here

WebDriver Launch the target browser , And bind to the specified port . The browser instance that should be started , As web driver Of remoteserver.
Client End pass CommandExcuter send out HTTPRequest to remote server The listening port of ( Communication protocol : thewebriver wire protocol)
Remote server Need to rely on native browser components ( Such as :IEDriverServer.exe、chromedriver.exe), To transform the browser native call .

5、 ... and . Use IDE Recording script

1. preparation

1、 install Firefox 17.0 - 40.*
because firefox Update too fast ,selenium Different versions of firefox Different support for .
Be careful , After installation , Cancel automatic update in the options menu . For compatibility selenium as well as ide, It is recommended to use 54 edition .
Download address :http://ftp.mozilla.org/pub/firefox/releases/
2、 install selenium IDE
Download address :https://addons.mozilla.org/enUS/firefox/addon/selenium-ide/
https://addons.mozilla.org/en-GB/firefox/addon/selenium-ide/versions/
Be careful :IDE It is only used as an auxiliary tool to quickly generate use cases or personal tests . In practice, it is rarely used to manage automated test cases and execute .
Take the Zen path installed on this machine as an example IDE Use .

2. Detailed use

1、 open Firefox- Tools - choice selenium ide
2、 Click on File menu , Pop up the drop-down list , choice New Test Case, At this time, the middle left Test Case The window will add a Untitle 2 Test case
example , Right click on the ’Property’, Rename to... In the pop-up window ”TestDemo”
3、 Click on IDE Record button on the upper right of the ( Little red dot ) Start manual recording
4、 Enter the web address to be tested in the address bar ( ZenTao ) Such as http://127.0.0.1, Enter your username and password , Log in . Now you can see IDE Recording operation was performed .
5、 Right click on the page , You can add checkpoints .
6、 After recording , Click the record button ( Little red dot ), End this manual recording . stay selenium IDE in , Choose one Test Case, Click on
File menu , Select... From the drop-down list “Export Test Case As”-“python2/ unittest/ WebDriver”; Export to Testdemo.py file .
7、 Put the script in python Run and debug .

Please bring the original link to reprint ,thank
Similar articles