zoukankan      html  css  js  c++  java
  • Appium入门脚本

    没有用框架的代码实现登录功能:

    import time
    from selenium import webdriver
    
    
    # 创建字典
    desired_caps = {}
    desired_caps['platformName'] = 'Android'
    desired_caps['platformVersion'] = '5.1'
    desired_caps['deviceName'] = 'm2 note'
    desired_caps['appPackage'] = 'com.test.abc'
    desired_caps['appActivity'] = 'com.app.ui.activity.WelcomeActivity'
    # 方便输入中文
    desired_caps['unicodeKeyboard'] = 'True'
    desired_caps['resetKeyboard'] = 'True'
    # 每次测试清空缓存
    desired_caps['noReset'] = 'False'
    driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
    time.sleep(6)
    # 通过xpath定位“去登录”按钮并点击
    driver.find_element_by_xpath('/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.TextView[2]').click()
    # 输入用户名、密码,点击登录按钮
    driver.find_element_by_xpath('/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.EditText').send_keys('username')
    driver.find_element_by_xpath('/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout[1]/android.widget.LinearLayout[2]/android.widget.EditText').send_keys('password')
    driver.find_element_by_xpath('/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout[2]/android.widget.Button').click()
    # 判断是否成功
    try:
        if driver.find_element_by_xpath("test/test").is_displayed():
            print('pass')
    except Exception as e:
        print(e)
        print("fail")
    time.sleep(3)
    # 资源释放
    driver.quit()
    
  • 相关阅读:
    event对象之与onmouse相关的事件触发
    对文档树进行导航
    event对象的onkeydown使用
    event的onchange方法
    函数名-函数参数坑-迭代器
    函数进阶-名称空间
    初识函数
    文件管理
    基础数据类型补充-编码进阶
    集合-缓存机制-深浅copy
  • 原文地址:https://www.cnblogs.com/lianstyle/p/11055891.html
Copyright © 2011-2022 走看看