当前位置:网站首页>Still worrying about how to write web automation test cases? Senior test engineers teach you selenium test case writing hand in hand

Still worrying about how to write web automation test cases? Senior test engineers teach you selenium test case writing hand in hand

2022-07-06 06:15:00 The elegance of testing

To write Selenium The test case is to simulate a series of operations of the user on the browser , Complete automated testing through scripts .

Advantages of writing test cases :

  • Open source , free .

  • Support multiple browsers IE,Firefox,Chrome,Safari.

  • Support for multiple platforms Windows,Linux,Mac.

  • Support for multiple languages Python,Java,C#.

  • Yes Web Good support .

  • Simple , flexible .

  • Support distributed test case execution .

Introduce dependencies

Dependency is introduced to call webdriver To interact with the browser to realize the operation steps .

  • Python edition
from selenium import webdriver

Flow of test cases

A test case is a set of sets provided to the system under test in order to implement the test , This set of collections contains : Test environment 、 Operation steps 、 Test data 、 Expected results, etc .

Be careful : The final result of a test case is only one : Success or failure .

The three core elements are : title 、 step 、 Expected results

  • title : Is a description of the test case , The title should clearly express the content of the test case
  • step : Describe the test execution process
  • Expected results : Provide the expected results of test execution , The expected results are generally based on demand , If the actual results are consistent with the expected results, the test passes , On the contrary, failure .

Practical drill

The first is to import... At the top of the code Selenium My bag , The second is the naming of test methods 、 testing procedure 、 Assertion . The content of the test case is to assert whether the content displayed by opening Baidu page is equal to the expected value .

Python edition

from selenium import webdriver

#  The title of the test is  test_search
def test_search():
    driver = webdriver.Chrome()
    #  Test steps 
    driver.get('https://www.baidu.com')
    search = driver.find_element_by_id('su').get_attribute('value')
    #  Assert the expected result 
    assert search == " Baidu "

Here to assert whether the content displayed by opening Baidu page is equal to the expected value . Because the content actually obtained should be Baidu, not Baidu , So the assertion is wrong .

FAILED                                         [100%]
test_demo.py:3 (test_search)
 use Baidu Search  !=  Baidu 

Expected : Baidu 
Actual   : use Baidu Search 
<Click to see difference>

def test_search():
        driver = webdriver.Chrome()
        driver.get('https://www.baidu.com')
        search = driver.find_element_by_id('su').get_attribute('value')
>       assert search == " Baidu "
E       AssertionError: assert ' use Baidu Search ' == ' Baidu '
test_demo.py:9: AssertionError

Last : It can be in the official account : Sad spicy bar ! Get one by yourself 216 Page software testing engineer interview guide document information 【 Free of charge 】. And the corresponding video learning tutorial is free to share !, It includes basic knowledge 、Linux necessary 、Shell、 The principles of the Internet 、Mysql database 、 Special topic of bag capturing tools 、 Interface testing tool 、 Test advanced -Python Programming 、Web automated testing 、APP automated testing 、 Interface automation testing 、 Testing advanced continuous integration 、 Test architecture development test framework 、 Performance testing 、 Safety test, etc. .

I recommend one 【Python Automated test communication group :746506216】, We can discuss communication software testing together , Learn software testing together 、 Interview and other aspects of software testing , Help you advance quickly Python automated testing / Test Development , On the road to high pay .

Friends who like software testing , If my blog helps you 、 If you like my blog content , please “ give the thumbs-up ” “ Comment on ” “ Collection ” One Key triple connection !

原网站

版权声明
本文为[The elegance of testing]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060606580174.html