Python Writing Appium test Cases (2)

Source: Internet
Author: User
Tags appium

#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 ' Personal Center '))
#打开个人中心
El_login = self.driver.find_element_by_name (u "Personal Center")
El_login.click ()

#判断当前元素是否存在, if present, the user is logged in, or if it does not exist, perform a login operation

        if (webdriverwait (Self.driver). Until (ec.invisibility_of_element_located (by.id, ' Id_username ')):
            Pass
        ELSE:
            sys.exit ()
        #打开登录页面
        Login_regist ER = self.driver.find_element_by_id (' btn_islogin ')
        Login_register.click ()
  & nbsp     #输入用户名, password, and then login
        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):
#重新打开客户端 and then quit the app
Webdriverwait (self.driver,20). Until (Ec.presence_of_element_located ((by.name, U ' Personal Center '))
El_logout = self.driver.find_element_by_name (u "Personal Center")
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)

Reference article:

A) Http://www.tuicool.com/articles/vQ36nyZ

Python Writing Appium test Cases (2)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.