Commit 24ea03c6 by linguangwei

allure添加截图

parent 3b01b34d
......@@ -9,7 +9,7 @@
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.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/pageobject/loginpage.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/pageobject/loginpage.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/testcase/test_LoginPage.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/testcase/test_LoginPage.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/testcase/test_WhiteBoardPage.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/testcase/test_WhiteBoardPage.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
......@@ -148,19 +148,20 @@
<property name="node.js.selected.package.tslint" value="(autodetect)" />
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="nodejs_npm_path_reset_for_default_project" value="true" />
<property name="settings.editor.selected.configurable" value="project.propVCSSupport.Mappings" />
<property name="settings.editor.selected.configurable" value="com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable" />
</component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="E:\python project\xm-uitest-sow\src\framework" />
</key>
<key name="MoveFile.RECENT_KEYS">
<recent name="E:\python project\xm-uitest-sow\report\" />
<recent name="E:\python project\xm-uitest-sow\src\testcase" />
<recent name="D:\pycharm projects\xm-uitest-sow\commom" />
<recent name="C:\Users\Administrator\PycharmProjects\xm-uitest-live" />
</key>
</component>
<component name="RunManager" selected="Python tests.pytest in test_LoginPage.py">
<component name="RunManager" selected="Python.main">
<configuration name="main" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="xm-uitest-live" />
<option name="INTERPRETER_OPTIONS" value="" />
......@@ -183,28 +184,23 @@
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="test_LoginPage" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<configuration name="pytest for src.testcase.test_LoginPage.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" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/src/testcase" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="E:\python project\xm-uitest-sow\src\testcase\test_LoginPage.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<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;src.testcase.test_LoginPage.TestLoginPage.testLogin&quot;" />
<option name="_new_targetType" value="&quot;PYTHON&quot;" />
<method v="2" />
</configuration>
<configuration name="pytest for src.testcase.test_LoginPage.TestLoginPage.testLogin" type="tests" factoryName="py.test" temporary="true" nameIsGenerated="true">
<configuration name="pytest for test_LoginPage.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" />
......@@ -216,7 +212,7 @@
<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;src.testcase.test_LoginPage.TestLoginPage.testLogin&quot;" />
<option name="_new_target" value="&quot;test_LoginPage.TestLoginPage.testLogin&quot;" />
<option name="_new_targetType" value="&quot;PYTHON&quot;" />
<method v="2" />
</configuration>
......@@ -254,11 +250,11 @@
</configuration>
<recent_temporary>
<list>
<item itemvalue="Python tests.pytest in test_LoginPage.py" />
<item itemvalue="Python.main" />
<item itemvalue="Python tests.pytest for test_LoginPage.TestLoginPage.testLogin" />
<item itemvalue="Python tests.pytest in test_LoginPage.py" />
<item itemvalue="Python tests.pytest in test_MainPage.py" />
<item itemvalue="Python tests.pytest for src.testcase.test_LoginPage.TestLoginPage.testLogin" />
<item itemvalue="Python.test_LoginPage" />
</list>
</recent_temporary>
</component>
......@@ -379,7 +375,14 @@
<option name="project" value="LOCAL" />
<updated>1624270134308</updated>
</task>
<option name="localTasksCounter" value="15" />
<task id="LOCAL-00015" summary="review">
<created>1624345577551</created>
<option name="number" value="00015" />
<option name="presentableId" value="LOCAL-00015" />
<option name="project" value="LOCAL" />
<updated>1624345577551</updated>
</task>
<option name="localTasksCounter" value="16" />
<servers />
</component>
<component name="TestHistory">
......
import pytest
import os
from src.framework import common
if __name__ == '__main__':
htmlPath = "./report/AI-XM_Report{}.html".format(common.year_to_minute())
pytest.main(["-v", '--html={}'.format(htmlPath), './src/testcase/test_LoginPage.py', "--durations=0"])
pytest.main(["-v", '--alluredir={}'.format(htmlPath), './src/testcase/test_WhiteBoardPage.py', "--durations=0"])
os.system('allure generate {} -o ./report/output --clean'.format(htmlPath))
# # 定义报告输出路径
# htmlPath = "./report/AI-XM_Report{}.html".format(common.year_to_minute())
......
......@@ -6,6 +6,9 @@ import random
import string
import time
from functools import reduce
import allure
from config import readConfig
import requests
......@@ -29,8 +32,11 @@ def file_abspath():
def screenshot_path(module_name):
screen_path = file_abspath() + "/screenshots/"
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_path):
os.mkdir(screen_path)
if not os.path.exists(screen_day_path):
os.mkdir(screen_day_path)
if not os.path.exists(screenshot_file):
......@@ -48,6 +54,16 @@ def compare_pictures(pic1, pic2):
return result
# allure测试报告相关
# 添加截图至测试报告中
def get_allure_screenshots(screenshot_path, describe):
with open(screenshot_path, "rb") as f:
context = f.read()
allure.attach(context, describe, allure.attachment_type.PNG)
allure.attach()
# 小麦接口相关
# 获取登录token
def get_token():
account = readConfig.test_account()
......
......@@ -24,7 +24,10 @@ class Page(object):
# 输入元素输入
def input_text(self, loc, text):
self.find_element(*loc).send_keys(text)
try:
self.find_element(*loc).send_keys(text)
except Exception:
self.find_elements(*loc)[0].send_keys(text)
# 获取元素文本
def get_text(self, loc):
......
import allure
import pytest
from src.pageobject.loginpage import LoginPage
......@@ -20,10 +21,11 @@ class TestLoginPage(object):
self.driver.quit()
# 测试登录
@pytest.fixture()
def testLogin(self):
driver = self.driver
login_page = LoginPage(driver=driver)
login_page = LoginPage(driver=self.driver)
login_page.sleep(15)
allure.attach('在fixture前置操作里面添加一个附件txt', 'fixture前置附件', allure.attachment_type.PNG)
login_page.click_phone_login()
login_page.input_account(account=self.account)
login_page.input_password(password=self.password)
......
import time
import allure
import pytest
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.logger import Logger
from src.framework.common import create_a_live
from src.framework.common import screenshot_path, compare_pictures, year_to_minute
from src.framework.common import get_allure_screenshots
from config import readConfig
......@@ -36,7 +39,7 @@ class TestLivePage(object):
def teardown_class(self):
self.driver.quit()
# 测试白板功能-文本输入
@allure.title("测试白板功能-文本输入")
def testWhiteBoard(self):
self.White_Board_page.click_white_board()
self.White_Board_page.sleep(2)
......@@ -55,11 +58,13 @@ class TestLivePage(object):
self.White_Board_page.sleep(1)
before_send_wenben = screenshot_path(sys._getframe().f_code.co_name) + "/" + year_to_minute() + '.png'
self.White_Board_page.save_screenshot(before_send_wenben)
get_allure_screenshots(before_send_wenben, "输入文本框字符前截图")
# 切换iframe后必须时textarea才能输入文本
self.White_Board_page.input_wenben("11111")
self.White_Board_page.sleep(1)
after_send_wenben = screenshot_path(sys._getframe().f_code.co_name) + "/" + year_to_minute() + '.png'
self.White_Board_page.save_screenshot(after_send_wenben)
get_allure_screenshots(after_send_wenben, "输入文本框字符后截图")
wenben_result = compare_pictures(before_send_wenben, after_send_wenben)
print(wenben_result)
assert 10 < wenben_result
......
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