• Android Native和Hybrid两种架构采用Appium进行UI自动化


    一、Native和Hybrid两种架构,整理一张图

    二、native与web view上下文切换简单代码示例

     1 import pytest,time
     2 from appium import webdriver
     3 from selenium.webdriver.common.by import By
     4 from selenium.webdriver.support import expected_conditions
     5 from selenium.webdriver.support.wait import WebDriverWait
     6 
     7 class TestDemo():
     8     def setup(self):
     9         caps = {}
    10         caps["platformName"] = "Android"
    11         caps["deviceName"] = "Android Emulator"
    12         caps["appPackage"] = "com.xxxxx.android"
    13         caps["appActivity"] = ".view.WelcomeActivityAlias"
    14         caps["autoGrantPermissions"] = "true"
    15         #Chromedriver可通过Chrome浏览器的inspect看到app自带的web view版本号,再去下载相应的driver
    16         # caps["chromedriverExecutable"] = "Chromedriver的路径"
    17 
    18         self.driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
    19         self.driver.implicitly_wait(20)
    20         self.driver.find_element_by_id("com.xueqiu.android:id/tv_agree").click()
    21 
    22     def test_webview(self):
    23         self.driver.find_element_by_xpath("//*[@text='男女']").click()
    24         #打印出上下文信息
    25         for i in range(3):
    26             time.sleep(5)
    27             print(self.driver.contexts)
    28 
    29         self.driver.find_element_by_accessibility_id("开户").click()
    30         #切换到web view中
    31         self.driver.switch_to.context(self.driver.contexts[1])
    32         #等待元素展示完全再进行点击和输入内容
    33         WebDriverWait(self.driver,15).until(expected_conditions.visibility_of_element_located((By.ID,"phone-number")))
    34         self.driver.find_element_by_id("phone-number").send_keys("13577778881")
    35 
    36 
    37     def teardown(self):
    38         time.sleep(10)
    39         self.driver.quit()
  • 相关阅读:
    LINQ查询表达式(5)
    LINQ查询表达式(4)
    并不对劲的loj2279
    并不对劲的bzoj1563:p1912:[NOI2009]诗人小G
    并不对劲的loj507
    并不对劲的loj2332
    并不对劲的loj6191
    并不对劲的bzoj4552:p2824:[HEOI2016/TJOI2016]排序
    并不对劲的bzoj3924:loj2135:p3345:[ZJOI2015]幻想乡战略游戏
    并不对劲的bzoj3295:[CQOI2011]动态逆序对
  • 原文地址:https://www.cnblogs.com/hanxiaobei/p/12962132.html
Copyright © 2020-2023  润新知