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()
    
  • 相关阅读:
    makefile ifeq ($(LANG),) 判断操作系统
    MIPS 指令集速查
    ps ef|grep mh* 命令
    ulimit c unlimited 命令
    kill 9 2402 命令
    chmod R 777 命令
    计算机网络总结
    source 命令
    ./ 命令
    reboot f 命令
  • 原文地址:https://www.cnblogs.com/lianstyle/p/11055891.html
Copyright © 2011-2022 走看看