current position:Home>Python UI automated testing

Python UI automated testing

2022-02-02 15:07:36 Panda code

selenium+unittest package , To do it ui automated testing . API/DEMO:selenium-python Chinese document (opens new window) | seleniumbase( be based on selenium encapsulation ) (opens new window) | demo project (opens new window)

# understand

Similar to reptiles , adopt html The way of source code , Snap to corresponding label , Then click through the browser event 、 Input box input 、 Double click and so on , Finalized Open the browser - Auto click / Input operation - Close the browser , This series of operations .

# demo

# coding=utf-8

from selenium import webdriver
import unittest, time
from utils.log import logger

class BaiduTest(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome("/Library/work/workspace-my/python/chromedriver")
        self.driver.implicitly_wait(30) # The implicit waiting time is 30 second 
        self.base_url = "https://www.baidu.com"
    
    def test_baidu(self):
        driver = self.driver
        driver.get(self.base_url + "/")
        driver.find_element_by_id("kw").clear()
        logger.info("Input search str")#Print input unittest
        driver.find_element_by_id("kw").send_keys("unittest")
        driver.find_element_by_id("su").click()
        time.sleep(3)
        title=driver.title
        self.assertEqual(title, "unittest_ Baidu search ") 

    def tearDown(self):
        self.driver.quit()

if __name__ == "__main__":
    unittest.main()

copyright notice
author[Panda code],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/02/202202021507344875.html

Random recommended