• 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()
    
  • 相关阅读:
    原生js系列 删除元素
    事件绑定的几种方式
    js的五种输出方式
    三、浏览器事件处理机制--事件循环(event loop)
    二、事件流、事件代理
    一、事件的分类
    js数据类型转换
    html锚点
    观察者模式
    策略模式
  • 原文地址:https://www.cnblogs.com/lianstyle/p/11055891.html
Copyright © 2020-2023  润新知