import pytest import time import json from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.support import expected_conditions from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.common.keys import Keys method=1 class TestUntitled(): def setup_method(self, method): self.driver = webdriver.Firefox() self.vars = {} def teardown_method(self, method): self.driver.quit(); def test_untitled(self): # Test name: Untitled # Step # | name | target | value | comment # 1 | open | / | | self.driver.get("https://www.taobao.com/") # 2 | setWindowSize | 1801x695 | | self.driver.set_window_size(1801, 695) # 3 | mouseOver | css=#J_SiteNavSeller a > span | | element = self.driver.find_element(By.CSS_SELECTOR, "#J_SiteNavSeller a > span") actions = ActionChains(driver) actions.move_to_element(element).perform() # 4 | click | linkText=亲,请登录 | | self.driver.find_element(By.LINK_TEXT, "亲,请登录").click() # 5 | click | css=.ph-label | | self.driver.find_element(By.CSS_SELECTOR, ".ph-label").click() # 6 | type | id=TPL_username_1 | 15850790853 | self.driver.find_element(By.ID, "TPL_username_1").send_keys("19999999999") # 7 | click | id=TPL_password_1 | | self.driver.find_element(By.ID, "TPL_password_1").click() # 8 | mouseOver | id=J_SubmitStatic | | element = self.driver.find_element(By.ID, "J_SubmitStatic") actions = ActionChains(driver) actions.move_to_element(element).perform() # 9 | type | id=TPL_password_1 | woben123 | self.driver.find_element(By.ID, "TPL_password_1").send_keys("123456") # 10 | click | id=J_SubmitStatic | | self.driver.find_element(By.ID, "J_SubmitStatic").click() # 11 | mouseOver | css=.item-1 | | element = self.driver.find_element(By.CSS_SELECTOR, ".item-1") actions = ActionChains(driver) actions.move_to_element(element).perform() # 12 | click | id=q | | self.driver.find_element(By.ID, "q").click() # 13 | type | id=q | 1 | self.driver.find_element(By.ID, "q").send_keys("1") # 14 | click | css=.btn-search | | self.driver.find_element(By.CSS_SELECTOR, ".btn-search").click() if __name__=='__main__': TestUntitled().setup_method(method) time.sleep(1) TestUntitled().test_untitled() TestUntitled().teardown_method(method)
####调用类里面的方法如果方法带self,最后调用时要类后面加()
TestUntitled().test_untitled() 带参数的参数也必须加上
TestUntitled().setup_method(method)