import unittest
test_dir="./case2" #用例存放地址
ddd=unittest.defaultTestLoader.discover(test_dir,pattern='IDE*.py') #调用unittest.defaultTestLoader.discover,pattern=‘IDE*.py’ IDE*.py是用例前缀
runner=unittest.TextTestRunner() #run跑用例
runner.run(ddd)
IDE_1.py 用例文件
# -*- coding: utf-8 -*-
from selenium import webdriver
import unittest, time, re
class IDE1(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://www.oray.com/"
self.verificationErrors = []
self.accept_next_alert = True
def test_i_d_e1(self):
driver = self.driver
driver.get(self.base_url + "/")
driver.find_element_by_link_text(u"登录").click()
driver.find_element_by_id("account").clear()
driver.find_element_by_id("account").send_keys("chenhuatest")
driver.find_element_by_id("password").clear()
driver.find_element_by_id("password").send_keys("123456")
driver.find_element_by_css_selector("input.btn-red").click()
def tearDown(self):
print("login end")
# if __name__ == "__main__":
# unittest.main()
IDE_2.py用例文件
# -*- coding: utf-8 -*-
from selenium import webdriver
import unittest, time, re
class IDE2(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://www.oray.com/"
self.verificationErrors = []
self.accept_next_alert = True
def test_i_d_e2(self):
driver = self.driver
driver.get(self.base_url + "/")
driver.find_element_by_css_selector("#manage-center > a > span").click()
driver.find_element_by_xpath("//div/ul/li[2]/a/span").click()
driver.find_element_by_id("btn-add").click()
driver.find_element_by_name("name").clear()
driver.find_element_by_name("name").send_keys("testwq
testko
test")
driver.find_element_by_xpath("(//button[@type='submit'])[9]").click()
driver.find_element_by_id("remote-done-btn").click()
def tearDown(self):
print("IDE2 end")