Commit ddf2e2f9 by linguangwei

添加测试白板的page和testcase

parent e1ff8f18
......@@ -4,25 +4,12 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="00f4febb-36b6-426d-bfe6-b023876a617e" name="Default Changelist" comment="添加转换窗口方法">
<list default="true" id="00f4febb-36b6-426d-bfe6-b023876a617e" name="Default Changelist" comment="review">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/report/AI-XM_Report20210618182932.html" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/framework/logger.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/framework/logger.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pageobject/liveCourseTable/__init__.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/pageobject/liveCourseTable/classStatus.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/pageobject/liveCourseTable/enterClass.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/pageobject/liveCourseTable/startClass.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/pageobject/liveCourseTable/today.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/pageobject/liveCourseTable/weekDay.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/pageobject/liveCourseTable/weekName.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/pageobject/liveRoom/__init__.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/pageobject/liveRoom/coursewareTab.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/pageobject/liveRoom/roomName.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/pageobject/liveRoom/startPrompt.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/pageobject/mainpage.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/pageobject/mainpage.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/framework/common.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/framework/common.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pageobject/basepage.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/pageobject/basepage.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/testcase/testLoginPage.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/testcase/testLoginPage.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/testcase/testMainPage.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/testcase/testMainPage.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
......@@ -171,7 +158,7 @@
<recent name="C:\Users\Administrator\PycharmProjects\xm-uitest-live" />
</key>
</component>
<component name="RunManager" selected="Python.main">
<component name="RunManager" selected="Python tests.pytest for testWhiteBoardPage.TestLivePage.testWhiteBoard">
<configuration name="main" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="xm-uitest-live" />
<option name="INTERPRETER_OPTIONS" value="" />
......@@ -194,7 +181,7 @@
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="pytest for testLoginPage.TestLoginPage.testLogin" type="tests" factoryName="py.test" temporary="true" nameIsGenerated="true">
<configuration name="pytest for testLivePage.TestLivePage.testWhiteBoard" type="tests" factoryName="py.test" temporary="true" nameIsGenerated="true">
<module name="xm-uitest-live" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
......@@ -203,15 +190,14 @@
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="_new_keywords" value="&quot;&quot;" />
<option name="_new_parameters" value="&quot;&quot;" />
<option name="_new_additionalArguments" value="&quot;&quot;" />
<option name="_new_target" value="&quot;testLoginPage.TestLoginPage.testLogin&quot;" />
<option name="_new_target" value="&quot;testLivePage.TestLivePage.testWhiteBoard&quot;" />
<option name="_new_targetType" value="&quot;PYTHON&quot;" />
<method v="2" />
</configuration>
<configuration name="pytest for testMainPage.TestMainPage" type="tests" factoryName="py.test" temporary="true" nameIsGenerated="true">
<configuration name="pytest for testLoginPage.TestLoginPage.testLogin" type="tests" factoryName="py.test" temporary="true" nameIsGenerated="true">
<module name="xm-uitest-live" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
......@@ -220,15 +206,14 @@
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="_new_keywords" value="&quot;&quot;" />
<option name="_new_parameters" value="&quot;&quot;" />
<option name="_new_additionalArguments" value="&quot;&quot;" />
<option name="_new_target" value="&quot;testMainPage.TestMainPage&quot;" />
<option name="_new_target" value="&quot;testLoginPage.TestLoginPage.testLogin&quot;" />
<option name="_new_targetType" value="&quot;PYTHON&quot;" />
<method v="2" />
</configuration>
<configuration name="pytest for testMainPage.TestMainPage.test_2_StartLive" type="tests" factoryName="py.test" temporary="true" nameIsGenerated="true">
<configuration name="pytest for testWhiteBoardPage.TestLivePage.testWhiteBoard" type="tests" factoryName="py.test" temporary="true" nameIsGenerated="true">
<module name="xm-uitest-live" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
......@@ -237,15 +222,14 @@
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="_new_keywords" value="&quot;&quot;" />
<option name="_new_parameters" value="&quot;&quot;" />
<option name="_new_additionalArguments" value="&quot;&quot;" />
<option name="_new_target" value="&quot;testMainPage.TestMainPage.test_2_StartLive&quot;" />
<option name="_new_target" value="&quot;testWhiteBoardPage.TestLivePage.testWhiteBoard&quot;" />
<option name="_new_targetType" value="&quot;PYTHON&quot;" />
<method v="2" />
</configuration>
<configuration name="pytest for testMainPage.TestMainPage.test_4_StartLive" type="tests" factoryName="py.test" temporary="true" nameIsGenerated="true">
<configuration name="pytest in testLoginPage.py" type="tests" factoryName="py.test" temporary="true" nameIsGenerated="true">
<module name="xm-uitest-live" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
......@@ -254,21 +238,20 @@
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="_new_keywords" value="&quot;&quot;" />
<option name="_new_parameters" value="&quot;&quot;" />
<option name="_new_additionalArguments" value="&quot;&quot;" />
<option name="_new_target" value="&quot;testMainPage.TestMainPage.test_4_StartLive&quot;" />
<option name="_new_targetType" value="&quot;PYTHON&quot;" />
<option name="_new_target" value="&quot;$PROJECT_DIR$/src/testcase/testLoginPage.py&quot;" />
<option name="_new_targetType" value="&quot;PATH&quot;" />
<method v="2" />
</configuration>
<recent_temporary>
<list>
<item itemvalue="Python tests.pytest for testWhiteBoardPage.TestLivePage.testWhiteBoard" />
<item itemvalue="Python tests.pytest for testLivePage.TestLivePage.testWhiteBoard" />
<item itemvalue="Python.main" />
<item itemvalue="Python tests.pytest in testLoginPage.py" />
<item itemvalue="Python tests.pytest for testLoginPage.TestLoginPage.testLogin" />
<item itemvalue="Python tests.pytest for testMainPage.TestMainPage.test_2_StartLive" />
<item itemvalue="Python tests.pytest for testMainPage.TestMainPage.test_4_StartLive" />
<item itemvalue="Python tests.pytest for testMainPage.TestMainPage" />
</list>
</recent_temporary>
</component>
......@@ -361,7 +344,14 @@
<option name="project" value="LOCAL" />
<updated>1624012198851</updated>
</task>
<option name="localTasksCounter" value="11" />
<task id="LOCAL-00011" summary="review">
<created>1624067390535</created>
<option name="number" value="00011" />
<option name="presentableId" value="LOCAL-00011" />
<option name="project" value="LOCAL" />
<updated>1624067390535</updated>
</task>
<option name="localTasksCounter" value="12" />
<servers />
</component>
<component name="TestHistory">
......@@ -464,7 +454,8 @@
<MESSAGE value="同步" />
<MESSAGE value="登录-开课-结束课程-关闭客户端" />
<MESSAGE value="添加转换窗口方法" />
<option name="LAST_COMMIT_MESSAGE" value="添加转换窗口方法" />
<MESSAGE value="review" />
<option name="LAST_COMMIT_MESSAGE" value="review" />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/server.log" />
......
......@@ -4,20 +4,20 @@ from src.framework.HTMLTestRunner import HTMLTestRunner
from src.framework import common
from src.testcase.testLoginPage import TestLoginPage as TLP
from src.testcase.testMainPage import TestMainPage as TMP
# from src.testcase.testWordPage import TestWordPage as TWP
# from src.testcase.testMainPage import TestMainPage as TMP
if __name__ == '__main__':
testunit = unittest.TestSuite()
testunit.addTest(TLP('testLogin'))
testunit.addTests([TMP('test_1_UnStartLive'), TMP('test_2_StartLive'), TMP('test_3_ReviewLive')])
# testunit.addTests([TMP('test_1_UnStartLive'), TMP('test_2_StartLive'), TMP('test_3_ReviewLive')])
# testunit.addTests([TMP('test_1_UnStartLive')])
# 定义报告输出路径
htmlPath = "./report/AI-XM_Report{}.html".format(common.year_to_minute())
with(open(htmlPath, 'wb')) as fp:
runner = HTMLTestRunner(
stream=fp,
title='AI-小麦测试报告',
title='企培客户端UI自动化测试报告',
description='描述'
)
runner.run(testunit)
......@@ -27,8 +27,11 @@ def file_abspath():
return os.path.abspath(__file__).split('src')[0]
def screenshot_path():
screenshot_file = file_abspath() + "/screenshots/" + year_to_day()
def screenshot_path(module_name):
screen_day_path = file_abspath() + "/screenshots/" + year_to_day()
screenshot_file = file_abspath() + "/screenshots/" + year_to_day() + "/" + module_name
if not os.path.exists(screen_day_path):
os.mkdir(screen_day_path)
if not os.path.exists(screenshot_file):
os.mkdir(screenshot_file)
return screenshot_file
......
......@@ -99,9 +99,18 @@ class Page(object):
def close(self, loc, num):
self.find_elements(*loc)[num].click()
# 保存图片
def save_screenshot(self, filename):
self.driver.save_screenshot(filename)
# 跳出iframe
def switch_to_iframe(self, iframe_id):
self.driver.switch_to.frame(iframe_id)
# 跳出iframe
def switch_to_current(self):
self.driver.switch_to.default_content()
# 切换窗口
def change_window(self, loc):
driver = self.driver
......@@ -127,3 +136,16 @@ class Page(object):
login_page.input_text(account_input, readConfig.test_account())
login_page.input_text(password_input, readConfig.test_password())
login_page.click(login_button)
# 鼠标键盘操作
# 拖拽元素
def drag_mouse(self, source, xoffset, yoffset):
ActionChains(self.driver).drag_and_drop_by_offset(source=source, xoffset=xoffset, yoffset=yoffset).perform()
# 鼠标左键单击
def left_click(self):
ActionChains(self.driver).click().perform()
# 鼠标移动N个像素
def mouse_move(self, x, y):
ActionChains(self.driver).move_by_offset(xoffset=x, yoffset=y).click().perform()
from src.pageobject.mainpage import MainPage
from selenium.webdriver.common.by import By
# 主页面
class LivePage(MainPage):
# 元素集
# 切换白板标签
white_board = (By.XPATH, """//div[text()="白板"]""")
# 添加白板按钮
add_white_board = (By.XPATH, """//span[text()=" 添加白板"]""")
# 打开白板
open_white_board = (By.XPATH, """//span[@class="name oneLineText"]""")
# iframe
iframe_ele = (By.XPATH, """//iframe[@id="webview"]""")
# 白板
green_board = (By.XPATH, """//div[@class="whiteboard-box "]""")
# 白板功能
# 画笔
huabi = (By.XPATH, """//span[@class="icon iconfont iconhuabi "]""")
# 文本
wenben = (By.XPATH, """//span[@class="icon iconfont iconwenben "]""")
# 文本输入框
wenben_text = (By.XPATH, """//textarea[@class="editable-textarea my-textarea"]""")
# "进入直播间"按钮 format里面的参数还是要继续修改,先创建课程,再通过课程名称来查看进入直播间按钮
in_live_btn = (By.XPATH, """//div[text()={}]/..//button[@class="ant-btn ant-btn-primary"]""".format("测试新增直播课"))
# 验证元素
def __init__(self, driver):
MainPage.__init__(self, driver)
# 点击切换白板
def click_white_board(self):
self.click(self.white_board)
# 点击添加白板
def click_add_white_board(self):
self.click(self.add_white_board)
# 打开白板
def click_open_white_board(self):
self.click(self.open_white_board)
# 点击画笔
def click_huabi(self):
self.click(self.huabi)
# 点击文本
def click_wenben(self):
self.click(self.wenben)
def input_wenben(self, text):
self.input_text(self.wenben_text, text=text)
def move_get_wenben(self):
self.mouse_move(100, 100)
from src.pageobject.mainpage import MainPage
from selenium.webdriver.common.by import By
# 主页面
class WhiteBoardPage(MainPage):
# 元素集
# 切换白板标签
white_board = (By.XPATH, """//div[text()="白板"]""")
# 添加白板按钮
add_white_board = (By.XPATH, """//span[text()=" 添加白板"]""")
# 打开白板
open_white_board = (By.XPATH, """//span[@class="name oneLineText"]""")
# iframe
iframe_ele = (By.XPATH, """//iframe[@id="webview"]""")
# 白板
green_board = (By.XPATH, """//div[@class="whiteboard-box "]""")
# 白板功能
# 画笔
huabi = (By.XPATH, """//span[@class="icon iconfont iconhuabi "]""")
# 文本
wenben = (By.XPATH, """//span[@class="icon iconfont iconwenben "]""")
# 文本输入框
wenben_text = (By.XPATH, """//textarea[@class="editable-textarea my-textarea"]""")
# "进入直播间"按钮 format里面的参数还是要继续修改,先创建课程,再通过课程名称来查看进入直播间按钮
in_live_btn = (By.XPATH, """//div[text()={}]/..//button[@class="ant-btn ant-btn-primary"]""".format("测试新增直播课"))
# 验证元素
def __init__(self, driver):
MainPage.__init__(self, driver)
# 点击切换白板
def click_white_board(self):
self.click(self.white_board)
# 点击添加白板
def click_add_white_board(self):
self.click(self.add_white_board)
# 打开白板
def click_open_white_board(self):
self.click(self.open_white_board)
# 点击画笔
def click_huabi(self):
self.click(self.huabi)
# 点击文本
def click_wenben(self):
self.click(self.wenben)
def input_wenben(self, text):
self.input_text(self.wenben_text, text=text)
def move_get_wenben(self):
self.mouse_move(100, 100)
from src.framework.logger import Logger
from src.pageobject.livepage import LivePage
from src.framework.common import create_a_live
from src.framework.appDriver import get_app_driver
from src.framework.common import screenshot_path, compare_pictures, year_to_minute
from config import readConfig
import unittest
import sys
class TestLivePage(unittest.TestCase):
logger = Logger('live page').getlog()
cloud_class_location = readConfig.test_location()
live_course_name = create_a_live(start_time=25, start_time2=1)
driver = get_app_driver(cloud_class_location)
live_page = LivePage(driver=driver)
# 这里停15s是因为setUP里创建直播间获取token登录了一次,限制两次登录需间隔15s
live_page.sleep(15)
live_page.login()
live_page.sleep(2)
live_page.click_in_live_btn(live_course_name[0])
live_page.sleep(5)
live_page.change_window(live_page.camera_btn)
live_page.sleep(5)
def setUp(self) -> None:
# 指定客户端的本地路径,在/config/config.ini配置
pass
@classmethod
def tearDownClass(cls) -> None:
cls.driver.quit()
# 测试直播间摄像头 测试的时候有个问题,如果摄像头黑屏,检查一下是否开了两个客户端,造成了摄像头抢占
def testLiveCamera(self):
before_savescreen = screenshot_path(sys._getframe().f_code.co_name) + "/" + year_to_minute() + '.png'
self.live_page.save_screenshot(before_savescreen)
self.live_page.click_camera_btn()
self.live_page.sleep(1)
after_savescreen = screenshot_path(sys._getframe().f_code.co_name) + "/" + year_to_minute() + '.png'
self.live_page.save_screenshot(after_savescreen)
result = compare_pictures(before_savescreen, after_savescreen)
self.assertLessEqual(10, result)
self.live_page.sleep(3)
# 测试添加白板并打开
def testWhiteBoard(self):
self.live_page.click_white_board()
self.live_page.sleep(2)
self.live_page.click_add_white_board()
self.live_page.click_camera_btn()
self.live_page.sleep(1)
before_whiteboard_savescreen = screenshot_path(sys._getframe().f_code.co_name) + "/" + year_to_minute() + '.png'
self.live_page.save_screenshot(before_whiteboard_savescreen)
self.live_page.click_open_white_board()
self.live_page.sleep(1)
after_whiteboard_savescreen = screenshot_path(sys._getframe().f_code.co_name) + "/" + year_to_minute() + '.png'
self.live_page.save_screenshot(after_whiteboard_savescreen)
whiteboard_result = compare_pictures(before_whiteboard_savescreen, after_whiteboard_savescreen)
self.assertLessEqual(10, whiteboard_result)
if __name__ == '__main__':
unittest.main(verbosity=1)
......@@ -24,6 +24,7 @@ class TestLoginPage(unittest.TestCase):
def testLogin(self):
driver = self.driver
login_page = LoginPage(driver=driver)
login_page.sleep(15)
login_page.click_phone_login()
login_page.input_account(account=self.account)
login_page.input_password(password=self.password)
......
from src.framework.logger import Logger
from src.pageobject.whiteboardpage import WhiteBoardPage
from src.framework.common import create_a_live
from src.framework.appDriver import get_app_driver
from src.framework.common import screenshot_path, compare_pictures, year_to_minute
from config import readConfig
import unittest
import sys
class TestLivePage(unittest.TestCase):
logger = Logger('live page').getlog()
cloud_class_location = readConfig.test_location()
live_course_name = create_a_live(start_time=25, start_time2=1)
driver = get_app_driver(cloud_class_location)
live_page = WhiteBoardPage(driver=driver)
# 这里停15s是因为setUP里创建直播间获取token登录了一次,限制两次登录需间隔15s
live_page.sleep(15)
live_page.login()
live_page.sleep(2)
live_page.click_in_live_btn(live_course_name[0])
live_page.sleep(5)
live_page.change_window(live_page.camera_btn)
live_page.sleep(5)
def setUp(self) -> None:
# 指定客户端的本地路径,在/config/config.ini配置
pass
@classmethod
def tearDownClass(cls) -> None:
cls.driver.quit()
# 测试白板功能-文本输入
def testWhiteBoard(self):
self.live_page.click_white_board()
self.live_page.sleep(2)
self.live_page.click_add_white_board()
self.live_page.click_camera_btn()
self.live_page.sleep(1)
self.live_page.click_open_white_board()
self.live_page.click_wenben()
self.live_page.sleep(3)
# 切换iframe前后都要点击一次才能生效,神奇
self.live_page.move_get_wenben()
self.live_page.switch_to_iframe("webview")
self.live_page.move_get_wenben()
print(self.live_page.ifElementExist(self.live_page.wenben_text))
self.live_page.sleep(1)
before_send_wenben = screenshot_path(sys._getframe().f_code.co_name) + "/" + year_to_minute() + '.png'
self.live_page.save_screenshot(before_send_wenben)
# 切换iframe后必须时textarea才能输入文本
self.live_page.input_wenben("11111")
self.live_page.sleep(1)
after_send_wenben = screenshot_path(sys._getframe().f_code.co_name) + "/" + year_to_minute() + '.png'
self.live_page.save_screenshot(after_send_wenben)
wenben_result = compare_pictures(before_send_wenben, after_send_wenben)
print(wenben_result)
self.assertLessEqual(10, wenben_result)
if __name__ == '__main__':
unittest.main(verbosity=1)
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