How to use get_source method in avocado

Best Python code snippet using avocado_python

test_courier_menu.py

Source:test_courier_menu.py Github

copy

Full Screen

1#!/usr/bin/env python32# -*- coding:utf-8 -*-3import re4import pytest5import allure6from datetime import datetime7from utils.times import sleep8from utils.logger import log9from common.readconfig import ini10from page_object.loginpage import LoginPage11from page_object.menupage import MenuPage, Service, Link, ServiceConfig, ConfigManage, Blacklist, Location, Conditional, Statistics12# 系统run时改为False13auto = False14# @pytest.mark.skip(reason="暂时跳过测试")15@allure.feature("courier菜单栏点击")16class TestService:17 @pytest.fixture(scope='session', autouse=True)18 def open_devops(self, drivers):19 """打开courier"""20 login = LoginPage(drivers)21 login.get_url(ini.url)22 login.input_username_login('admin')23 login.input_password_login('password')24 login.click_login()25 login.click_Menu("服务管理")26 @allure.story("点击服务管理")27 def test_001(self, drivers):28 """点击服务管理"""29 serv = Service(drivers)30 serv.click_Menu('服务管理')31 serv.waite_element('服务名')32 result = re.search(r'服务列表', serv.get_source)33 log.info(result)34 assert result35 @allure.story("服务管理搜索功能")36 def test_002(self, drivers):37 """服务管理搜索功能"""38 serv = Service(drivers)39 serv.input_servername("服务名搜索测试")40 serv.click_search()41 serv.click_reset()42 serv.input_devname("设备名称搜索测试")43 serv.click_search()44 serv.click_reset()45 serv.input_colonyname("集群名称搜索测试")46 serv.click_search()47 serv.click_reset()48 serv.input_servername("服务名搜索测试")49 serv.input_devname("设备名称搜索测试")50 serv.input_colonyname("集群名称搜索测试")51 serv.click_search()52 serv.click_reset()53 @allure.story("注销异常按钮")54 def test_003(self, drivers):55 """注销异常按钮"""56 serv = Service(drivers)57 serv.click_logoff()58 result = re.search(r'注销异常服务成功', serv.get_source)59 log.info(result)60 assert result61 @allure.story("刷新按钮")62 def test_004(self, drivers):63 """点击刷新按钮"""64 serv = Service(drivers)65 serv.click_refresh()66 @allure.story("修改按钮")67 def test_005(self, drivers):68 """点击修改按钮"""69 serv = Service(drivers)70 serv.click_change(0)71 result = re.search(r'修改服务', serv.get_source)72 log.info(result)73 assert result74 serv.click_Canle()75 @allure.story("输入经度")76 def test_006(self, drivers):77 """经度测试"""78 longtitude = "13.24"79 serv = Service(drivers)80 serv.click_change(0)81 serv.input_longtitude(longtitude)82 serv.click_Canle()83 serv.click_change(0)84 serv.input_longtitude(longtitude)85 serv.click_Define()86 result = re.search(r'修改服务成功', serv.get_source)87 log.info(result)88 assert result89 serv.click_change(0)90 result = re.search(longtitude, serv.get_source)91 log.info(result)92 assert result93 serv.click_Canle()94 @allure.story("输入纬度")95 def test_007(self, drivers):96 """纬度测试"""97 latitude = "165.24"98 serv = Service(drivers)99 serv.click_change(0)100 serv.input_latitude(latitude)101 serv.click_Canle()102 serv.click_change(0)103 serv.input_latitude(latitude)104 serv.click_Define()105 result = re.search(r'修改服务成功', serv.get_source)106 log.info(result)107 assert result108 serv.click_change(0)109 result = re.search(latitude, serv.get_source)110 log.info(result)111 assert result112 serv.click_Canle()113 @allure.story("服务描述")114 def test_008(self, drivers):115 """服务描述测试"""116 basic = "测试服务描述,随便写的一点文本内容"117 serv = Service(drivers)118 serv.click_change(0)119 serv.input_basic(basic)120 serv.click_Canle()121 serv.click_change(0)122 serv.input_basic(basic)123 serv.click_Define()124 result = re.search(r'修改服务成功', serv.get_source)125 log.info(result)126 assert result127 serv.click_change(0)128 result = re.search(basic, serv.get_source)129 log.info(result)130 assert result131 serv.click_Canle()132 @allure.story("修改服务模块参数一同修改")133 def test_09(self, drivers):134 """修改服务参数模块一同修改测试"""135 longtitude, latitude, basic = "12.31","123.98","测试服务描述,随便写的一点文本内容"136 serv = Service(drivers)137 # click_change(0) 代表修改元素列表中第一个元素138 serv.click_change(0)139 serv.input_longtitude(longtitude)140 serv.input_latitude(latitude)141 serv.input_basic(basic)142 serv.click_Canle()143 serv.click_change(0)144 serv.input_longtitude(longtitude)145 serv.input_latitude(latitude)146 serv.input_basic(basic)147 serv.click_Define()148 result = re.search(r'修改服务成功', serv.get_source)149 log.info(result)150 assert result151 serv.click_change(0)152 result1 = re.search(basic, serv.get_source)153 result2 = re.search(longtitude, serv.get_source)154 result3 = re.search(latitude, serv.get_source)155 log.info(f"匹配信息:result1:{result1},\nresult2:{result2},\nresult3:{result3}")156 assert result1 and result2 and result3157 serv.click_Canle()158 @pytest.mark.skip("系统run的时候不需要注销,否则后续用例无法正常运行")159 @allure.story("注销按钮")160 def test_010(self, drivers):161 """注销按钮测试"""162 serv = Service(drivers)163 serv.click_logoffs(0)164 serv.click_ButtoNo(0)165 sleep()166 serv.click_logoffs(0)167 serv.click_ButtonYes(0)168 result = re.search(r'注销成功', serv.get_source)169 log.info(result)170 assert result171@allure.feature("courier链路追踪")172class TestLink:173 # @pytest.mark.skip("整体run的时候,不启动前置条件")174 @pytest.fixture(scope='session', autouse=auto)175 def open_devops(self, drivers):176 """打开courier"""177 login = LoginPage(drivers)178 login.get_url(ini.url)179 login.input_username_login('admin')180 login.input_password_login('password')181 login.click_login()182 login.click_Menu("链路追踪")183 @allure.story("点击链路追踪")184 def test_001(self, drivers):185 """点击服务管理"""186 link = Link(drivers)187 link.click_Menu('链路追踪')188 link.waite_element("根服务名")189 result = re.search(r'链路追踪记录列表', link.get_source)190 log.info(result)191 assert result192 @allure.story("根服务名搜索功能")193 def test_002(self, drivers):194 """链路追踪搜索功能"""195 link = Link(drivers)196 link.input_rootservername("conditionservice")197 link.click_search()198 result = re.search(r'<span>conditionservice', link.get_source)199 log.info(result)200 assert result201 link.click_reset()202 link.input_rootservername("根服务名搜索功能")203 link.click_search()204 result = re.search(r'暂无数据', link.get_source)205 log.info(result)206 assert result207 link.click_reset()208 @allure.story("日期范围搜索功能")209 def test_003(self, drivers):210 """服务管理搜索功能"""211 # 开始日期212 link = Link(drivers)213 link.click_Menu("开始日期")214 result = re.search(r'2022年', link.get_source)215 log.info(result)216 assert result217 link.click_Menu('年份按钮')218 link.click_Menu('2020年')219 link.click_Menu('月份按钮')220 link.click_Menu('1月')221 link.click_Menu('1日')222 link.click_datesubmit()223 result = re.search(r'2020-01-01', link.get_source)224 log.info(result)225 assert result226 # 结束日期227 link.input_enddate(datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M:%S"))228 link.click_datesubmit()229 result = re.search(datetime.strftime(datetime.now(), "%Y-%m-%d"), link.get_source)230 log.info(result)231 assert result232 link.click_search()233 link.click_search()234 result = re.search(r'开始日期', link.get_source)235 log.info(result)236 assert result237 @allure.story("链路追踪列表刷新")238 def test_004(self, drivers):239 """链路追踪列表刷新"""240 link = Link(drivers)241 link.click_refresh()242 result = re.search(r'disabled', link.get_source)243 log.info(result)244 assert result245 @allure.story("查看列表第一个链路追踪详情")246 def test_005(self, drivers):247 """查看列表第一个链路追踪详情"""248 link = Link(drivers)249 link.click_lookup(0)250 link.click_Linkinfo(1)251 result = re.search(r'链路追踪详情', link.get_source)252 log.info(result)253 assert result254 link.click_Menu('返回链路追踪')255 result = re.search(r'链路追踪记录列表', link.get_source)256 log.info(result)257@allure.feature("courier服务配置")258class TestServiceConfig:259 @pytest.fixture(scope='session', autouse=auto)260 def open_devops(self, drivers):261 """打开courier"""262 login = LoginPage(drivers)263 login.get_url(ini.url)264 login.input_username_login('admin')265 login.input_password_login('password')266 login.click_login()267 login.click_Menu("服务配置")268 @allure.story("点击服务配置")269 def test_001(self, drivers):270 """点击服务管理"""271 sercof = ServiceConfig(drivers)272 sercof.click_Menu('服务配置')273 sercof.waite_element("key")274 result = re.search(r'配置类型', sercof.get_source)275 log.info(result)276 assert result277 @allure.story("新建配置单个Global")278 def test_002(self, drivers):279 """新建配置单个Global"""280 sercof = ServiceConfig(drivers)281 sercof.click_add(0)282 result = re.search(r'data.prop', sercof.get_source)283 log.info(result)284 assert result285 sercof.click_Menu('Global')286 sercof.input_key1("key1")287 sercof.input_value1('value1')288 sercof.click_Canle()289 result = re.search(r'配置类型', sercof.get_source)290 log.info(result)291 assert result292 # 新建配置保存293 sercof.click_add(0)294 result = re.search(r'data.prop', sercof.get_source)295 log.info(result)296 assert result297 sercof.click_Menu('Global')298 sercof.input_key1("key1")299 sercof.input_value1('value1')300 sercof.click_Define()301 result = re.search(r'key1', sercof.get_source)302 log.info(result)303 assert result304 sercof.click_del(0)305 result = re.search(r'删除成功', sercof.get_source)306 log.info(result)307 assert result308 @allure.story("新建配置多个Global")309 def test_003(self, drivers):310 """新建配置多个Global"""311 sercof = ServiceConfig(drivers)312 sercof.click_add(0)313 result = re.search(r'data.prop', sercof.get_source)314 log.info(result)315 assert result316 sercof.click_Menu('Global')317 sercof.input_key1("key1")318 sercof.input_value1('value1')319 sercof.click_Menu('添加一行数据')320 result = re.search(r'删除', sercof.get_source)321 log.info(result)322 assert result323 sercof.input_key2("key2")324 sercof.input_value2("value2")325 sercof.click_contentdel(1)326 # sleep()327 # sercof.click_ButtoNo(0)328 # sercof.click_contentdel(1)329 # sleep(2)330 sercof.click_ButtonYes(0)331 sercof.click_Menu('添加一行数据')332 result = re.search(r'删除', sercof.get_source)333 log.info(result)334 assert result335 sercof.input_key2("key2")336 sercof.input_value2("value2")337 sercof.click_Define()338 result = re.search(r'value2', sercof.get_source)339 log.info(result)340 assert result341 sercof.click_del(0)342 sercof.click_del(0)343 result = re.search(r'删除成功', sercof.get_source)344 log.info(result)345 assert result346 @allure.story("编辑配置Global")347 def test_004(self, drivers):348 """编辑配置Global"""349 # 新建配置350 sercof = ServiceConfig(drivers)351 sercof.click_add(0)352 result = re.search(r'data.prop', sercof.get_source)353 log.info(result)354 assert result355 sercof.click_Menu('Global')356 sercof.input_key1("key1")357 sercof.input_value1('value1')358 sercof.click_Define()359 result = re.search(r'key1', sercof.get_source)360 log.info(result)361 assert result362 # 编辑配置363 sercof.click_edit(0)364 sercof.input_value1('value2')365 sercof.click_Define()366 result = re.search(r'value2', sercof.get_source)367 log.info(result)368 assert result369 sercof.click_del(0)370 result = re.search(r'删除成功', sercof.get_source)371 log.info(result)372 assert result373 @allure.story("新建配置单个Service")374 def test_005(self, drivers):375 """新建配置单个Service"""376 sercof = ServiceConfig(drivers)377 sercof.click_add(0)378 result = re.search(r'data.prop', sercof.get_source)379 log.info(result)380 assert result381 sercof.click_Menu('service')382 result = re.search(r'服务名', sercof.get_source)383 log.info(result)384 assert result385 sercof.input_servicename('service')386 sercof.input_key1("key1")387 sercof.input_value1('value1')388 sercof.click_Canle()389 result = re.search(r'配置类型', sercof.get_source)390 log.info(result)391 assert result392 # 新建配置保存393 sercof.click_add(0)394 result = re.search(r'data.prop', sercof.get_source)395 log.info(result)396 assert result397 sercof.click_Menu('service')398 sercof.input_servicename('service1')399 sercof.input_key1("key1")400 sercof.input_value1('value1')401 sercof.click_Define()402 result = re.search(r'service1', sercof.get_source)403 log.info(result)404 assert result405 sercof.click_del(0)406 result = re.search(r'删除成功', sercof.get_source)407 log.info(result)408 assert result409 @allure.story("新建配置多个Service")410 def test_006(self, drivers):411 """新建配置多个Service"""412 sercof = ServiceConfig(drivers)413 sercof.click_add(0)414 result = re.search(r'data.prop', sercof.get_source)415 log.info(result)416 assert result417 sercof.click_Menu('service')418 result = re.search(r'服务名', sercof.get_source)419 log.info(result)420 assert result421 sercof.input_servicename('service1')422 sercof.input_key1("key1")423 sercof.input_value1('value1')424 sercof.click_Menu('添加一行数据')425 result = re.search(r'删除', sercof.get_source)426 log.info(result)427 assert result428 sercof.input_key2("key2")429 sercof.input_value2("value2")430 # sercof.click_contentdel(1)431 # sercof.click_ButtoNo(0)432 sercof.click_contentdel(1)433 sercof.click_ButtonYes(0)434 sercof.click_Menu('添加一行数据')435 result = re.search(r'删除', sercof.get_source)436 log.info(result)437 assert result438 sercof.input_key2("key2")439 sercof.input_value2("value2")440 sercof.click_Define()441 result = re.search(r'value2', sercof.get_source)442 log.info(result)443 assert result444 sercof.click_del(0)445 sercof.click_del(0)446 result = re.search(r'删除成功', sercof.get_source)447 log.info(result)448 assert result449 @allure.story("编辑配置Global")450 def test_007(self, drivers):451 """编辑配置Global"""452 # 新建配置453 sercof = ServiceConfig(drivers)454 sercof.click_add(0)455 result = re.search(r'data.prop', sercof.get_source)456 log.info(result)457 assert result458 sercof.click_Menu('service')459 result = re.search(r'服务名', sercof.get_source)460 log.info(result)461 assert result462 sercof.input_servicename('service1')463 sercof.input_key1("key1")464 sercof.input_value1('value1')465 sercof.click_Define()466 result = re.search(r'service1', sercof.get_source)467 log.info(result)468 assert result469 # 编辑配置470 sercof.click_edit(0)471 sercof.input_value1('value2')472 sercof.click_Define()473 result = re.search(r'value2', sercof.get_source)474 log.info(result)475 assert result476 sercof.click_del(0)477 result = re.search(r'删除成功', sercof.get_source)478 log.info(result)479 assert result480 @allure.story("服务配置刷新")481 def test_008(self, drivers):482 """服务配置刷新"""483 # 新建配置484 sercof = ServiceConfig(drivers)485 sercof.click_refresh()486 result = re.search(r'anticon anticon-reload ant-tooltip-open', sercof.get_source)487 log.info(result)488 assert result489 @allure.story("服务配置搜索")490 def test_009(self, drivers):491 """服务配置搜索"""492 # 新建Global配置493 sercof = ServiceConfig(drivers)494 sercof.click_add(0)495 result = re.search(r'data.prop', sercof.get_source)496 log.info(result)497 assert result498 sercof.click_Menu('Global')499 sercof.input_key1("key1")500 sercof.input_value1('value1')501 sercof.click_Define()502 result = re.search(r'key1', sercof.get_source)503 log.info(result)504 assert result505 # 新建service配置506 sercof = ServiceConfig(drivers)507 sercof.click_add(0)508 result = re.search(r'data.prop', sercof.get_source)509 log.info(result)510 assert result511 sercof.click_Menu('service')512 result = re.search(r'服务名', sercof.get_source)513 log.info(result)514 assert result515 sercof.input_servicename('service1')516 sercof.input_key1("key2")517 sercof.input_value1('value2')518 sercof.click_Define()519 result = re.search(r'service1', sercof.get_source)520 log.info(result)521 assert result522 # key搜索523 sercof.input_key("key1")524 sercof.click_search()525 result = re.search(r'key2', sercof.get_source)526 log.info(result)527 assert not result528 sercof.click_reset()529 sercof.input_key('key2')530 sercof.click_search()531 result = re.search(r'key1', sercof.get_source)532 log.info(result)533 assert not result534 sercof.click_reset()535 sercof.input_key('key3')536 sercof.click_search()537 result = re.search(r'key1', sercof.get_source)538 result2 = re.search(r'key2', sercof.get_source)539 log.info("{result} \n {result2}")540 assert not result and not result2541 sercof.click_reset()542 # 服务名称搜索543 sercof.input_configType('global')544 sercof.click_search()545 result = re.search(r'service1', sercof.get_source)546 log.info(result)547 assert not result548 sercof.click_reset()549 sercof.input_configType('service1')550 sercof.click_search()551 result = re.search(r'global</td>', sercof.get_source)552 log.info(result)553 assert not result554 sercof.click_reset()555 sercof.input_configType('key3')556 sercof.click_search()557 result = re.search(r'global</td>', sercof.get_source)558 result2 = re.search(r'service1', sercof.get_source)559 log.info("{result} \n {result2}")560 assert not result and not result2561 sercof.click_reset()562 sercof.click_del(0)563 sercof.click_del(0)564 result = re.search(r'删除成功', sercof.get_source)565 log.info(result)566 assert result567@allure.feature("配置管理")568class TestConfigManage:569 @pytest.fixture(scope='session', autouse=auto)570 def open_devops(self, drivers):571 """打开courier"""572 login = LoginPage(drivers)573 login.get_url(ini.url)574 login.input_username_login('admin')575 login.input_password_login('password')576 login.click_login()577 login.click_Menu("服务网关")578 login.click_Menu("配置管理")579 @allure.story("点击配置管理")580 def test_001(self, drivers):581 """点击服务管理"""582 confma = ConfigManage(drivers)583 # 系统run的时候开启这一条,否则无法跳转配置管理584 confma.click_Menu("服务网关")585 confma.click_Menu('配置管理')586 confma.waite_element('随机')587 result = re.search(r'负载均衡', confma.get_source)588 log.info(result)589 assert result590 @allure.story("负载均衡选择")591 def test_002(self, drivers):592 """负载均衡选择"""593 confma = ConfigManage(drivers)594 confma.click_Menu('负载均衡')595 result = re.search(r'随机', confma.get_source)596 log.info(result)597 assert result598 confma.click_Menu("轮询")599 confma.click_Canle()600 confma.click_Menu("轮询")601 confma.click_close()602 confma.click_Menu("轮询")603 confma.click_Define()604 confma.click_Menu("一致性哈希")605 confma.click_Canle()606 confma.click_Menu("一致性哈希")607 confma.click_close()608 confma.click_Menu("一致性哈希")609 confma.click_Define()610 confma.click_Menu("最小连接数")611 confma.click_Canle()612 confma.click_Menu("最小连接数")613 confma.click_close()614 confma.click_Menu("最小连接数")615 confma.click_Define()616 confma.click_Menu("随机")617 confma.click_Canle()618 confma.click_Menu("随机")619 confma.click_close()620 confma.click_Menu("随机")621 confma.click_Define()622 @allure.story("服务熔断")623 def test_003(self, drivers):624 """服务熔断测试"""625 confma = ConfigManage(drivers)626 confma.click_Menu('服务熔断')627 result = re.search(r'服务熔断默认阈值', confma.get_source)628 log.info(result)629 assert result630 # 服务熔断开关631 confma.click_switch(0)632 result = re.search(r'aria-checked="true"', confma.get_source)633 log.info(result)634 assert result635 confma.click_switch(0)636 result = re.search(r'aria-checked="false"', confma.get_source)637 log.info(result)638 assert result639 # 服务默认阈值640 confma.click_DefaultEdit()641 confma.input_box('')642 confma.click_Tick()643 result = re.search(r'服务熔断默认阈值不能为空', confma.get_source)644 log.info(result)645 assert result646 confma.input_box('0')647 confma.click_Tick()648 result = re.search(r'值不能小于1', confma.get_source)649 log.info(result)650 assert result651 confma.input_box('101')652 confma.click_Tick()653 result = re.search(r'值不能大于100', confma.get_source)654 log.info(result)655 assert result656 confma.input_box('6')657 confma.click_fork()658 confma.click_DefaultEdit()659 confma.input_box('11')660 confma.click_Tick()661 result = re.search(r'操作成功', confma.get_source)662 log.info(result)663 assert result664 # 熔断阈值665 confma.click_list(0)666 confma.input_box('')667 confma.click_Tick()668 result = re.search(r'操作成功', confma.get_source)669 log.info(result)670 assert result671 confma.click_list(0)672 confma.input_box('0')673 confma.click_Tick()674 result = re.search(r'值不能小于1', confma.get_source)675 log.info(result)676 assert result677 confma.input_box('101')678 confma.click_Tick()679 result = re.search(r'值不能大于100', confma.get_source)680 log.info(result)681 assert result682 confma.click_fork()683 sleep()684 confma.click_list(0)685 confma.input_box('6')686 confma.click_fork()687 confma.click_list(0)688 confma.input_box('13')689 confma.click_Tick()690 result = re.search(r'<span>13</span>', confma.get_source)691 log.info(result)692 assert result693 @allure.story("流量控制")694 def test_004(self, drivers):695 """流量控制测试"""696 confma = ConfigManage(drivers)697 confma.click_Menu('流量控制')698 result = re.search(r'流量控制默认网速', confma.get_source)699 log.info(result)700 assert result701 # 流量控制开关702 confma.click_switch(0)703 result = re.search(r'aria-checked="true"', confma.get_source)704 log.info(result)705 assert result706 confma.click_switch(0)707 result = re.search(r'aria-checked="false"', confma.get_source)708 log.info(result)709 assert result710 # 流量控制默认网速711 confma.click_DefaultEdit()712 confma.input_box('-1')713 confma.click_Tick()714 result = re.search(r'值不能小于0', confma.get_source)715 log.info(result)716 assert result717 confma.input_box('101')718 confma.click_Tick()719 result = re.search(r'值不能大于100', confma.get_source)720 log.info(result)721 assert result722 confma.input_box('6')723 confma.click_fork()724 confma.click_DefaultEdit()725 confma.input_box('11')726 confma.click_Tick()727 result = re.search(r'操作成功', confma.get_source)728 log.info(result)729 assert result730 # 流量权重731 confma.click_list(0)732 confma.input_box('-1')733 confma.click_Tick()734 result = re.search(r'值不能小于0', confma.get_source)735 log.info(result)736 assert result737 confma.input_box('0.1')738 confma.click_Tick()739 result = re.search(r'只能输入整数', confma.get_source)740 log.info(result)741 assert result742 confma.input_box('101')743 confma.click_Tick()744 result = re.search(r'值不能大于100', confma.get_source)745 log.info(result)746 assert result747 confma.click_fork()748 sleep()749 confma.click_list(0)750 confma.input_box('6')751 confma.click_fork()752 confma.click_list(0)753 confma.input_box('13')754 confma.click_Tick()755 result = re.search(r'<span>13</span>', confma.get_source)756 log.info(result)757 assert result758 @allure.story("服务质量")759 def test_005(self, drivers):760 """服务质量测试"""761 confma = ConfigManage(drivers)762 confma.click_Menu('服务质量')763 result = re.search(r'保留值', confma.get_source)764 log.info(result)765 assert result766 # 服务质量开关767 confma.click_switch(0)768 result = re.search(r'aria-checked="true"', confma.get_source)769 log.info(result)770 assert result771 confma.click_switch(0)772 result = re.search(r'aria-checked="false"', confma.get_source)773 log.info(result)774 assert result775 # 服务质量操作保留值776 confma.click_list(0)777 confma.input_retain('-1')778 confma.click_Tick()779 result = re.search(r'值不能小于0', confma.get_source)780 log.info(result)781 assert result782 confma.input_retain('0.1')783 confma.click_Tick()784 result = re.search(r'只能输入整数', confma.get_source)785 log.info(result)786 assert result787 confma.input_retain('101')788 confma.click_Tick()789 result = re.search(r'值不能大于100', confma.get_source)790 log.info(result)791 assert result792 confma.input_retain('22')793 confma.click_Tick()794 result = re.search(r'<span>22</span>', confma.get_source)795 log.info(result)796 assert result797 # 服务质量操作保留值798 confma.click_list(0)799 confma.input_upper('-1')800 confma.click_Tick()801 result = re.search(r'值不能小于0', confma.get_source)802 log.info(result)803 assert result804 confma.input_upper('0.1')805 confma.click_Tick()806 result = re.search(r'只能输入整数', confma.get_source)807 log.info(result)808 assert result809 confma.input_upper('101')810 confma.click_Tick()811 result = re.search(r'值不能大于100', confma.get_source)812 log.info(result)813 assert result814 confma.input_upper('23')815 confma.click_Tick()816 result = re.search(r'<span>23</span>', confma.get_source)817 log.info(result)818 assert result819 # 服务质量操作权重820 confma.click_list(0)821 confma.input_weight('-1')822 confma.click_Tick()823 result = re.search(r'值不能小于0', confma.get_source)824 log.info(result)825 assert result826 confma.input_weight('0.1')827 confma.click_Tick()828 result = re.search(r'只能输入整数', confma.get_source)829 log.info(result)830 assert result831 confma.input_weight('101')832 confma.click_Tick()833 result = re.search(r'值不能大于100', confma.get_source)834 log.info(result)835 assert result836 confma.input_weight('24')837 confma.click_Tick()838 result = re.search(r'<span>24</span>', confma.get_source)839 log.info(result)840 assert result841 # 服务质量一起操作842 confma.click_list(0)843 confma.input_retain('')844 confma.input_upper('')845 confma.input_weight('')846 confma.click_Tick()847 result = re.search(r'操作成功', confma.get_source)848 log.info(result)849 assert result850 confma.click_list(0)851 confma.input_retain('66')852 confma.input_upper('77')853 confma.input_weight('88')854 confma.click_fork()855 confma.click_ButtoNo(0)856 sleep()857 confma.click_fork()858 sleep()859 confma.click_ButtonYes(0)860 result = re.search(r'<span>66</span>', confma.get_source)861 log.info(result)862 assert not result863 confma.click_list(0)864 confma.input_retain('66')865 confma.input_upper('77')866 confma.input_weight('88')867 confma.click_Tick()868 result = re.search(r'<span>66</span>', confma.get_source)869 log.info(result)870 assert result871 @allure.story("服务降级")872 def test_006(self, drivers):873 """服务质量测试"""874 confma = ConfigManage(drivers)875 confma.click_Menu('服务降级')876 result = re.search(r'服务降级默认阈值', confma.get_source)877 log.info(result)878 assert result879 # 服务质量开关880 confma.click_switch(0)881 result = re.search(r'aria-checked="true"', confma.get_source)882 log.info(result)883 assert result884 confma.click_switch(0)885 result = re.search(r'aria-checked="false"', confma.get_source)886 log.info(result)887 assert result888 # 服务降级默认阈值889 confma.click_DefaultEdit()890 confma.input_box('0')891 confma.click_Tick()892 result = re.search(r'值不能小于1', confma.get_source)893 log.info(result)894 assert result895 confma.input_box('101')896 confma.click_Tick()897 result = re.search(r'值不能大于100', confma.get_source)898 log.info(result)899 assert result900 confma.input_box('6')901 confma.click_fork()902 confma.click_DefaultEdit()903 confma.input_box('26')904 confma.click_Tick()905 result = re.search(r'操作成功', confma.get_source)906 log.info(result)907 assert result908 # 服务降级阈值909 confma.click_list(0)910 confma.input_box('0')911 confma.click_Tick()912 result = re.search(r'值不能小于1', confma.get_source)913 log.info(result)914 assert result915 confma.input_box('0.1')916 confma.click_Tick()917 result = re.search(r'只能输入整数', confma.get_source)918 log.info(result)919 assert result920 confma.input_box('101')921 confma.click_Tick()922 result = re.search(r'值不能大于100', confma.get_source)923 log.info(result)924 assert result925 confma.input_box('25')926 confma.click_fork()927 result = re.search(r'<span>25</span>', confma.get_source)928 log.info(result)929 assert not result930 confma.click_list(0)931 confma.input_box('26')932 confma.click_Tick()933 result = re.search(r'<span>26</span>', confma.get_source)934 log.info(result)935 assert result936 # 降级服务937 confma.click_DegradServList(0)938 result = re.search(r'ant-select ant-select-focused ant-select-single ant-select-show-arrow ant-select-open', confma.get_source)939 log.info(result)940 assert result941 confma.click_DegradServ(0)942 result = re.search(r'操作成功', confma.get_source) # 如果之前就选中了第一个元素,这里不会出现操作成功按钮,会报错943 log.info(result)944 assert result945 # 最后选中空白元素,将环境还原946 confma.click_DegradServList(0)947 confma.click_DegradServEnd()948 result = re.search(r'操作成功', confma.get_source)949 log.info(result)950 assert result951@allure.feature("黑白名单")952class TestBlacklist:953 @pytest.fixture(scope='session', autouse=auto)954 def open_devops(self, drivers):955 """打开courier"""956 login = LoginPage(drivers)957 login.get_url(ini.url)958 login.input_username_login('admin')959 login.input_password_login('password')960 login.click_login()961 login.click_Menu("服务网关")962 login.click_Menu("黑白名单")963 @allure.story("点击黑白名单")964 def test_001(self, drivers):965 """点击黑白名单"""966 blackli = Blacklist(drivers)967 blackli.click_Menu('黑白名单')968 blackli.waite_element('白名单管理')969 result = re.search(r'IP地址', blackli.get_source)970 log.info(result)971 assert result972 @allure.story("白名单添加")973 def test_002(self, drivers):974 """白名单添加测试"""975 blackli = Blacklist(drivers)976 blackli.click_Menu('白名单管理')977 blackli.click_add(0)978 result = re.search(r'添加白名单', blackli.get_source)979 log.info(result)980 assert result981 blackli.click_Define()982 result = re.search(r'请输入正确的IP地址', blackli.get_source)983 log.info(result)984 assert result985 blackli.input_ip('1234')986 blackli.click_Define()987 result = re.search(r'请输入正确的IP地址', blackli.get_source)988 log.info(result)989 assert result990 blackli.input_ip('10.0.2.3')991 blackli.click_Canle()992 blackli.click_add(0)993 blackli.input_ip('10.0.2.3')994 blackli.click_close()995 blackli.click_add(0)996 blackli.input_ip('10.0.2.4')997 blackli.click_Define()998 result = re.search(r'10.0.2.4', blackli.get_source)999 log.info(result)1000 assert result1001 @allure.story("白名单刷新")1002 def test_003(self, drivers):1003 """白名单刷新测试"""1004 blackli = Blacklist(drivers)1005 blackli.click_refresh()1006 result = re.search(r'anticon anticon-reload ant-tooltip-open', blackli.get_source)1007 log.info(result)1008 assert result1009 @allure.story("白名单编辑")1010 def test_004(self, drivers):1011 """白名单编辑测试"""1012 blackli = Blacklist(drivers)1013 blackli.click_edit(0)1014 blackli.input_ip('')1015 blackli.click_Define()1016 blackli.input_ip('4.3.2.1')1017 blackli.click_Define()1018 result = re.search(r'4.3.2.1', blackli.get_source)1019 log.info(result)1020 assert result1021 @allure.story("白名单删除")1022 def test_005(self, drivers):1023 """白名单删除测试"""1024 blackli = Blacklist(drivers)1025 # blackli.click_gatedel(0)1026 # blackli.click_ButtoNo(0)1027 blackli.click_gatedel(0)1028 blackli.click_ButtonYes(0)1029 result = re.search(r'删除成功', blackli.get_source)1030 log.info(result)1031 assert result1032 @allure.story("黑名单添加")1033 def test_006(self, drivers):1034 """黑名单添加测试"""1035 blackli = Blacklist(drivers)1036 blackli.click_Menu('黑名单管理')1037 blackli.click_add(1)1038 result = re.search(r'添加黑名单', blackli.get_source)1039 log.info(result)1040 assert result1041 blackli.click_Define()1042 result = re.search(r'请输入正确的IP地址', blackli.get_source)1043 log.info(result)1044 assert result1045 blackli.input_ip('1234')1046 blackli.click_Define()1047 result = re.search(r'请输入正确的IP地址', blackli.get_source)1048 log.info(result)1049 assert result1050 blackli.input_ip('10.0.2.4')1051 blackli.click_Canle()1052 blackli.click_add(1)1053 blackli.input_ip('10.0.2.4')1054 blackli.click_close()1055 blackli.click_add(1)1056 blackli.input_ip('10.0.2.5')1057 blackli.click_Define()1058 result = re.search(r'10.0.2.5', blackli.get_source)1059 log.info(result)1060 assert result1061 @allure.story("黑名单编辑")1062 def test_007(self, drivers):1063 """黑名单编辑测试"""1064 blackli = Blacklist(drivers)1065 blackli.click_edit(0)1066 blackli.input_ip('')1067 blackli.click_Define()1068 blackli.input_ip('4.3.2.1')1069 blackli.click_Define()1070 result = re.search(r'4.3.2.1', blackli.get_source)1071 log.info(result)1072 assert result1073 @allure.story("黑名单删除")1074 def test_008(self, drivers):1075 """黑名单删除测试"""1076 blackli = Blacklist(drivers)1077 # blackli.click_gatedel(0)1078 # blackli.click_ButtoNo(0)1079 blackli.click_gatedel(0)1080 blackli.click_ButtonYes(0)1081 result = re.search(r'删除成功', blackli.get_source)1082 log.info(result)1083 assert result1084@allure.feature("地理位置")1085class TestLocation:1086 @pytest.fixture(scope='session', autouse=auto)1087 def open_devops(self, drivers):1088 """打开courier"""1089 login = LoginPage(drivers)1090 login.get_url(ini.url)1091 login.input_username_login('admin')1092 login.input_password_login('password')1093 login.click_login()1094 login.click_Menu("服务网关")1095 login.click_Menu("地理位置")1096 @allure.story("点击地理位置")1097 def test_001(self, drivers):1098 """点击地理位置"""1099 local = Location(drivers)1100 local.click_Menu('地理位置')1101 local.waite_element('开关按钮')1102 result = re.search(r'区域经纬度', local.get_source)1103 log.info(result)1104 assert result1105 @allure.story("地理位置启用开关")1106 def test_002(self, drivers):1107 """地理位置启用开关测试"""1108 local = Location(drivers)1109 local.click_switch(0)1110 sleep()1111 result = re.search(r'aria-checked="true"', local.get_source)1112 log.info(result)1113 assert result1114 local.click_switch(0)1115 result = re.search(r'aria-checked="false"', local.get_source)1116 log.info(result)1117 assert result1118 @allure.story("地理位置添加")1119 def test_003(self, drivers):1120 """地理位置添加测试"""1121 local = Location(drivers)1122 local.click_add(0)1123 result = re.search(r'添加地理位置', local.get_source)1124 log.info(result)1125 assert result1126 local.click_Define()1127 result = re.search(r'请输入区域半径', local.get_source)1128 log.info(result)1129 assert result1130 # 新增框取消与关闭1131 local.input_locationame("区域1")1132 local.input_longtitude("12.3")1133 local.input_latitude('31.5')1134 local.input_radius('13.6')1135 local.click_Canle()1136 result = re.search(r'<span>[12.3, 31.5]', local.get_source)1137 log.info(result)1138 assert not result1139 local.click_add(0)1140 local.input_locationame("区域1")1141 local.input_longtitude("12.3")1142 local.input_latitude('31.6')1143 local.input_radius('13.6')1144 local.click_close()1145 result = re.search(r'<span>[12.3, 31.6]', local.get_source)1146 log.info(result)1147 assert not result1148 local.click_add(0)1149 local.input_locationame("区域1")1150 local.input_longtitude("22.3")1151 local.input_latitude('33.5')1152 local.input_radius('15')1153 local.click_Define()1154 result = re.search(r'<span>[22.3, 33.5]', local.get_source)1155 log.info(result)1156 assert not result1157 @allure.story("地理位置刷新")1158 def test_004(self, drivers):1159 """地理位置刷新测试"""1160 local = Location(drivers)1161 local.click_refresh()1162 result = re.search(r'anticon anticon-reload ant-tooltip-open', local.get_source)1163 log.info(result)1164 assert result1165 @allure.story("地理位置展示数量下拉框")1166 def test_005(self, drivers):1167 """地理位置展示数量下拉框测试"""1168 local = Location(drivers)1169 local.click_Menu('下拉展示条')1170 local.click_Menu('10条')1171 result = re.search(r'<span.*?10 条/页', local.get_source)1172 log.info(result)1173 assert result1174 local.click_Menu('下拉展示条')1175 local.click_Menu('20条')1176 result = re.search(r'<span.*?20 条/页', local.get_source)1177 log.info(result)1178 assert result1179 local.click_Menu('下拉展示条')1180 local.click_Menu('50条')1181 result = re.search(r'<span.*?50 条/页', local.get_source)1182 log.info(result)1183 assert result1184 local.click_Menu('下拉展示条')1185 local.click_Menu('100条')1186 result = re.search(r'<span.*?100 条/页', local.get_source)1187 log.info(result)1188 assert result1189 @allure.story("地理位置开启强制刷新")1190 def test_006(self, drivers):1191 """地理位置刷新测试"""1192 local = Location(drivers)1193 local.click_switch(1)1194 result = re.search(r'更改成功', local.get_source)1195 log.info(result)1196 assert result1197 local.click_switch(1)1198 result = re.search(r'更改成功', local.get_source)1199 log.info(result)1200 assert result1201 @allure.story("地理位置编辑")1202 def test_007(self, drivers):1203 """地理位置编辑测试"""1204 local = Location(drivers)1205 local.click_edit(0)1206 result = re.search(r'编辑地理位置', local.get_source)1207 log.info(result)1208 assert result1209 try:1210 local.input_locationame("区域2")1211 except Exception as e:1212 log.info(f"报错:{e}, \n编辑时,区域名无法点击")1213 local.input_longtitude("3")1214 local.input_latitude('4')1215 local.input_radius('5')1216 local.click_Define()1217 result = re.search(r'编辑成功', local.get_source)1218 log.info(result)1219 assert result1220 @allure.story("地理位置删除")1221 def test_008(self, drivers):1222 """地理位置删除测试"""1223 local = Location(drivers)1224 local.click_gatedel(0)1225 # sleep()1226 # local.click_ButtoNo(0)1227 # local.click_gatedel(0)1228 # sleep(2)1229 local.click_ButtonYes(0)1230 result = re.search(r'删除成功', local.get_source)1231 log.info(result)1232 assert result1233@allure.feature("条件表达式")1234class TestConditional:1235 @pytest.fixture(scope='session', autouse=auto)1236 def open_devops(self, drivers):1237 """打开courier"""1238 login = LoginPage(drivers)1239 login.get_url(ini.url)1240 login.input_username_login('admin')1241 login.input_password_login('password')1242 login.click_login()1243 login.click_Menu("服务网关")1244 login.click_Menu("条件表达式")1245 @allure.story("点击条件表达式")1246 def test_001(self, drivers):1247 """点击地理位置"""1248 condit = Location(drivers)1249 condit.click_Menu('条件表达式')1250 condit.waite_element('服务名输入')1251 result = re.search(r'开启', condit.get_source)1252 log.info(result)1253 assert result1254 @allure.story("添加条件表达式取消退出")1255 def test_002(self, drivers):1256 """添加条件表达式测试"""1257 # 添加框取消退出1258 condit = Conditional(drivers)1259 condit.click_add(0)1260 condit.click_Define()1261 result = re.search(r'请输入服务名', condit.get_source)1262 log.info(result)1263 assert result1264 condit.input_servicename(num=1, content='服务名1')1265 condit.click_Menu('force')1266 result = re.search(r'<button id="force.*?aria-checked="true"', condit.get_source)1267 log.info(result)1268 assert result1269 condit.click_Menu('force')1270 condit.click_Menu('enabled')1271 result = re.search(r'<button id="enabled.*?aria-checked="true"', condit.get_source)1272 log.info(result)1273 assert result1274 condit.click_Menu('enabled')1275 condit.click_Canle()1276 condit.click_add(0)1277 condit.click_close()1278 @allure.story("添加条件表达式")1279 def test_003(self, drivers):1280 """添加条件表达式测试"""1281 # 添加框输入1282 condit = Conditional(drivers)1283 condit.click_add(0)1284 condit.input_servicename(num=1, content='服务名1')1285 condit.click_Menu('force')1286 condit.click_Menu('enabled')1287 # tag11288 condit.input_tagname1('标签名称1')1289 condit.input_address1("10.0.1.1")1290 condit.click_address(0)1291 result = re.search(r'tags_0_address_1', condit.get_source)1292 log.info(result)1293 assert result1294 condit.input_address2("10.0.1.2")1295 result = re.search(r'10.0.1.2', condit.get_source)1296 log.info(result)1297 assert result1298 # tag21299 condit.click_Menu('添加tag')1300 condit.input_tagname2('标签名称2')1301 condit.input_2address1("10.0.2.1")1302 condit.click_address(1)1303 result = re.search(r'tags_1_address_1', condit.get_source)1304 log.info(result)1305 assert result1306 condit.input_2address2("10.0.2.2")1307 result = re.search(r'10.0.2.2', condit.get_source)1308 log.info(result)1309 assert result1310 condit.click_Define()1311 result = re.search(r'服务名1', condit.get_source)1312 log.info(result)1313 assert result1314 @allure.story("条件表达式搜索")1315 def test_004(self, drivers):1316 """条件表达式搜索测试"""1317 # 新建两个服务1318 condit = Conditional(drivers)1319 condit.click_add(0)1320 condit.input_servicename(num=1, content='服务名2')1321 condit.input_tagname1('标签名称2')1322 condit.input_address1("10.0.1.2")1323 condit.click_Define()1324 result = re.search(r'服务名2', condit.get_source)1325 log.info(result)1326 assert result1327 condit.click_add(0)1328 condit.input_servicename(num=1, content='服务名3')1329 condit.input_tagname1('标签名称3')1330 condit.input_address1("10.0.1.3")1331 condit.click_Define()1332 result = re.search(r'服务名3', condit.get_source)1333 log.info(result)1334 assert result1335 # 搜索服务名21336 condit.input_servicename(num=0, content='服务名2')1337 condit.click_search()1338 result = re.search(r'服务名3', condit.get_source)1339 log.info(result)1340 assert not result1341 condit.click_gatedel(0)1342 condit.click_ButtonYes(0)1343 condit.click_reset()1344 result = re.search(r'服务名2', condit.get_source)1345 log.info(result)1346 assert not result1347 # 搜索服务名31348 condit.input_servicename(num=0, content='服务名3')1349 condit.click_search()1350 result = re.search(r'服务名3', condit.get_source)1351 log.info(result)1352 assert result1353 condit.click_gatedel(0)1354 condit.click_ButtonYes(0)1355 condit.click_reset()1356 result = re.search(r'服务名3', condit.get_source)1357 log.info(result)1358 assert not result1359 @allure.story("条件表达式刷新")1360 def test_005(self, drivers):1361 """条件表达式刷新测试"""1362 condit = Conditional(drivers)1363 condit.click_refresh()1364 result = re.search(r'anticon anticon-reload ant-tooltip-open', condit.get_source)1365 log.info(result)1366 assert result1367 @allure.story("条件表达式展示数量下拉框")1368 def test_006(self, drivers):1369 """条件表达式刷新测试"""1370 condit = Conditional(drivers)1371 condit.click_Menu('下拉展示条')1372 condit.click_Menu('10条')1373 result = re.search(r'<span.*?10 条/页', condit.get_source)1374 log.info(result)1375 assert result1376 condit.click_Menu('下拉展示条')1377 condit.click_Menu('20条')1378 result = re.search(r'<span.*?20 条/页', condit.get_source)1379 log.info(result)1380 assert result1381 condit.click_Menu('下拉展示条')1382 condit.click_Menu('50条')1383 result = re.search(r'<span.*?50 条/页', condit.get_source)1384 log.info(result)1385 assert result1386 condit.click_Menu('下拉展示条')1387 condit.click_Menu('100条')1388 result = re.search(r'<span.*?100 条/页', condit.get_source)1389 log.info(result)1390 assert result1391 @allure.story("条件表达式详情")1392 def test_007(self, drivers):1393 """条件表达式刷新测试"""1394 condit = Conditional(drivers)1395 condit.click_details(0)1396 result = re.search(r'条件表达式详情', condit.get_source)1397 log.info(result)1398 assert result1399 condit.click_close()1400 condit.click_details(0)1401 condit.click_Canle()1402 result = re.search(r'条件表达式详情', condit.get_source)1403 log.info(result)1404 assert not result1405 @allure.story("条件表达式编辑")1406 def test_008(self, drivers):1407 """条件表达式编辑测试"""1408 condit = Conditional(drivers)1409 condit.click_edit(0)1410 result = re.search(r'编辑条件表达式', condit.get_source)1411 log.info(result)1412 assert result1413 condit.input_tagname1("new标签")1414 condit.input_address1("10.0.1.5")1415 condit.click_Define()1416 result = re.search(r'编辑成功', condit.get_source)1417 log.info(result)1418 assert result1419 @allure.story("条件表达式开启关闭")1420 def test_009(self, drivers):1421 """条件表达式开启关闭测试"""1422 condit = Conditional(drivers)1423 # 关闭1424 condit.click_shut(0)1425 # sleep()1426 # condit.click_ButtoNo(0)1427 # condit.click_shut(0)1428 # sleep(2)1429 sleep()1430 condit.click_ButtonYes(0)1431 result = re.search(r'更改成功', condit.get_source)1432 log.info(result)1433 assert result1434 #开启1435 condit.click_opens(0)1436 # sleep()1437 # condit.click_ButtoNo(0)1438 # condit.click_opens(0)1439 # sleep(2)1440 sleep()1441 condit.click_ButtonYes(0)1442 result = re.search(r'更改成功', condit.get_source)1443 log.info(result)1444 assert result1445 @allure.story("条件表达式删除")1446 def test_010(self, drivers):1447 """条件表达式删除测试"""1448 condit = Conditional(drivers)1449 condit.click_gatedel(0)1450 # 当全部执行时,上个用例操作后,页面元素中会多一个重复元素,这时改为11451 # condit.click_ButtoNo(1)1452 # condit.click_gatedel(0)1453 # 单独执行该用例时,参数为 01454 # condit.click_ButtoNo(0)1455 # condit.click_gatedel(0)1456 # condit.click_ButtonYes(0)1457 condit.click_ButtonYes(1)1458 result = re.search(r'删除成功', condit.get_source)1459 log.info(result)1460 assert result1461@allure.feature("指标统计")1462class TestStatistics:1463 @pytest.fixture(scope='session', autouse=auto)1464 def open_devops(self, drivers):1465 """打开courier"""1466 login = LoginPage(drivers)1467 login.get_url(ini.url)1468 login.input_username_login('admin')1469 login.input_password_login('password')1470 login.click_login()1471 login.click_Menu("指标统计")1472 @allure.story("点击指标统计")1473 def test_001(self, drivers):1474 """点击指标统计"""1475 stati = Statistics(drivers)1476 stati.click_Menu('指标统计')1477 stati.waite_element('端口')1478 result = re.search(r'成功次数', stati.get_source)1479 log.info(result)1480 assert result1481 @allure.story("指标统计搜索")1482 def test_002(self, drivers):1483 """点击指标统计"""1484 stati = Statistics(drivers)1485 stati.click_search()1486 result = re.search(r'请输入IP', stati.get_source)1487 log.info(result)1488 assert result1489 # 搜索1490 stati.input_ip('192.168.31.10')1491 stati.click_search()1492 result = re.search(r'请输入端口号', stati.get_source)1493 log.info(result)1494 assert result1495 stati.input_port('1523')1496 stati.click_search()1497 result = re.search(r'请输入服务名', stati.get_source)1498 log.info(result)1499 assert result1500 stati.input_serviceName('conditionservice')1501 stati.click_search()1502 result = re.search(r'请输入服务名', stati.get_source)1503 log.info(result)1504 assert not result1505 #重置1506 stati.click_reset()1507 result = re.search(r'192.168.31.10', stati.get_source)1508 log.info(result)1509 assert not result1510 @allure.story("指标统计刷新")1511 def test_003(self, drivers):1512 """指标统计刷新测试"""1513 stati = Statistics(drivers)1514 stati.click_refresh()1515 result = re.search(r'anticon anticon-reload ant-tooltip-open', stati.get_source)1516 log.info(result)1517 assert result1518if __name__ == '__main__':1519 pytest.main(['TestCase/test_courier_login.py', '-sv'])1520# if __name__ == '__main__':1521# 下面的代码使用pycharm运行可能会没有生成报告,建议使用vscode执行1522# import os1523# pytest.main(['TestCase/test_search.py', '--alluredir', './allure'])...

Full Screen

Full Screen

py2php.py

Source:py2php.py Github

copy

Full Screen

...37 # node body of the module, a <tt class="class">Stmt</tt>38 self.src += '<?php\n' 39 if t.doc:40 self.src += self.comment_start + t.doc + self.comment_end41 self.src += get_source(t.getChildNodes()[0])42 self.src += '?>'43 44 def visitStmt(self,node):45 #print '***stmt nodes****',len(node.nodes), node.nodes46 self.src += '\n'.join( [ get_source(n) for n in node.nodes ]) + '\n'47 def visitClass(self, node):48 # Class attributes49 # name the name of the class, a string50 # bases a list of base classes51 # doc doc string, a string or <code>None</code>52 # code the body of the class statement53 global current_class_name, is_parsing_class54 is_parsing_class = True # important, must be in the beginning !55 current_class_name = node.name56 if node.doc != None:57 self.src += self.comment_start + node.doc + self.comment_end58 self.src += 'class %s ' % node.name59 if len(node.bases) > 0:60 self.src += 'extends %s' % get_source( node.bases[0] )[1:] # php has no multiple inheritance61 self.src += ' {\n'62 self.src += get_source( node.code )63 self.src += '}\n'64 is_parsing_class = False # important, must be at the end!65 def visitFunction(self, node):66 # Function attributes67 # name name used in def, a string68 # argnames list of argument names, as strings69 # defaults list of default values70 # flags xxx71 # doc doc string, a string or <code>None</code>72 # code the body of the function73 global current_class_name, is_parsing_class74 if is_parsing_class: # if class method, delete the Python's self argument75 node.argnames = node.argnames[1:]76 if node.doc != None:77 self.src += self.comment_start + node.doc + self.comment_end78 if (PHPVERSION == 5 and 79 node.name == '__init__' and 80 is_parsing_class):81 node.name = '__construct'82 elif (PHPVERSION == 4 and83 node.name == '__init__' and84 is_parsing_class and85 current_class_name != ''):86 node.name = current_class_name87 self.src += 'function %s (' % node.name88 nb_defaults = len(node.defaults)89 if nb_defaults > 0 : # there are some default args90 simple_args = node.argnames[:len(node.argnames)-nb_defaults]91 assigned_args = node.argnames[len(node.argnames)-nb_defaults:]92 assg_args_w_vals = []93 j = 094 for assign in assigned_args:95 valu = get_source( node.defaults[j] )96 assg_args_w_vals.append( '%s = %s' % (assign,valu) )97 j+=198 self.src += ', '.join( ['$%s'%n for n in99 simple_args+assg_args_w_vals ])100 else: 101 self.src += ', '.join( '$%s'%n for n in node.argnames)102 self.src += ') {\n'103 self.src += get_source( node.code )104 self.src += '}\n'105 def visitGetattr(self, node):106 # Getattr attributes107 # expr 108 # attrname 109 self.src += get_source( node.expr ) + '->' + node.attrname110 111 def visitAssAttr(self, node):112 # AssAttr attributes113 # expr expression on the left-hand side of the dot114 # attrname the attribute name, a string115 # flags XXX116 self.src += get_source( node.expr ) + '->'117 self.src += node.attrname118 def visitDiscard(self, node):119 # Discard attributes120 # expr 121 if node.expr.__class__ is compiler.ast.Const :122 self.src += '/* ' + get_source( node.expr )[1:-1] + ' */'123 else:124 self.src += get_source( node.expr )125 def visitReturn(self, node):126 self.src += 'return '+get_source(node.value)127 def visitContinue(self, node):128 # Continue attributes129 self.src += 'continue'130 def visitBreak(self, node):131 # Break attributes132 self.src += 'break'133 def visitPrintnl(self, node):134 # Printnl attributes135 # nodes 136 # dest 137 # PHP print statement takes only one parameter so we take the first one :138 self.src += 'print '+ get_source( node.nodes[0] ) 139 def visitName(self, node):140 if node.name == 'self':141 self.src += '$this'142 elif node.name == 'False':143 self.src += 'false'144 elif node.name == 'True':145 self.src += 'true'146 elif node.name == 'None':147 self.src += 'null'148 elif re.match( '^[A-Z][_A-Z]*$', node.name ): # it's a constant if ALL CAPS149 self.src += node.name150 elif (node.name in self.magic_constants):151 self.src += node.name152 else:153 self.src += '$%s'%node.name154 def visitConst(self, node):155 # Const attributes156 # value 157 if type(node.value) is str:158 self.src += '"%s"' % node.value159 else:160 self.src += str(node.value)161 def visitMod(self, node):162 # Mod attributes163 # left 164 # right 165 left = get_source( node.left )166 if '%' in left and type(left) is str and left.startswith('"'):167 # sprintf168 self.src += 'sprintf(' + left + ', '169 if node.right.__class__ is compiler.ast.Tuple:170 self.src += ', '.join( [ get_source(n) for n in node.right ] )171 else:172 self.src += get_source(node.right)173 self.src += ')'174 else:175 # modulo normal176 self.src += '('+get_source( node.left ) + ' % ' + get_source(177 node.right )+')'178 pass179 def visitMul(self, node):180 # Mul attributes181 # left 182 # right 183 self.src += '('+get_source( node.left ) + ' * ' + get_source(184 node.right )+')'185 def visitDiv(self, node):186 # Div attributes187 # left 188 # right 189 self.src += '('+get_source( node.left ) + ' / ' + get_source(190 node.right )+')'191 def visitAdd(self, node):192 # Add attributes193 # left left operand194 # right right operand195 if ((node.left.__class__ is compiler.ast.Const and 196 type(node.left.getChildren()[0]) is str) or197 (node.right.__class__ is compiler.ast.Const and198 type(node.right.getChildren()[0]) is str)):199 self.src += get_source(node.left) + ' . ' + get_source(node.right)200 else: 201 self.src += '('+get_source( node.left ) + ' + ' + get_source(202 node.right )+')'203 def visitSub(self, node):204 # Sub attributes205 # left 206 # right 207 self.src += '('+get_source( node.left ) + ' - ' + get_source(208 node.right )+')'209 def visitUnaryAdd(self, node):210 # UnaryAdd attributes211 # expr 212 self.src += '+'+get_source( node.expr )213 def visitUnarySub(self, node):214 # UnarySub attributes215 # expr 216 self.src += '-'+get_source( node.expr )217 def visitAssign(self, node):218 # Assign attributes219 # nodes a list of assignment targets, one per equal sign220 # expr the value being assigned221 parsed_expr = get_source( node.expr )222 if ( len(node.nodes)==1 and 223 type(node.nodes[0].getChildren()[0]) is StringType and 224 re.match('^[A-Z][_A-Z]*$', node.nodes[0].getChildren()[0]) ):225 self.src += 'define("'+node.nodes[0].getChildren()[0]+'", '+parsed_expr+')' 226 else:227 self.src += ', '.join( [get_source( n ) for n in node.nodes ] ) + ' = ' 228 self.src += parsed_expr229 def visitAugAssign(self, node):230 # AugAssign attributes231 # node 232 # op 233 # expr 234 def nodeLoop(node):235 try:236 if node.getChildren()[0].__class__ is compiler.ast.Add:237 return nodeLoop(node.getChildren()[0])238 elif node.getChildren()[0].__class__ is compiler.ast.Const:239 return node.getChildren()[0]240 else:241 return node242 except Exception, e:243 return node244 245 if (node.op == '+=' and246 node.expr.__class__ is compiler.ast.Const and247 type(node.expr.getChildren()[0]) is str):248 self.src += get_source( node.node )249 self.src += ' .= '250 self.src += get_source( node.expr )251 else:252 try:253 if (nodeLoop(node.expr).__class__ is compiler.ast.Const and254 type(nodeLoop(node.expr).getChildren()[0]) is str):255 node.op = '.='256 except Exception, e:257 pass258 self.src += get_source( node.node )259 self.src += ' '+node.op+' '260 self.src += get_source( node.expr )261 def visitOr(self, node):262 # Or attributes263 # nodes 264 self.src += ' || '.join( [ get_source( n ) for n in node.nodes ] )265 266 def visitAnd(self, node):267 # And attributes268 # nodes list of operands269 self.src += ' && '.join( [ get_source( n ) for n in node.nodes ] )270 def visitNot(self, node):271 # Not attributes272 # expr 273 self.src += '!%s' % get_source(node.expr)274 def visitGlobal(self, node):275 # Global attributes276 # names 277 self.src += 'global '+ ( ', '.join( ['$%s' % name for name in node.names ] ) )278 def visitCompare(self, node):279 # Compare attributes280 # expr 281 # ops 282 self.src += get_source( node.expr )283 for comp in node.ops:284 if comp[0] == '!=':285 operator = '!=='286 elif comp[0] == '==':287 operator = '==='288 elif comp[0] == 'is':289 raise visitor_base.NotImplementedException('IS keyword')290 else:291 operator = comp[0]292 self.src += ' '+operator+' ' + get_source( comp[1] )293 def visitIf(self, node):294 # if attributes295 # tests 296 # else_ 297 i = 0298 for test in node.tests:299 if i==0:300 self.src += 'if ('301 else:302 self.src += 'elseif ('303 # for compare in test:304 self.src += get_source( test[0] )305 self.src += ') {\n'306 self.src += ''.join( [ get_source(n) for n in test[1:] ] )307 self.src += '}\n'308 i+= 1309 if node.else_:310 self.src += 'else {\n'311 self.src += get_source( node.else_ )312 self.src += '}\n'313 def visitTryExcept(self, node):314 # TryExcept attributes315 # body 316 # handlers 317 # else_ 318 self.src += 'try {\n'319 self.src += get_source( node.body )320 self.src += '}\n' 321 for handler in node.handlers:322 self.src += 'catch ('323 if handler[1] == None:324 self.src += 'Exception '+get_source(handler[0])325 else:326 self.src += handler[0].getChildren()[0] + ' '327 self.src += get_source( handler[1] )328 self.src += ') {\n'329 self.src += get_source( handler[2] )330 self.src += '}\n'331 def visitFor(self, node):332 # For attributes333 # assign 334 # list 335 # body 336 # else_ 337 self.src += 'foreach ('+get_source(node.list)+' as '338 self.src += get_source( node.assign ) + ') {\n'339 self.src += get_source( node.body )340 self.src += '}\n'341 def visitWhile(self, node):342 # While attributes343 # test 344 # body 345 # else_ 346 self.src += 'while ('347 self.src += get_source( node.test )348 self.src += ') {\n'349 self.src += get_source( node.body )350 self.src += '}\n'351 def visitCallFunc(self, node):352 # CallFunc attributes353 # node expression for the callee354 # args a list of arguments355 # star_args the extended *-arg value356 # dstar_args the extended **-arg value357 # call a function :358 if type(node.node.getChildren()[0]) is str:359 # if it's an instanciation:360 if re.match('^[A-Z]', node.node.getChildren()[0] ):361 self.src += 'new ' + node.node.getChildren()[0] + '('362 else: # we have a function:363 funcname = node.node.getChildren()[0]364 if self.funcs_to_replace.has_key(funcname):365 funcname = self.funcs_to_replace[funcname]366 self.src += funcname + '('367 else: # call a method :368 if len( node.node.getChildren() ) == 2 :369 self.src += get_source( node.node.getChildren()[0] )370 self.src += '->' + node.node.getChildren()[1] + '('371 self.src += ', '.join( [get_source(n) for n in node.args ] )372 self.src += ')'373 def visitAssName(self, node):374 # AssName attributes375 # name name being assigned to376 # flags XXX377 if re.match( '^[A-Z][_A-Z]*$', node.name ): # it's a constant if ALL CAPS378 self.src += node.name379 elif (node.name in self.magic_constants):380 self.src += node.name381 else:382 self.src += '$%s' % node.name383 def visitAssTuple(self, node):384 # AssTuple attributes385 # nodes list of tuple elements being assigned to386 # ** Tuple assignment does not exist in PHP so i'm gonna use it for the387 # foreach key => value pair, or value only if there is only one element388 if len(node.nodes) == 2:389 self.src += get_source(node.nodes[0]) + ' => ' 390 self.src += get_source(node.nodes[1])391 elif len(node.nodes) == 1:392 self.src += get_source(node.nodes[0])393 else:394 raise visitor_base.NotImplementedException('Tuple assignment does not exist in PHP')395 def visitList(self,t):396 self.src += 'array('397 self.src += ', '.join ( [ get_source(n) for n in t.nodes ])398 self.src += ')'399 def visitDict(self, node):400 # Dict attributes401 # items 402 self.src += 'array('403 self.src += ', '.join( [get_source(k)+'=>'+get_source(v) for k,v in404 node.items] )405 self.src += ')'406 def visitSubscript(self, node):407 # Subscript attributes408 # expr 409 # flags 410 # subs 411 if node.flags == 'OP_ASSIGN' or node.flags == 'OP_APPLY':412 self.src += get_source(node.expr) +'['413 self.src += get_source(node.subs[0]) # [0] parce qu'on ne peut faire de [0:2] en PHP414 self.src += ']'415 def visitPass(self, node):416 pass417 418def get_source(node):419 """Return the source code of the node, built by an instance of420 ge_visitor"""421 return compiler.walk(node,visitor()).src422def add_semicolons(code):423 global LINEEND424 lines_list = code.split('\n')425 in_comment = False426 new_lines = []427 for line in lines_list:428 if line.startswith('/*') and not line.endswith('*/'):429 in_comment = True430 elif line.endswith('*/'):431 in_comment = False432 if (line.strip() != '<?php' and433 line.strip() != '?>' and434 line.strip() != '' and 435 not in_comment and 436 not (437 line.endswith('}') or438 line.endswith('{') or 439 line.endswith('*/')440 )441 ):442 new_lines.append( line + LINEEND )443 else:444 new_lines.append( line )445 return '\n'.join(new_lines)446def indent_source(code):447 global INDENT448 lines_list = code.split('\n')449 tab_count = 0450 new_lines = []451 for line in lines_list:452 if line == '}':453 tab_count -= 1454 val = (INDENT*tab_count) + line455 indentation = INDENT*tab_count456 if not (line.strip() == '' and tab_count != 0):457 new_lines.append( val )458 if line.endswith('{'):459 tab_count += 1460 return '\n'.join(new_lines)461if __name__ == '__main__':462 unindented_source = get_source(compiler.parseFile('source.py'))...

