使用pageObject模式

This commit is contained in:
lily 2019-02-26 10:52:37 +08:00
parent 2de71eb39b
commit 572fcb39c3
11 changed files with 1104 additions and 141 deletions

View File

@ -2,7 +2,14 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="09a4aeb4-cd0a-454b-9878-fc6edee9400a" name="Default" comment="">
<change afterPath="$PROJECT_DIR$/common/pageObject.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/page/searchPage.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/testcase/test_baiduSearch.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/common/sendEmail.py" beforeDir="false" afterPath="$PROJECT_DIR$/common/sendEmail.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/page/LoginPage.py" beforeDir="false" afterPath="$PROJECT_DIR$/common/url.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/run.py" beforeDir="false" afterPath="$PROJECT_DIR$/run.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/testcase/test_baidu.py" beforeDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="TRACKING_ENABLED" value="true" />
@ -12,15 +19,17 @@
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="CoverageDataManager">
<SUITE FILE_PATH="coverage/Automated_Test$imagetobase64.coverage" NAME="imagetobase64 Coverage Results" MODIFIED="1550560891475" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/testcase" />
<SUITE FILE_PATH="coverage/Automated_Test$Unittests_for_t_MyTestCase.coverage" NAME="Unittests for t.MyTestCase Coverage Results" MODIFIED="1550495220265" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
<SUITE FILE_PATH="coverage/Automated_Test$Unnamed.coverage" NAME="Unnamed Coverage Results" MODIFIED="1550546753307" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/testcase" />
<SUITE FILE_PATH="coverage/Automated_Test$Unittests_in_test_py.coverage" NAME="Unittests in test.py Coverage Results" MODIFIED="1550545365197" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/testcase" />
<SUITE FILE_PATH="coverage/Automated_Test$run__1_.coverage" NAME="run (1) Coverage Results" MODIFIED="1550497417209" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
<SUITE FILE_PATH="coverage/Automated_Test$Unittests_in_test_baidu_py.coverage" NAME="Unittests in test_baidu.py Coverage Results" MODIFIED="1551147051623" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/testcase" />
<SUITE FILE_PATH="coverage/Automated_Test$test.coverage" NAME="test Coverage Results" MODIFIED="1550558865800" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/testcase" />
<SUITE FILE_PATH="coverage/Automated_Test$Unittests_for_test_TestDemo.coverage" NAME="Unittests for test.TestDemo Coverage Results" MODIFIED="1550493736228" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
<SUITE FILE_PATH="coverage/Automated_Test$Unittests_for_test_baidu_TestLogin.coverage" NAME="Unittests for test_baidu.TestLogin Coverage Results" MODIFIED="1551147317563" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/testcase" />
<SUITE FILE_PATH="coverage/Automated_Test$imagetobase64.coverage" NAME="imagetobase64 Coverage Results" MODIFIED="1550560891475" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/testcase" />
<SUITE FILE_PATH="coverage/Automated_Test$Unittests_for_t_MyTestCase.coverage" NAME="Unittests for t.MyTestCase Coverage Results" MODIFIED="1550495220265" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
<SUITE FILE_PATH="coverage/Automated_Test$Unittests_in_test_py.coverage" NAME="Unittests in test.py Coverage Results" MODIFIED="1550545365197" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/testcase" />
<SUITE FILE_PATH="coverage/Automated_Test$run__1_.coverage" NAME="run (1) Coverage Results" MODIFIED="1550497417209" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
<SUITE FILE_PATH="coverage/Automated_Test$sendEmail.coverage" NAME="sendEmail Coverage Results" MODIFIED="1550574997598" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/testcase" />
<SUITE FILE_PATH="coverage/Automated_Test$run.coverage" NAME="run Coverage Results" MODIFIED="1550575005734" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/testcase" />
<SUITE FILE_PATH="coverage/Automated_Test$run.coverage" NAME="run Coverage Results" MODIFIED="1551149370552" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/testcase" />
<SUITE FILE_PATH="coverage/Automated_Test$Unittests_in_t_py.coverage" NAME="Unittests in t.py Coverage Results" MODIFIED="1550495271315" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
<SUITE FILE_PATH="coverage/Automated_Test$Unittests_for_test_TestLogin.coverage" NAME="Unittests for test.TestLogin Coverage Results" MODIFIED="1550545430554" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/testcase" />
</component>
@ -29,8 +38,8 @@
<file leaf-file-name="run.py" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/run.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="323">
<caret line="20" column="38" selection-start-line="20" selection-start-column="38" selection-end-line="20" selection-end-column="38" />
<state relative-caret-position="-95">
<caret line="7" column="25" lean-forward="true" selection-start-line="7" selection-start-column="25" selection-end-line="7" selection-end-column="25" />
<folding>
<element signature="e#0#15#0" expanded="true" />
</folding>
@ -38,18 +47,35 @@
</provider>
</entry>
</file>
<file leaf-file-name="sendEmail.py" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/common/sendEmail.py">
<file leaf-file-name="searchPage.py" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/page/searchPage.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="488">
<caret line="38" column="6" selection-start-line="38" selection-start-column="6" selection-end-line="38" selection-end-column="6" />
<state relative-caret-position="380">
<caret line="20" lean-forward="true" selection-start-line="20" selection-end-line="20" />
<folding>
<element signature="e#47#56#0" expanded="true" />
<element signature="e#0#53#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file leaf-file-name="test_baiduSearch.py" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/testcase/test_baiduSearch.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-173">
<caret line="34" column="27" selection-start-line="34" selection-start-column="27" selection-end-line="34" selection-end-column="27" />
<folding>
<element signature="e#15#56#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file leaf-file-name="2019-02-26 10_45_51report.html" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/report/2019-02-26 10_45_51report.html">
<provider selected="true" editor-type-id="text-editor" />
</entry>
</file>
</leaf>
</component>
<component name="FileTemplateManagerImpl">
@ -107,11 +133,15 @@
<option value="$PROJECT_DIR$/Page.py" />
<option value="$PROJECT_DIR$/page/loginPage1.py" />
<option value="$PROJECT_DIR$/imagetobase64.py" />
<option value="$PROJECT_DIR$/README.md" />
<option value="$PROJECT_DIR$/testcase/test.py" />
<option value="$PROJECT_DIR$/page/LoginPage.py" />
<option value="$PROJECT_DIR$/run.py" />
<option value="$PROJECT_DIR$/README.md" />
<option value="$PROJECT_DIR$/common/pageObject.py" />
<option value="$PROJECT_DIR$/page/searchPage.py" />
<option value="$PROJECT_DIR$/testcase/test_baidu.py" />
<option value="$PROJECT_DIR$/common/sendEmail.py" />
<option value="$PROJECT_DIR$/common/url.py" />
<option value="$PROJECT_DIR$/run.py" />
</list>
</option>
</component>
@ -125,16 +155,15 @@
<packageJsonPaths />
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="939" />
<option name="x" value="-12" />
<option name="width" value="981" />
<option name="height" value="1080" />
<option name="height" value="1092" />
</component>
<component name="ProjectView">
<navigator proportions="" version="1">
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="Scope" />
<pane id="ProjectPane">
<subPane>
<expand>
@ -145,7 +174,22 @@
<path>
<item name="Automated-Test" type="b2602c69:ProjectViewProjectNode" />
<item name="Automated-Test" type="462c0819:PsiDirectoryNode" />
<item name="z-README-image" type="462c0819:PsiDirectoryNode" />
<item name="common" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="Automated-Test" type="b2602c69:ProjectViewProjectNode" />
<item name="Automated-Test" type="462c0819:PsiDirectoryNode" />
<item name="page" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="Automated-Test" type="b2602c69:ProjectViewProjectNode" />
<item name="Automated-Test" type="462c0819:PsiDirectoryNode" />
<item name="report" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="Automated-Test" type="b2602c69:ProjectViewProjectNode" />
<item name="Automated-Test" type="462c0819:PsiDirectoryNode" />
<item name="testcase" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="Automated-Test" type="b2602c69:ProjectViewProjectNode" />
@ -155,17 +199,19 @@
<select />
</subPane>
</pane>
<pane id="Scope" />
</panes>
</component>
<component name="PropertiesComponent">
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/testcase/test.py" />
<property name="last_opened_file_path" value="D:/tmp/PageObjectFramework" />
<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="com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable" />
</component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="D:\githublily\Automated-Test\common" />
<recent name="D:\githublily\Automated-Test\z-README-image" />
<recent name="D:\githublily\Automated-Test\image" />
<recent name="D:\githublily\Automated-Test\file" />
@ -266,37 +312,48 @@
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
</configuration>
<configuration name="test" type="PythonConfigurationType" factoryName="Python" temporary="true">
<configuration name="Unittests for testcase.test_baiduSearch.TestLogin" type="tests" factoryName="Unittests" temporary="true" nameIsGenerated="true">
<module name="Automated-Test" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="D:\tmp\test\venv\Scripts\python3.exe" />
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/testcase" />
<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="SCRIPT_NAME" value="D:\githublily\Automated-Test\testcase\test_baidu.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="_new_additionalArguments" value="&quot;&quot;" />
<option name="_new_target" value="&quot;testcase.test_baiduSearch.TestLogin&quot;" />
<option name="_new_targetType" value="&quot;PYTHON&quot;" />
</configuration>
<configuration name="Unittests in test_baiduSearch.py" type="tests" factoryName="Unittests" temporary="true" nameIsGenerated="true">
<module name="Automated-Test" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/testcase" />
<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_additionalArguments" value="&quot;&quot;" />
<option name="_new_target" value="&quot;$PROJECT_DIR$/testcase/test_baiduSearch.py&quot;" />
<option name="_new_targetType" value="&quot;PATH&quot;" />
</configuration>
<list>
<item itemvalue="Python.test" />
<item itemvalue="Python.imagetobase64" />
<item itemvalue="Python.run" />
<item itemvalue="Python.sendEmail" />
<item itemvalue="Python tests.Unittests in test_baiduSearch.py" />
<item itemvalue="Python tests.Unittests for testcase.test_baiduSearch.TestLogin" />
</list>
<recent_temporary>
<list>
<item itemvalue="Python.run" />
<item itemvalue="Python tests.Unittests for testcase.test_baiduSearch.TestLogin" />
<item itemvalue="Python tests.Unittests in test_baiduSearch.py" />
<item itemvalue="Python.sendEmail" />
<item itemvalue="Python.imagetobase64" />
<item itemvalue="Python.test" />
</list>
</recent_temporary>
</component>
@ -314,15 +371,6 @@
<servers />
</component>
<component name="TestHistory">
<history-entry file="Unittests_in_t_py - 2019.02.18 at 20h 59m 40s.xml">
<configuration name="Unittests in t.py" configurationId="tests" />
</history-entry>
<history-entry file="Unittests_for_t_MyTestCase - 2019.02.18 at 21h 07m 17s.xml">
<configuration name="Unittests for t.MyTestCase" configurationId="tests" />
</history-entry>
<history-entry file="Unittests_in_t_py - 2019.02.18 at 21h 08m 08s.xml">
<configuration name="Unittests in t.py" configurationId="tests" />
</history-entry>
<history-entry file="Unittests_in_test_py - 2019.02.18 at 22h 09m 47s.xml">
<configuration name="Unittests in test.py" configurationId="tests" />
</history-entry>
@ -344,18 +392,28 @@
<history-entry file="Unittests_for_test_TestLogin - 2019.02.19 at 11h 03m 51s.xml">
<configuration name="Unittests for test.TestLogin" configurationId="tests" />
</history-entry>
<history-entry file="Unittests_in_test_baidu_py - 2019.02.26 at 10h 11m 32s.xml">
<configuration name="Unittests in test_baidu.py" configurationId="tests" />
</history-entry>
<history-entry file="Unittests_for_test_baidu_TestLogin - 2019.02.26 at 10h 12m 40s.xml">
<configuration name="Unittests for test_baidu.TestLogin" configurationId="tests" />
</history-entry>
<history-entry file="Unittests_for_test_baidu_TestLogin - 2019.02.26 at 10h 16m 10s.xml">
<configuration name="Unittests for test_baidu.TestLogin" configurationId="tests" />
</history-entry>
</component>
<component name="ToolWindowManager">
<frame x="-7" y="-7" width="1295" height="735" extended-state="7" />
<frame x="-7" y="-7" width="1295" height="735" extended-state="6" />
<editor active="true" />
<layout>
<window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="bottom" id="Event Log" order="12" side_tool="true" weight="0.3292683" />
<window_info anchor="bottom" id="Database Changes" order="9" show_stripe_button="false" />
<window_info anchor="bottom" id="Version Control" order="8" />
<window_info anchor="bottom" id="Python Console" order="10" />
<window_info anchor="bottom" id="Run" order="2" weight="0.3292683" />
<window_info anchor="bottom" id="Terminal" order="11" visible="true" weight="0.32752612" />
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.25788197" />
<window_info anchor="bottom" id="Run" order="2" visible="true" weight="0.3292683" />
<window_info anchor="bottom" id="Terminal" order="11" weight="0.32752612" />
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.261924" />
<window_info anchor="bottom" id="Docker" order="7" show_stripe_button="false" />
<window_info anchor="right" id="Database" order="3" />
<window_info anchor="right" id="SciView" order="4" />
@ -383,17 +441,6 @@
</breakpoint-manager>
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/reports/HTMLTestRunner.py" />
<entry file="file://D:/software/Python/python2.7.10/Lib/unittest/loader.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="119">
<caret line="31" selection-start-line="31" selection-end-line="31" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/report/result.html" />
<entry file="file://$PROJECT_DIR$/test_case/test.py" />
<entry file="file://$PROJECT_DIR$/test_case/t.py" />
<entry file="file://$PROJECT_DIR$/common/__init__.py">
<provider selected="true" editor-type-id="text-editor" />
</entry>
@ -442,31 +489,17 @@
<entry file="file://$PROJECT_DIR$/z-README-image/structure.png">
<provider selected="true" editor-type-id="images" />
</entry>
<entry file="file://$PROJECT_DIR$/HTMLTestRunner.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2306">
<caret line="396" column="47" selection-start-line="396" selection-start-column="47" selection-end-line="396" selection-end-column="47" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/report/2019-02-19 16_32_21_result.html" />
<entry file="file://$PROJECT_DIR$/report/2019-02-19 16_32_28_result.html" />
<entry file="file://$PROJECT_DIR$/report/2019-02-19 16_43_57report.html">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/report/2019-02-19-14-47-46result.html" />
<entry file="file://$PROJECT_DIR$/testcase/test_baidu.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="392">
<caret line="48" column="18" selection-start-line="48" selection-start-column="18" selection-end-line="48" selection-end-column="18" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/README.md">
<provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
<state split_layout="SPLIT">
<first_editor relative-caret-position="206">
<caret line="47" lean-forward="true" selection-start-line="47" selection-end-line="47" />
<first_editor relative-caret-position="-22">
<caret line="40" column="96" selection-start-line="40" selection-start-column="96" selection-end-line="40" selection-end-column="96" />
</first_editor>
<second_editor />
</state>
@ -475,25 +508,82 @@
<entry file="file://$PROJECT_DIR$/page/LoginPage.py">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/run.py">
<entry file="file://$USER_HOME$/.PyCharm2018.1/system/python_stubs/1970740885/builtins.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="323">
<caret line="20" column="38" selection-start-line="20" selection-start-column="38" selection-end-line="20" selection-end-column="38" />
<state relative-caret-position="120">
<caret line="167" column="4" selection-start-line="167" selection-start-column="4" selection-end-line="167" selection-end-column="4" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/common/pageObject.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="608">
<caret line="32" column="11" lean-forward="true" selection-start-line="32" selection-start-column="11" selection-end-line="32" selection-end-column="11" />
<folding>
<element signature="e#0#15#0" expanded="true" />
<element signature="e#0#61#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/common/url.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="38">
<caret line="2" column="39" lean-forward="true" selection-start-line="2" selection-start-column="39" selection-end-line="2" selection-end-column="39" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/common/sendEmail.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="488">
<caret line="38" column="6" selection-start-line="38" selection-start-column="6" selection-end-line="38" selection-end-column="6" />
<state relative-caret-position="506">
<caret line="48" selection-start-line="48" selection-end-line="48" />
<folding>
<element signature="e#47#56#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/HTMLTestRunner.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="5700">
<caret line="396" column="47" selection-start-line="396" selection-start-column="47" selection-end-line="396" selection-end-column="47" />
<folding>
<element signature="e#3209#3224#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/run.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-95">
<caret line="7" column="25" lean-forward="true" selection-start-line="7" selection-start-column="25" selection-end-line="7" selection-end-column="25" />
<folding>
<element signature="e#0#15#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/page/searchPage.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="380">
<caret line="20" lean-forward="true" selection-start-line="20" selection-end-line="20" />
<folding>
<element signature="e#0#53#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/testcase/test_baiduSearch.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-173">
<caret line="34" column="27" selection-start-line="34" selection-start-column="27" selection-end-line="34" selection-end-column="27" />
<folding>
<element signature="e#15#56#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/report/2019-02-26 10_45_51report.html">
<provider selected="true" editor-type-id="text-editor" />
</entry>
</component>
</project>

