zoukankan      html  css  js  c++  java
  • Python编写Appium测试用例(2)

    #coding=utf-8
    import os,sys
    import unittest
    from appium import webdriver
    import time
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC

    # Returns abs path relative to this file and not cwd
    PATH = lambda p: os.path.abspath(
    os.path.join(os.path.dirname(__file__), p)
    )
    ISOTIMEFORMAT='%Y-%m-%d %X'

    class LoginTests(unittest.TestCase):
        def setUp(self):
            desired_caps = {}
            desired_caps['platformName'] = 'Android'
            desired_caps['platformVersion'] = '4.4.4'
            desired_caps['deviceName'] = '24c13456'
            #desired_caps['app'] = PATH('ContactManager/ContactManager.apk')
            desired_caps['appPackage'] = 'com.aaa.bbb'
            desired_caps['appActivity'] = '.MainActivity'

            self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)

        def tearDown(self):
            self.driver.quit()

        def test_user_login(self):
            WebDriverWait(self.driver,20).until(EC.presence_of_element_located((By.NAME, u'个人中心')))
            #打开个人中心
            el_login = self.driver.find_element_by_name(u"个人中心")
            el_login.click()

            #判断当前元素是否存在,若是存在,则用户已登录;若不存在,则执行登录操作

            if(WebDriverWait(self.driver, 10).until(EC.invisibility_of_element_located((By.ID,'id_username')))):
                pass
            else:
                sys.exit()
            #打开登录页面
            login_register = self.driver.find_element_by_id('btn_islogin')
            login_register.click()
            #输入用户名,密码,然后登录
            user_name = self.driver.find_element_by_id('et_usename')
            user_name.send_keys('aaa')
            user_pass = self.driver.find_element_by_id('et_passwrod')
            user_pass.send_keys('123456')
            butn_login = self.driver.find_element_by_id('btn_login')
            butn_login.click()

        def test_user_logout(self):
            #重新打开客户端,然后退出app
            WebDriverWait(self.driver,20).until(EC.presence_of_element_located((By.NAME, u'个人中心')))
            el_logout = self.driver.find_element_by_name(u"个人中心")
            el_logout.click()
            #打开个人信息页面
            WebDriverWait(self.driver,20).until(EC.presence_of_element_located((By.ID, 'id_username')))
            login_pic = self.driver.find_element_by_id('btn_islogin')
            login_pic.click()
            user_logout = self.driver.find_element_by_id('id_logout')
            user_logout.click()

    if __name__ == '__main__':
        suite = unittest.TestLoader().loadTestsFromTestCase(LoginTests)
        unittest.TextTestRunner(verbosity=2).run(suite)

     参考文章:

    a) http://www.tuicool.com/articles/vQ36nyZ

     

  • 相关阅读:
    html-fieldset线中嵌套字符
    在Windows平台上绿色安装postgresQL
    tomcat处理中文文件名的访问(乱码)
    CSS div水平垂直居中和div置于底部
    java-工具类-读取配置文件
    Win+Ctrl键设置
    eclipse-将同一个文件分屏显示
    spring-poi-excle往单元格写入图片
    spring-初始化完成后运行指定内容
    java-collections.sort异常Comparison method violates its general contract!
  • 原文地址:https://www.cnblogs.com/jiguanghover/p/4966732.html
Copyright © 2011-2022 走看看