# Generated by Selenium IDE
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
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
# 登录 异常用例数据驱动DDT
class Test():
def setup_method(self, method):
self.driver = webdriver.Chrome(executable_path="D:/bangong/py/chromedriver.exe")
self.vars = {}
def teardown_method(self, method):
self.driver.quit()
@pytest.mark.parametrize("username", ["蕾蕾", "账号超过15个字符1234567", " "]) # 数据驱动DDT:把数据当做用例执行
@pytest.mark.parametrize("password", ["abc123456", "1234567890abcdefghijk", " "])
def test_(self, username, password):
self.driver.implicitly_wait(10)
self.driver.get("http://127.168.8.136:8080/")
self.driver.set_window_size(1936, 1072)
self.driver.find_element(By.CSS_SELECTOR, ".domain-container").click()
self.driver.find_element(By.NAME, "username").send_keys(username) # 传参
self.driver.find_element(By.NAME, "password").click()
self.driver.find_element(By.NAME, "password").send_keys(password) # 传参
self.driver.find_element(By.CSS_SELECTOR, ".btn > span").click()
# assert self.driver.find_element(By.CSS_SELECTOR, ".avatar-wrapper > span").text == "蕾蕾"
# self.driver.find_element(By.CSS_SELECTOR, ".el-icon-caret-bottom").click()
# self.driver.find_element(By.CSS_SELECTOR, ".logout > span").click()
# self.driver.close()
"""
注意:
1.driver驱动版本是否匹配
2.使用驱动手动加上驱动路径executable_path=“”,不然报错找不到元素
3.添加DDT数据驱动固定格式 @pytest.mark.parametrize()
"""
# Generated by Selenium IDE
import pytest
from time import sleep
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
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
class Test():
def setup_method(self, method):
self.driver = webdriver.Chrome()
self.vars = {}
def teardown_method(self, method):
self.driver.quit()
def test_(self):
# driver_path = r"D:\bangong\py\chromedriver.exe"
# self.driver = webdriver.Chrome(executable_path=driver_path)
self.driver.implicitly_wait(10)
# 上面告诉计算机去打开谷歌浏览器
self.driver.get("http://127.0.0:9124/")
self.driver.set_window_size(1936, 1072)
self.driver.find_element(By.CSS_SELECTOR, ".ant-row:nth-child(1) .ant-input").click()
self.driver.find_element(By.CSS_SELECTOR, ".ant-row:nth-child(1) .ant-input").send_keys("13226319497")
self.driver.find_element(By.CSS_SELECTOR, ".ant-input-password > .ant-input").click()
self.driver.find_element(By.CSS_SELECTOR, ".ant-input-password > .ant-input").send_keys("abc123456")
self.driver.find_element(By.CSS_SELECTOR, ".login-btn").click()
element = self.driver.find_element(By.CSS_SELECTOR, ".login-btn")
actions = ActionChains(self.driver)
actions.move_to_element(element).perform()
assert self.driver.find_element(By.CSS_SELECTOR, ".name").text == "蕾蕾(后)"
self.driver.find_element(By.CSS_SELECTOR, ".ant-dropdown-menu-item-active > span").click()
self.driver.close()
Test().test_()