132
common/pageObject.py Normal file
View File

@ -0,0 +1,132 @@
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By
# Map PageElement constructor arguments to webdriver locator enums
_LOCATOR_MAP = {'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_name': By.TAG_NAME,
'class_name': By.CLASS_NAME,
}
class PageObject(object):
"""Page Object pattern.
:param webdriver: `selenium.webdriver.WebDriver`
Selenium webdriver instance
:param root_uri: `str`
Root URI to base any calls to the ``PageObject.get`` method. If not defined
in the constructor it will try and look it from the webdriver object.
"""
def __init__(self, webdriver, root_uri=None):
self.w = webdriver
self.root_uri = root_uri if root_uri else getattr(self.w, 'root_uri', None)
def get(self, uri):
"""
:param uri: URI to GET, based off of the root_uri attribute.
uri can be None
"""
root_uri = self.root_uri or ''
self.w.get(root_uri + uri)
class PageElement(object):
"""Page Element descriptor.
:param css: `str`
Use this css locator
:param id_: `str`
Use this element ID locator
:param name: `str`
Use this element name locator
:param xpath: `str`
Use this xpath locator
:param link_text: `str`
Use this link text locator
:param partial_link_text: `str`
Use this partial link text locator
:param tag_name: `str`
Use this tag name locator
:param class_name: `str`
Use this class locator
:param context: `bool`
This element is expected to be called with context
Page Elements are used to access elements on a page. The are constructed
using this factory method to specify the locator for the element.
# >>> from page_objects import PageObject, PageElement
# >>> class MyPage(PageObject):
elem1 = PageElement(css='div.myclass')
elem2 = PageElement(id_='foo')
elem_with_context = PageElement(name='bar', context=True)
Page Elements act as property descriptors for their Page Object, you can get
and set them as normal attributes.
"""
def __init__(self, context=False, **kwargs):
if not kwargs:
raise ValueError("Please specify a locator")
if len(kwargs) > 1:
raise ValueError("Please specify only one locator")
k, v = next(iter(kwargs.items()))
self.locator = (_LOCATOR_MAP[k], v)
self.has_context = bool(context)
def find(self, context):
try:
return context.find_element(*self.locator)
except NoSuchElementException:
return None
def __get__(self, instance, owner, context=None):
if not instance:
return None
if not context and self.has_context:
return lambda ctx: self.__get__(instance, owner, context=ctx)
if not context:
context = instance.w
return self.find(context)
def __set__(self, instance, value):
if self.has_context:
raise ValueError("Sorry, the set descriptor doesn't support elements with context.")
elem = self.__get__(instance, instance.__class__)
if not elem:
raise ValueError("Can't set value, element not found")
elem.clear()
elem.send_keys(value)
class MultiPageElement(PageElement):
""" Like `PageElement` but returns multiple results.
# >>> from page_objects import PageObject, MultiPageElement
# >>> class MyPage(PageObject):
all_table_rows = MultiPageElement(tag='tr')
elem2 = PageElement(id_='foo')
elem_with_context = PageElement(tag='tr', context=True)
"""
def find(self, context):
try:
return context.find_elements(*self.locator)
except NoSuchElementException:
return []
def __set__(self, instance, value):
if self.has_context:
raise ValueError("Sorry, the set descriptor doesn't support elements with context.")
elems = self.__get__(instance, instance.__class__)
if not elems:
raise ValueError("Can't set value, no elements found")
[elem.send_keys(value) for elem in elems]
# Backwards compatibility with previous versions that used factory methods
page_element = PageElement
multi_page_element = MultiPageElement

