Commit ae86963a by zhangying

Merge remote-tracking branch 'origin/master'

parents e8afe595 85c8cc14
......@@ -6,7 +6,11 @@ browserName = Chrome
[testServer]
#调试客户端本地文件路径
app_location = C:\Users\Administrator\AppData\Local\Programs\xmqxy\小麦企学院.exe
win_app_location = C:\Users\Administrator\AppData\Local\Programs\xmqxy\小麦企学院.exe
mac_app_location = /Applications/小麦企学院.app/Contents/MacOS/小麦企学院
[testEnv]
env = prod
[account]
# 白名单账号
......
import configparser
import os
import platform
config = configparser.ConfigParser()
......@@ -9,12 +10,24 @@ config.read(dir + "/config/config.ini", encoding='utf-8')
# 根据配置文件获取测试url
def test_location():
location = config.get("testServer", "app_location")
return location
current_platform = platform.system().lower()
if current_platform == "windows":
location = config.get("testServer", "win_app_location")
return location
elif current_platform == "darwin":
location = config.get("testServer", "mac_app_location")
return location
# 获取测试的环境
def get_env():
env = config.get("testEnv", "env")
return env
def test_account():
return config.get("account", "username")
def test_password():
return config.get("account", "password")
\ No newline at end of file
import os
import platform
from time import sleep, time
from src.framework.common import file_abspath
......@@ -9,7 +10,12 @@ from selenium.webdriver.chrome.webdriver import WebDriver
# web_driver_path = os.path.join(
# "./chromedriver")
service = webdriver.chrome.service.Service(file_abspath() + "/tools/chromedriver.exe")
if platform.system().lower() == "windows":
service = webdriver.chrome.service.Service(file_abspath() + "/tools/chromedriver.exe")
elif platform.system().lower() == "darwin":
service = webdriver.chrome.service.Service(file_abspath() + "/tools/chromedriver")
os.system('chmod 777 {}'.format(file_abspath() + "/tools/chromedriver"))
service.start()
......
from time import sleep
import platform
from config import readConfig
......@@ -72,10 +73,23 @@ class Page(object):
def sleep(self, seconds):
return sleep(seconds)
# 查找文本,点击该文本元素
def click_text(self, text):
self.click((By.XPATH, """//span[text()="{}"]""".format(text)))
# 键盘down
def keys_down(self):
ActionChains(self.driver).key_down(Keys.DOWN).key_up(Keys.DOWN).perform()
# 键盘ctrl+M,command+m
def get_env_window(self):
if platform.system().lower() == "windows":
ActionChains(self.driver).send_keys(Keys.CONTROL, "m").perform()
elif platform.system().lower() == "darwin":
ActionChains(self.driver).send_keys(Keys.COMMAND, "m").perform()
# self.driver.find_element(By.XPATH, "//div[@class='title']").send_keys(Keys.COMMAND, "m")
# ActionChains(self.driver).key_down(Keys.COMMAND).send_keys("M").key_up(Keys.COMMAND).perform()
# 屏幕最大化
def max(self, *loc):
self.driver.find_element(*loc).click()
......@@ -114,6 +128,10 @@ class Page(object):
def switch_to_current(self):
self.driver.switch_to.default_content()
# 操作脚本
def excute_script(self, loc):
self.driver.execute_script("document.getElementsByClassName('{}')[0].style.position = 'static'".format(loc))
# 切换窗口,切换到存在loc元素的窗口
def change_window(self, loc):
driver = self.driver
......@@ -127,15 +145,20 @@ class Page(object):
def login(self):
driver = self.driver
login_page = Page(driver=driver)
# 手机号登录按钮
phone_login = (By.ID, "rc-tabs-0-tab-2")
# # 手机号登录按钮
# phone_login = (By.ID, "rc-tabs-0-tab-2")
# 账号输入框
account_input = (By.ID, "xmphone")
# 密码输入框
password_input = (By.ID, "xmpwd")
# 登录按钮
login_button = (By.CLASS_NAME, "submit")
login_page.click(phone_login)
# login_page.click(phone_login)
env = readConfig.get_env()
login_page.get_env_window()
login_page.click_text(env)
login_page.excute_script("form xm_phone_login")
login_page.sleep(2)
login_page.input_text(account_input, readConfig.test_account())
login_page.input_text(password_input, readConfig.test_password())
login_page.click(login_button)
......
......@@ -37,3 +37,8 @@ class LoginPage(Page):
# 点击登录
def click_login(self):
self.click(self.login_button)
# 手机号码登录窗口可显示操作
def phone_input_execute_script(self):
self.excute_script("form xm_phone_login")
......@@ -79,9 +79,6 @@ class MainPage(LoginPage):
def stop_live(self):
self.click(self.stop_live_btn)
def get_live_name(self):
self.keys_down()
# 获取按钮文本
def get_btn_text(self, coursename):
self.in_live_btn = (By.XPATH, """//div[text()="{}"]/..//button[@class="ant-btn"]""".format(coursename))
......
......@@ -14,6 +14,7 @@ class TestLoginPage(object):
self.account = readConfig.test_account()
self.password = readConfig.test_password()
cloud_class_location = readConfig.test_location()
self.env = readConfig.get_env()
# 指定客户端的本地路径,在/config/config.ini配置
self.driver = get_app_driver(cloud_class_location)
yield self.driver
......@@ -23,11 +24,16 @@ class TestLoginPage(object):
@pytest.mark.usefixtures("before_test_case")
def testLogin(self):
login_page = LoginPage(driver=self.driver)
login_page.click_phone_login()
login_page.get_env_window()
login_page.sleep(2)
login_page.click_text(self.env)
login_page.phone_input_execute_script()
login_page.sleep(2)
# login_page.click_phone_login()
login_page.input_account(account=self.account)
login_page.input_password(password=self.password)
login_page.click_login()
login_page.sleep(1)
login_page.sleep(5)
# 校验是否存在店铺名称的元素
assert login_page.ifElementExist(login_page.store_name)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment