zoukankan      html  css  js  c++  java
  • 当Appium中遇到alert(python篇)

    当Appium中遇到alert,可以使用switch_to_alert(),以下是微信登录切换登录方式的代码示例:

     1 #coding=utf-8
     2 from appium import webdriver
     3 from time import sleep
     4 import unittest
     5 
     6 class WxTestsCase(unittest.TestCase):
     7     def setUp(self):
     8         desired_cups={}
     9         desired_cups['platformName']='Android'
    10         desired_cups['platformVersion']='4.4.2'
    11         desired_cups['deviceName']='DU2SSE15A9032675'
    12         desired_cups['appPackage']='com.tencent.mm'
    13         desired_cups['appActivity']='com.tencent.mm.ui.LauncherUI'
    14         self.dr=webdriver.Remote("http://localhost:4725/wd/hub",desired_cups)
    15         sleep(10)
    16     def login(self):
    17         self.dr.find_element_by_id('com.tencent.mm:id/ba_').click()
    18         self.dr.switch_to_alert() #切换到alert窗口
    19         self.dr.find_element_by_id('com.tencent.mm:id/et').click() #点击弹窗上的切换账号选项
    20 
    21 if __name__ == '__main__':
    22     suite = unittest.TestSuite()
    23     suite.addTest(WxTestsCase('login'))
    24      # suite.addTest(cleanTestsCase('youhua'))
    25     # suite.addTest(cleanTestsCase('usual'))
    26     unittest.TextTestRunner(verbosity=2).run(suite)
    View Code
     1 #coding=utf-8
     2 from appium import webdriver
     3 from time import sleep
     4 import unittest
     5 
     6 class WxTestsCase(unittest.TestCase):
     7     def setUp(self):
     8         desired_cups={}
     9         desired_cups['platformName']='Android'
    10         desired_cups['platformVersion']='4.4.2'
    11         desired_cups['deviceName']='DU2SSE15A9032675'
    12         desired_cups['appPackage']='com.tencent.mm'
    13         desired_cups['appActivity']='com.tencent.mm.ui.LauncherUI'
    14         self.dr=webdriver.Remote("http://localhost:4725/wd/hub",desired_cups)
    15         sleep(10)
    16     def login(self):
    17         self.dr.find_element_by_id('com.tencent.mm:id/ba_').click()
    18         self.dr.switch_to_alert() #切换到alert窗口
    19         self.dr.find_element_by_id('com.tencent.mm:id/et').click() #点击弹窗上的切换账号选项
    20 
    21 if __name__ == '__main__':
    22     suite = unittest.TestSuite()
    23     suite.addTest(WxTestsCase('login'))
    24      # suite.addTest(cleanTestsCase('youhua'))
    25     # suite.addTest(cleanTestsCase('usual'))
    26     unittest.TextTestRunner(verbosity=2).run(suite)
    View Code
  • 相关阅读:
    分享2021年陆陆续续看过的电影-附电影名单
    LEPUS开源数据库监控系统-开源的MySQL/Oracle/MongoDB/Redis一站式数据库专业级性能监控系统
    分享2021年陆陆续续读过的书-附书单
    Jmeter压测报错:Non HTTP response code: java.net.ConnectExceptionexception的解决办法
    adb安装apk包时提示:device unauthorized
    Pyhton AES_cbc解密
    appium— Android定位webView里面的UI元素
    appium自动化测试实战
    Appium + Python环境搭建(移动端自动化)
    selenium自动化定位方法
  • 原文地址:https://www.cnblogs.com/testhub/p/6265936.html
Copyright © 2011-2022 走看看