View File

@ -1,6 +1,4 @@
# email3381350680@qq.com passwordabc123456
import os
import smtplib
from email.mime.text import MIMEText
@ -48,7 +46,3 @@ class SendEmail():
the_last_report_address = os.path.join(reports_address, the_last_report)
return the_last_report_address

3
common/url.py Normal file
View File

@ -0,0 +1,3 @@
class Url():
base_url = "https://www.baidu.com/"

View File

21
page/searchPage.py Normal file
View File

@ -0,0 +1,21 @@
from common.pageObject import PageObject, PageElement
from common.url import *
class SearchPage(PageObject):
# 测试网址
base_url = Url.base_url
url = base_url+'/'
# 查询元素
search = PageElement(id="kw")
wrong_search = PageElement(id="k")
search_btn = PageElement(id='su')
# 查询内容
search_content = "hello"
# 断言
search_content_assert = "hello"
search_content_assert_wrong = "hello12232423423"

View File

@ -0,0 +1,339 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Web自动化测试</title>
<meta name="generator" content="HTMLTestRunner 0.8.2"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css">
<script src="http://cdn.bootcss.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<script src="http://apps.bdimg.com/libs/Chart.js/0.2.0/Chart.min.js"></script>
<!-- <link href="https://cdn.bootcss.com/echarts/3.8.5/echarts.common.min.js" rel="stylesheet"> -->
<style type="text/css" media="screen">
body { font-family: verdana, arial, helvetica, sans-serif; font-size: 80%; }
table { font-size: 100%; }
pre { }
/* -- heading ---------------------------------------------------------------------- */
h1 {
font-size: 16pt;
color: gray;
}
.heading {
font-size: 12px;
margin-top: 0ex;
margin-bottom: 1ex;
margin-left: 10px;
}
.heading .attribute {
font-size: 12px;
margin-top: 1ex;
margin-bottom: 0;
}
.heading .description {
font-size: 12px;
margin-top: 4ex;
margin-bottom: 6ex;
}
/* -- css div popup ------------------------------------------------------------------------ */
a.popup_link {
}
a.popup_link:hover {
color: red;
}
.popup_window {
display: none;
position: relative;
left: 0px;
top: 0px;
/*border: solid #627173 1px; */
font-family: "Lucida Console", "Courier New", Courier, monospace;
text-align: left;
font-size: 12pt;
width: 500px;
}
}
/* -- report ------------------------------------------------------------------------ */
#show_detail_line {
margin-top: 3ex;
margin-bottom: 1ex;
margin-left: 10px;
}
#result_table {
width: 80%;
border-collapse: collapse;
border: 1px solid #777;
margin-left: 10px;
}
#header_row {
font-weight: bold;T
color: #606060;
background-color: #f5f5f5;
border-top-width: 10px;
border-color: #d6e9c6;
font-size: 12px;
}
#result_table td {
font-size:10px
border: 1px solid #f5f5f5;
padding: 2px;
}
#total_row { font-weight: bold; }
.passClass { background-color: #d6e9c6; }
.failClass { background-color: #faebcc; }
.errorClass { background-color: #ebccd1; }
.passCase { color: #6c6; }
.failCase { color: #c60; font-weight: bold; }
.errorCase { color: #c00; font-weight: bold; }
.hiddenRow { display: none; }
.testcase { margin-left: 2em; }
/* -- ending ---------------------------------------------------------------------- */
#ending {
}
/* -- chars ---------------------------------------------------------------------- */
.testChars {margin-left: 150px; font-size:10px; text-align:center;}
.btn-info1 {
color: #fff;
background-color: #28B463;
border-color: #d6e9c6;
}
.btn-info2 {
color: #fff;
background-color: #D4AC0D;
border-color: #faebcc;
}
.btn-info3 {
color: #fff;
background-color: #D35400;
border-color: #ebccd1;
}
</style>
</head>
<body>
<script language="javascript" type="text/javascript"><!--
output_list = Array();
/* level - 0:Summary; 1:Failed; 2:All */
function showCase(level) {
trs = document.getElementsByTagName("tr");
for (var i = 0; i < trs.length; i++) {
tr = trs[i];
id = tr.id;
if (id.substr(0,2) == 'ft') {
if (level < 1) {
tr.className = 'hiddenRow';
}
else {
tr.className = '';
}
}
if (id.substr(0,2) == 'pt') {
if (level > 1) {
tr.className = '';
}
else {
tr.className = 'hiddenRow';
}
}
}
}
function showClassDetail(cid, count) {
var id_list = Array(count);
var toHide = 1;
for (var i = 0; i < count; i++) {
tid0 = 't' + cid.substr(1) + '.' + (i+1);
tid = 'f' + tid0;
tr = document.getElementById(tid);
if (!tr) {
tid = 'p' + tid0;
tr = document.getElementById(tid);
}
id_list[i] = tid;
if (tr.className) {
toHide = 0;
}
}
for (var i = 0; i < count; i++) {
tid = id_list[i];
if (toHide) {
document.getElementById('div_'+tid).style.display = 'none'
document.getElementById(tid).className = 'hiddenRow';
}
else {
document.getElementById(tid).className = '';
}
}
}
function showTestDetail(div_id){
var details_div = document.getElementById(div_id)
var displayState = details_div.style.display
// alert(displayState)
if (displayState != 'block' ) {
displayState = 'block'
details_div.style.display = 'block'
}
else {
details_div.style.display = 'none'
}
}
function html_escape(s) {
s = s.replace(/&/g,'&amp;');
s = s.replace(/</g,'&lt;');
s = s.replace(/>/g,'&gt;');
return s;
}
/* obsoleted by detail in <div>
function showOutput(id, name) {
var w = window.open("", //url
name,
"resizable,scrollbars,status,width=800,height=450");
d = w.document;
d.write("<pre>");
d.write(html_escape(output_list[id]));
d.write("\n");
d.write("<a href='javascript:window.close()'>close</a>\n");
d.write("</pre>\n");
d.close();
}
*/
--></script>
<div class='heading'>
<h1>Web自动化测试</h1>
<p class='attribute'><strong>Start Time:</strong> 2019-02-26 10:45:51</p>
<p class='attribute'><strong>Duration:</strong> 0:00:32.794098</p>
<p class='attribute'><strong>Status:</strong> Pass 2 Error 1</p>
<p class='description'>详细测试结果如下:</p>
</div>
<div style="float:left; margin-left: 10px; font-size:12px">
<p> Test Case Pie charts </p>
<a class="btn btn-xs btn-info1">-Pass-</a><br>
<a class="btn btn-xs btn-info2">-Faild-</a><br>
<a class="btn btn-xs btn-info3">-Error-</a><br>
</div>
<div class="testChars" style="center">
<canvas id="myChart" width="250" height="250"></canvas>
</div>
<p id='show_detail_line' style="margin-left: 16px; font-size:12px">Show
<a href='javascript:showCase(0)' class="btn btn-xs btn-primary">Summary</a>
<a href='javascript:showCase(1)' class="btn btn-xs btn-danger">Failed</a>
<a href='javascript:showCase(2)' class="btn btn-xs btn-info">All</a>
</p>
<table id='result_table'>
<colgroup>
<col align='left' />
<col align='right' />
<col align='right' />
<col align='right' />
<col align='right' />
<col align='right' />
</colgroup>
<tr id='header_row' class="panel-title">
<td>Test Group/Test case</td>
<td>Count</td>
<td>Pass</td>
<td>Fail</td>
<td>Error</td>
<td>View</td>
</tr>
<tr class='errorClass'>
<td>test_baiduSearch.TestLogin</td>
<td>3</td>
<td>2</td>
<td>0</td>
<td>1</td>
<td><a href="javascript:showClassDetail('c1',3)">Detail</a></td>
</tr>
<tr id='pt1.1' class='hiddenRow'>
<td class='none'><div class='testcase'>test_search</div></td>
<td colspan='5' align='center'>pass</td>
</tr>
<tr id='pt1.2' class='hiddenRow'>
<td class='none'><div class='testcase'>test_search1</div></td>
<td colspan='5' align='center'>pass</td>
</tr>
<tr id='ft1.3' class='none'>
<td class='errorCase'><div class='testcase'>test_search2</div></td>
<td colspan='5' align='center'>
<!--css div popup start-->
<a class="popup_link" onfocus='this.blur();' href="javascript:showTestDetail('div_ft1.3')" >
error</a>
<div id='div_ft1.3' class="popup_window">
<div style='text-align: right; color:red;cursor:pointer'>
<a onfocus='this.blur();' onclick="document.getElementById('div_ft1.3').style.display = 'none' " >
[x]</a>
</div>
<pre>
ft1.3: Traceback (most recent call last):
File "D:\githublily\Automated-Test\testcase\test_baiduSearch.py", line 49, in test_search2
self.page.wrong_search = self.page.search_content
File "D:\githublily\Automated-Test\common\pageObject.py", line 101, in __set__
raise ValueError("Can't set value, element not found")
ValueError: Can't set value, element not found
</pre>
</div>
<!--css div popup end-->
</td>
</tr>
<tr id='total_row'>
<td>Total</td>
<td>3</td>
<td class="text text-success">2</td>
<td class="text text-danger">0</td>
<td class="text text-warning">1</td>
<td>&nbsp;</td>
</tr>
</table>
<div id='ending'>&nbsp;</div>
<script type="text/javascript">
var data = [
{
name: 'error',
value: 1,
color: "#D35400",
label: "Error",
labelColor: 'white',
labelFontSize: '16'
},
{
name: 'fail',
value : 0,
color : "#D4AC0D",
label: "Fail",
labelColor: 'white',
labelFontSize: '16'
},
{
name : 'pass',
value : 2,
color : "#28B463",
label : "Pass",
labelColor: 'white',
labelFontSize: '16'
}
]
var newopts = {
animationSteps: 100,
animationEasing: 'easeInOutQuart',
}
//Get the context of the canvas element we want to select
var ctx = document.getElementById("myChart").getContext("2d");
var myNewChart = new Chart(ctx).Pie(data,newopts);
</script>
</body>
</html>

File diff suppressed because one or more lines are too long

16
run.py
View File

@ -5,7 +5,7 @@ from common.sendEmail import SendEmail
def get_test_cases(dirpath):
# dirpath 是存放测试用例的文件路径
# dirpath是存放测试用例的文件路径
test_cases = unittest.TestSuite()
# 测试用例均使用"test_"开头命名
suites = unittest.defaultTestLoader.discover(dirpath, 'test_*.py', top_level_dir=dirpath)
@ -16,15 +16,15 @@ def get_test_cases(dirpath):
if __name__ == '__main__':
cases = get_test_cases('../testcase')
now = time.strftime("%Y-%m-%d %H_%M_%S")
test_reports_address = '../report'
now = time.strftime("%Y-%m-%d %H_%M_%S") # 报告生成时间
test_reports_address = '../report' # 测试报告存放位置
filename = '../report/' + now + 'report.html' # 设置报告文件名
f = open(filename, 'wb')
runner = HTMLTestRunner.HTMLTestRunner(stream=f, title=u'Web自动化测试', description=u'详细测试结果如下:')
runner.run(cases)
f.close()
time.sleep(6)
# 查找最新生成的测试报告地址
new_report_addr = SendEmail().acquire_report_address(test_reports_address)
# 自动发送邮件
SendEmail().send_email(new_report_addr)
# time.sleep(6)
# # 查找最新生成的测试报告地址
# new_report_addr = SendEmail().acquire_report_address(test_reports_address)
# # 自动发送邮件
# SendEmail().send_email(new_report_addr)

View File

@ -1,50 +0,0 @@
# coding=utf-8
from HTMLTestRunner import HTMLTestRunner
from selenium import webdriver
import time
import unittest
class TestLogin(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
self.url = "https://www.baidu.com/"
self.driver.get(self.url)
self.driver.maximize_window()
def tearDown(self):
self.driver.close()
def test_search(self):
self.driver.find_element_by_id("kw").send_keys("hello")
self.driver.find_element_by_id("su").click()
time.sleep(2)
self.assertIn("hello", self.driver.page_source)
def test_search1(self):
self.driver.find_element_by_id("kw").send_keys("hello")
self.driver.find_element_by_id("su").click()
time.sleep(2)
self.assertIn("hello1232323", self.driver.page_source)
def test_search2(self):
self.driver.find_element_by_id("k").send_keys("hello")
self.driver.find_element_by_id("su").click()
time.sleep(2)
self.assertIn("hello1232323", self.driver.page_source)
if __name__ == '__main__':
# now = time.strftime("%Y-%m-%d-%H-%M-%S")
# suite = unittest.TestSuite()
# suite.addTest(TestLogin("test_search"))
# suite.addTest(TestLogin("test_search1"))
# suite.addTest(TestLogin("test_search2"))
# path = "../report/" + now + "result.html"
# fp = open(path, 'wb')
#
# runner = HTMLTestRunner(stream=fp, title=u"Web页面自动化测试", description=u"测试查询功能")
# runner.run(suite)
# fp.close
unittest.main()

View File

@ -0,0 +1,75 @@
# coding=utf-8
from HTMLTestRunner import HTMLTestRunner
from selenium import webdriver
from page.searchPage import SearchPage
import time
import unittest
from page.searchPage import *
class TestLogin(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
self.url = SearchPage.url
self.driver.maximize_window()
self.page = SearchPage(self.driver)
self.page.get(self.url)
def tearDown(self):
self.driver.close()
def test_search(self):
# 使用pageObject模式时的web页面自动化测试代码
self.page.search = self.page.search_content
self.page.search_btn.click()
time.sleep(2)
self.assertIn(self.page.search_content_assert, self.driver.page_source)
# # 未使用pageObject模式时的web页面自动化测试代码
# self.driver.find_element_by_id("kw").send_keys("hello")
# self.driver.find_element_by_id("su").click()
# time.sleep(2)
# self.assertIn("hello", self.driver.page_source)
def test_search1(self):
# 错误的断言导致测试用例failed
self.page.search = self.page.search_content
self.page.search_btn.click()
time.sleep(2)
self.assertIn(self.page.search_content_assert_wrong, self.driver.page_source)
# # 未使用pageObject模式的web页面自动化测试代码
# self.driver.find_element_by_id("kw").send_keys("hello")
# self.driver.find_element_by_id("su").click()
# time.sleep(2)
# self.assertIn("hello1232323", self.driver.page_source)
def test_search2(self):
# 元素值错误导致的自动化测试用例error
self.page.wrong_search = self.page.search_content
self.page.search_btn.click()
time.sleep(2)
self.assertIn(self.page.search_content_assert, self.driver.page_source)
# # 未使用pageObject模式的web页面自动化测试代码
# self.driver.find_element_by_id("k").send_keys("hello")
# self.driver.find_element_by_id("su").click()
# time.sleep(2)
# self.assertIn("hello", self.driver.page_source)
if __name__ == '__main__':
# 当没有run.py是可以单独使用以下语句生成测试报告
# now = time.strftime("%Y-%m-%d-%H-%M-%S")
# suite = unittest.TestSuite()
# suite.addTest(TestLogin("test_search"))
# suite.addTest(TestLogin("test_search1"))
# suite.addTest(TestLogin("test_search2"))
# path = "../report/" + now + "result.html"
# fp = open(path, 'wb')
#
# runner = HTMLTestRunner(stream=fp, title=u"Web页面自动化测试", description=u"测试查询功能")
# runner.run(suite)
# fp.close()
unittest.main()