data.json
[
["https://mail.163.com/","XXX010203","XXXbb22!!"] --使用自己账户名和密码
]
test_LoginPage_Out.py
import unittest
from selenium import webdriver
from xtext.runner import main
from xtext.data import file_data,date_class
from xtext.LoginPage import LoginPage
class Testemial163_Test(unittest.TestCase):
def setUp(self):
self.driver=webdriver.Chrome()
@file_data("data.json",2)
def test_email_login_scccess(self,URL_IP_Port,username,password):
loginPage=LoginPage(self.driver)
loginPage.goto163HomePage(URL_IP_Port)
loginPage.input_username_test(username)
loginPage.input_password_test(password)
loginPage.click_login_button()
def tearDown(self):
pass
# if __name__ == '__main__':
# main(path=r"D:\\github\\xtext\\163email\\",browser="Chrome",timeout=20) #代表该执行文件的目录路径
#
# if __name__ == '__main__':
# BasePage.main(path=r"D:\\github\\xtext\\163email\\",browser="Chrome",timeout=20) #代表该执行文件的目录路径
if __name__ == "__main__":
unittest.main()
__init__.py
from .data import data,file_data,date_class
from .LoginPage import LoginPage
from .locators import *
from .runner import main
BasePage.py
from .config import XTest
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.webdriver import ActionChains
from selenium.common.exceptions import NoSuchElementException
LOCATOR_LIST = {
'css': By.CSS_SELECTOR,
'id_': By.ID,
'name': By.NAME,
'xpath': By.XPATH,
'link_text': By.LINK_TEXT,
'partial_link_text': By.PARTIAL_LINK_TEXT,
'tag': By.TAG_NAME,
'class_name': By.CLASS_NAME,
}
browser_list=["Chrome","Firefox"]
class BasePage(object):
def __init__(self, driver):
self.driver = driver
# self.URL_IP_Port = URL_IP_Port
# 元素定位的封装方法2:按照动作分
def __find_element(self, index, **kwargs):
'''
定位元素
:param kwargs:
:return:
'''
if not kwargs:
raise ValueError("Please specify a locator")
if len(kwargs) > 1:
raise ValueError("Please specify only one locator")
by, value = next(iter(kwargs.items())) # 取值
try:
LOCATOR_LIST[by]
except KeyError:
raise ValueError("Element type is not support")
if by == "id_":
if index is None:
self.__wait_element(By.ID, value)
elem = self.driver.find_elements(By.ID, value)
elif by == "name":
if index is None:
self.__wait_element(By.NAME, value)
elem = self.driver.find_elements(By.NAME, value)
elif by == "class_name":
if index is None:
self.__wait_element(By.CLASS_NAME, value)
elem = self.driver.find_elements(By.CLASS_NAME, value)
elif by == "tag":
if index is None:
self.__wait_element(By.TAG_NAME, value)
elem = self.driver.find_elements(By.TAG_NAME, value)
elif by == "xpath":
if index is None:
self.__wait_element(By.XPATH, value)
elem = self.driver.find_elements(By.XPATH, value)
elif by == "link_text":
if index is None:
self.__wait_element(By.LINK_TEXT, value)
elem = self.driver.find_elements(By.LINK_TEXT, value)
elif by == "partial_link_text":
if index is None:
self.__wait_element(By.PARTIAL_LINK_TEXT, value)
elem = self.driver.find_elements(