zoukankan      html  css  js  c++  java
  • selenium python bindings 写测试用例

    这章总结selenium在UI测试方面的用法

    import unittest
    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
    
    class PythonOrgSearch(unittest.TestCase):
    
        def setUp(self):
            self.driver = webdriver.Firefox()
    
        def test_search_in_python_org(self):
            driver = self.driver
            driver.get("http://www.python.org")
            self.assertIn("Python", driver.title)
            elem = driver.find_element_by_name("q")
            elem.send_keys("pycon")
            elem.send_keys(Keys.RETURN)
            assert "No results found." not in driver.page_source
    
    
        def tearDown(self):
            self.driver.close()
    
    if __name__ == "__main__":
        unittest.main()
    

     首先创建一个类 PythonOrgSearch ,其中 test_search_in_python_org 方法中写的是一个测试用例,像JUnit中@before@after一样的作用,可以用setUp和tearDown函数。这两个函数分别表示在每个测试用例执行前需要做的操作和执行后需要做的操作。不用在每个测试用例中都进行声明,只要写在两个函数中就会自动调用

    参考 http://selenium-python.readthedocs.io/navigating.html

  • 相关阅读:
    UML类图基础说明
    grep: /usr/include/php/main/php.h: No such file or directory
    活在幻梦中的你我
    Markdown语法笔记
    眼见为实
    潜意识与暗示
    蝌蚪与青蛙是同一个物种么?
    PHP 数组函数整理
    git 笔记
    vue2.0-组件传值
  • 原文地址:https://www.cnblogs.com/chercher/p/5593891.html
Copyright © 2011-2022 走看看