1""" 2 * Copyright (c) 2023 iSoftStone Information Technology (Group) Co.,Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14""" 15import unittest 16from Tool import WebView 17 18class Test(unittest.TestCase): 19 @classmethod # 初始化测试环境且只会执行一次 20 def setUp(self) -> None: 21 self.LE = WebView() 22 self.LE.init_webview(test_package='com.example.myapplication') # 运行chromeDriver 23 24 def test_fetch_001(self): 25 self.LE.init_runner('test_fetch_001') # 打开runner页面 26 self.LE.click_js() # 取消勾选js 27 self.LE.click_manual() # 取消勾选manual 28 self.LE.send_path('fetch/corb/img-html-correctly-labeled.sub.html') # 是否进入指定路径 默认是/ 即全部路径 29 self.LE.start_test() # 点击start test 按钮 30 self.LE.click_show_test() # 点击show test按钮 31 self.LE.test_screenshot('/html/body/img', "test") # test页面截图 32 self.LE.click_show_ref() # 点击show reference按钮 33 self.LE.ref_screenshot('/html/body/img', "ref") # reference页面截图 34 self.LE.test_assert("test", "ref") # 断言 35 self.LE.runner_end('test_fetch_001') 36 37 def test_fetch_002(self): 38 self.LE.init_runner('test_fetch_002') # 打开runner页面 39 self.LE.click_js() # 取消勾选js 40 self.LE.click_manual() # 取消勾选manual 41 self.LE.send_path('fetch/corb/img-png-mislabeled-as-html-nosniff.tentative.sub.html') # 是否进入指定路径 默认是/ 即全部路径 42 self.LE.start_test() # 点击start test 按钮 43 self.LE.click_show_test() # 点击show test按钮 44 self.LE.test_screenshot('/html/body/img', "test") # test页面截图 45 self.LE.click_show_ref() # 点击show reference按钮 46 self.LE.ref_screenshot('/html/body/img', "ref") # reference页面截图 47 self.LE.test_assert("test", "ref") # 断言 48 self.LE.runner_end('test_fetch_002') 49 50 def test_fetch_003(self): 51 self.LE.init_runner('test_fetch_003') # 打开runner页面 52 self.LE.click_js() # 取消勾选js 53 self.LE.click_manual() # 取消勾选manual 54 self.LE.send_path('fetch/corb/img-png-mislabeled-as-html.sub.html') # 是否进入指定路径 默认是/ 即全部路径 55 self.LE.start_test() # 点击start test 按钮 56 self.LE.click_show_test() # 点击show test按钮 57 self.LE.test_screenshot('/html/body', "test") # test页面截图 58 self.LE.click_show_ref() # 点击show reference按钮 59 self.LE.ref_screenshot('/html/body', "ref") # reference页面截图 60 self.LE.test_assert("test", "ref") # 断言 61 self.LE.runner_end('test_fetch_003') 62 63 def test_fetch_004(self): 64 self.LE.init_runner('test_fetch_004') # 打开runner页面 65 self.LE.click_js() # 取消勾选js 66 self.LE.click_manual() # 取消勾选manual 67 self.LE.send_path('fetch/corb/img-svg-doctype-html-mimetype-empty.sub.html') # 是否进入指定路径 默认是/ 即全部路径 68 self.LE.start_test() # 点击start test 按钮 69 self.LE.click_show_test() # 点击show test按钮 70 self.LE.test_screenshot('/html/body/img', "test") # test页面截图 71 self.LE.click_show_ref() # 点击show reference按钮 72 self.LE.ref_screenshot('/html/body/img', "ref") # reference页面截图 73 self.LE.test_assert("test", "ref") # 断言 74 self.LE.runner_end('test_fetch_004') 75 76 def test_fetch_005(self): 77 self.LE.init_runner('test_fetch_005') # 打开runner页面 78 self.LE.click_js() # 取消勾选js 79 self.LE.click_manual() # 取消勾选manual 80 self.LE.send_path('fetch/corb/img-svg-doctype-html-mimetype-svg.sub.html') # 是否进入指定路径 默认是/ 即全部路径 81 self.LE.start_test() # 点击start test 按钮 82 self.LE.click_show_test() # 点击show test按钮 83 self.LE.test_screenshot('/html/body', "test") # test页面截图 84 self.LE.click_show_ref() # 点击show reference按钮 85 self.LE.ref_screenshot('/html/body', "ref") # reference页面截图 86 self.LE.test_assert("test", "ref") # 断言 87 self.LE.runner_end('test_fetch_005') 88 89 def test_fetch_006(self): 90 self.LE.init_runner('test_fetch_006') # 打开runner页面 91 self.LE.click_js() # 取消勾选js 92 self.LE.click_manual() # 取消勾选manual 93 self.LE.send_path('fetch/corb/img-svg-labeled-as-dash.sub.html') # 是否进入指定路径 默认是/ 即全部路径 94 self.LE.start_test() # 点击start test 按钮 95 self.LE.click_show_test() # 点击show test按钮 96 self.LE.test_screenshot('/html/body/img', "test") # test页面截图 97 self.LE.click_show_ref() # 点击show reference按钮 98 self.LE.ref_screenshot('/html/body/img', "ref") # reference页面截图 99 self.LE.test_assert("test", "ref") # 断言 100 self.LE.runner_end('test_fetch_006') 101 102 def test_fetch_007(self): 103 self.LE.init_runner('test_fetch_007') # 打开runner页面 104 self.LE.click_js() # 取消勾选js 105 self.LE.click_manual() # 取消勾选manual 106 self.LE.send_path('fetch/corb/img-svg-labeled-as-svg-xml.sub.html') # 是否进入指定路径 默认是/ 即全部路径 107 self.LE.start_test() # 点击start test 按钮 108 self.LE.click_show_test() # 点击show test按钮 109 self.LE.test_screenshot('/html/body', "test") # test页面截图 110 self.LE.click_show_ref() # 点击show reference按钮 111 self.LE.ref_screenshot('/html/body', "ref") # reference页面截图 112 self.LE.test_assert("test", "ref") # 断言 113 self.LE.runner_end('test_fetch_007') 114 115 def test_fetch_008(self): 116 self.LE.init_runner('test_fetch_008') # 打开runner页面 117 self.LE.click_js() # 取消勾选js 118 self.LE.click_manual() # 取消勾选manual 119 self.LE.send_path('fetch/corb/img-svg-xml-decl.sub.html') # 是否进入指定路径 默认是/ 即全部路径 120 self.LE.start_test() # 点击start test 按钮 121 self.LE.click_show_test() # 点击show test按钮 122 self.LE.test_screenshot('/html/body', "test") # test页面截图 123 self.LE.click_show_ref() # 点击show reference按钮 124 self.LE.ref_screenshot('/html/body', "ref") # reference页面截图 125 self.LE.test_assert("test", "ref") # 断言 126 self.LE.runner_end('test_fetch_008') 127 128 def test_fetch_009(self): 129 self.LE.init_runner('test_fetch_009') # 打开runner页面 130 self.LE.click_js() # 取消勾选js 131 self.LE.click_manual() # 取消勾选manual 132 self.LE.send_path('fetch/http-cache/basic-auth-cache-test.html') # 是否进入指定路径 默认是/ 即全部路径 133 self.LE.start_test() # 点击start test 按钮 134 self.LE.click_show_test() # 点击show test按钮 135 self.LE.test_screenshot('/html/body/img', "test") # test页面截图 136 self.LE.click_show_ref() # 点击show reference按钮 137 self.LE.ref_screenshot('/html/body/img[1]', "ref") # reference页面截图 138 self.LE.ref_screenshot('/html/body/img[2]', "ref") # reference页面截图 139 self.LE.test_assert("test", "ref") # 断言 140 self.LE.runner_end('test_fetch_009') 141 142 def test_fetch_010(self): 143 self.LE.init_runner('test_fetch_010') # 打开runner页面 144 self.LE.click_js() # 取消勾选js 145 self.LE.click_manual() # 取消勾选manual 146 self.LE.send_path('fetch/orb/tentative/img-png-mislabeled-as-html.sub.html') # 是否进入指定路径 默认是/ 即全部路径 147 self.LE.start_test() # 点击start test 按钮 148 self.LE.click_show_test() # 点击show test按钮 149 self.LE.test_screenshot('/html/body', "test") # test页面截图 150 self.LE.click_show_ref() # 点击show reference按钮 151 self.LE.ref_screenshot('/html/body', "ref") # reference页面截图 152 self.LE.test_assert("test", "ref") # 断言 153 self.LE.runner_end('test_fetch_010') 154 155 def test_fetch_011(self): 156 self.LE.init_runner('test_fetch_011') # 打开runner页面 157 self.LE.click_js() # 取消勾选js 158 self.LE.click_manual() # 取消勾选manual 159 self.LE.send_path('fetch/orb/tentative/img-png-unlabeled.sub.html') # 是否进入指定路径 默认是/ 即全部路径 160 self.LE.start_test() # 点击start test 按钮 161 self.LE.click_show_test() # 点击show test按钮 162 self.LE.test_screenshot('/html/body', "test") # test页面截图 163 self.LE.click_show_ref() # 点击show reference按钮 164 self.LE.ref_screenshot('/html/body', "ref") # reference页面截图 165 self.LE.test_assert("test", "ref") # 断言 166 self.LE.runner_end('test_fetch_011') 167 168if __name__ == '__main__': 169 suite = unittest.TestSuite() # 实例化TestSuite 170 suite.addTest(Test("test_add_02")) # 添加测试用例 171 suite.addTest(Test("test_add_01")) 172 runner = unittest.TextTestRunner() # 实例化TextTestRunner 173 runner.run(suite) # 传入suite并执行测试用例 174