Appium–automatic login login

Hits: 0

testing scenarios

  1. Start the app and enter the login interface
  2. On the login page, enter the username “self-study 2018”, password ‘zxw2018’ and click login.

# coding:utf-8

from appium import webdriver
from selenium.common.exceptions import  NoSuchElementException

# define a dictionary
desired_caps={}
desired_caps['platformName'] = 'Android'

# Simulate device 
desired_caps[ 'deviceName' ] = '127.0.0.1:62001' 
desired_caps[ 'platforVersion' ] = '5.1.1'

# desired_caps['platformVersion']='9'
# desired_caps['deviceName']='MI8'
# desired_caps['udid']='fed8544a'

desired_caps['app'] = r'C:\Users\Administrator\Desktop\kaoyan3.1.0.apk'
desired_caps['appPackage'] = 'com.tal.kaoyan'
desired_caps['appActivity'] = 'com.tal.kaoyan.ui.activity.SplashActivity'

desired_caps[ 'noReset' ]= 'True'  # Can control the first startup/non-first startup 
# send_keys() when Chinese is passed in 
desired_caps[ 'unicodeKeyboard' ]= "True" 
desired_caps[ 'resetKeyboard' ]= "True"

driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
driver.implicitly_wait( 5 )   # wait for 5s

#Define two methods 
def  check_cancelBtn () : 
    print( "check cancelBtn" )
     try :
        cancelBtn = driver.find_element_by_id("android:id/button2")
    except NoSuchElementException:
        print("no cancelBtn")
    else:
        cancelBtn.click()

def check_skipBtn():
    print("check skipBtn")
    try:
        skipBtn = driver.find_element_by_id("com.tal.kaoyan:id/tv_skip")
    except NoSuchElementException:
        print(" no skipBtn")
    else:
        skipBtn.click()

check_cancelBtn()
check_skipBtn()

  1. Note: The packge directory needs to be created here, otherwise an error will be reported when the “from find_element.capability import driver, NoSuchElementException” package is referenced

# coding:utf-8

from find_element.capability import driver,NoSuchElementException

def login():
    driver.find_element_by_id('com.tal.kaoyan:id/login_email_edittext').clear()
    driver.find_element_by_id( 'com.number.meaning:id/login_email_edittext' ).send_keys( 'Enable 2018' ) .

    driver.find_element_by_id('com.tal.kaoyan:id/login_password_edittext').send_keys('zxw2018')
    driver.find_element_by_id('com.tal.kaoyan:id/login_login_btn').click()

try:
    driver.find_element_by_id('com.tal.kaoyan:id/mainactivity_button_mysefl')
except NoSuchElementException:
    login()
else:
    driver.find_element_by_id('com.tal.kaoyan:id/mainactivity_button_mysefl').click()
    driver.find_element_by_id('com.tal.kaoyan:id/activity_usercenter_username').click()
    login()

You may also like...

Leave a Reply

Your email address will not be published.