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

  • 相关阅读:
    php 异步执行脚本
    微信扫描带参数二维码事件
    windows7搭建wnmp环境
    Windows下安装Redis及php的redis拓展教程
    英语翻译(一维map)
    转圈游戏
    蓝桥杯剪邮票
    再谈组合
    关于inf设置为0x3f3f3f3f
    枚举排列组合(dfs)
  • 原文地址:https://www.cnblogs.com/chercher/p/5593891.html
Copyright © 2011-2022 走看看