zoukankan      html  css  js  c++  java
  • 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()
  • 相关阅读:
    缩略图架构实现
    基于GDAL实现的PCA变换(主成分分析)
    【OpenGL】GLSL中的函数和子程序(subroutines)
    【OpenGL】关于OpenGL中Bind函数的理解
    使用MTL库求解矩阵特征值和特征向量
    C#键盘事件列表
    C#用 SendKyes 结合 Process 或 API FindWindow、SendMessage(PostMessage) 等控制外部程序
    什么是句柄
    在DLL中产生对话框的方法一(Win32 DLL)
    C# 四舍五入
  • 原文地址:https://www.cnblogs.com/hanxiaobei/p/12962132.html
Copyright © 2011-2022 走看看