unittest简单实例

```

# -*- coding:utf-8 -*-
import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

class PythonOrgSearch(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome()

    def test_login(self):
        driver = self.driver
        driver.get("http://opsadmin.nj.com/")
        self.assertIn("OPSAdmin", driver.title)
        input_name = driver.find_element_by_id("id_username")
        input_name.send_keys("admin")
        input_passwd = driver.find_element_by_id("id_password")
        input_passwd.send_keys("123456789")

        # 第一种登录方式,点击登录按钮元素
        # click = driver.find_element_by_class_name("btn-primary")
        # click.click()
        # 第二种登录方式,调用RETURN登录
        input_passwd.send_keys(Keys.RETURN)
        assert "No results found." not in driver.page_source


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

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

```

你可能感兴趣的:(自动化测试)