Full Screen

Full Screen

decompile_lambda_test.py

Source:decompile_lambda_test.py Github

copy

Full Screen

...4from raco.python.exceptions import PythonConvertException5from raco.python.util import decompile6class TestDecompileLambdas(unittest.TestCase):7 def test_simple(self):8 s = decompile.get_source(lambda: 0)9 self.assertEquals(eval(s)(), 0)10 def test_no_space(self):11 s = decompile.get_source(lambda:0)12 self.assertEquals(eval(s)(), 0)13 def test_space_after_colon(self):14 s = decompile.get_source(lambda :0)15 self.assertEquals(eval(s)(), 0)16 def test_variable(self):17 f = lambda: 018 s = decompile.get_source(f)19 self.assertEquals(eval(s)(), f())20 def test_newline(self):21 f = \22 lambda: 023 s = decompile.get_source(f)24 self.assertEquals(eval(s)(), f())25 def test_newline2(self):26 f = lambda: \27 028 s = decompile.get_source(f)29 self.assertEquals(eval(s)(), f())30 def test_tuple(self):31 t = (lambda: 0), 532 s = decompile.get_source(t[0])33 self.assertEquals(eval(s)(), t[0]())34 def test_tuple2(self):35 f = lambda : (0, 5)36 s = decompile.get_source(f)37 self.assertEquals(eval(s)(), f())38 def test_multiple_lambdas(self):39 t = lambda: 1, lambda: 2, lambda: 340 for f in t:41 s = decompile.get_source(f)42 self.assertEquals(eval(s)(), f())43 def test_embedded_lambda_token(self):44 f = lambda: "lambda: 0"45 s = decompile.get_source(f)46 self.assertEquals(eval(s)(), f())47 def test_parameters(self):48 f = lambda x: x49 s = decompile.get_source(f)50 self.assertEquals(eval(s)(5), f(5))51 def test_multiple_parameters(self):52 f = lambda x, y: x + y53 s = decompile.get_source(f)54 self.assertEquals(eval(s)(5, 6), f(5, 6))55 def test_args_kwargs(self):56 f = lambda *args, **kwargs: args[0] + kwargs['foo']57 s = decompile.get_source(f)58 self.assertEqual(eval(s)(5, foo=6), f(5, foo=6))59 def test_unpacking(self):60 """ Unpacking is not currently supported """61 f = lambda (x, y): x + y62 self.assertRaises(PythonConvertException,...

Full Screen

Full Screen

views.py

Source:views.py Github

copy

Full Screen

...7def index():8 '''9 View root page function that returns the index page and its data i.e news source10 '''11 general = get_source('general')12 science = get_source('science')13 business = get_source('business')14 technology = get_source('technology')15 health = get_source('health')16 entertainment = get_source('entertainment')17 sports = get_source('sports')18 return render_template('index.html',general = general, science = science, business = business,technology = technology, health = health, entertainment = entertainment, sports = sports)19@main.route('/sources/<id>')20def articles(id):21 '''22 view articles page23 '''24 articles = get_articles(id)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful