Comprehensive practice of Appium id location -- automatic login (postgraduate entrance examination help)

Keywords: network Android Attribute Selenium

Integrated practice of id location -- automatic login
Test scenario
1. Start the App and enter the login interface
2. Enter the user name "self study network 2018" and password "zxw2018" on the login page and click login.
requirement analysis
1. The modules that detect and upgrade the pop-up window and the guide page after startup can be pulled out as independent modules and called by other modules to improve the code reuse rate.
2. Get the element id attribute of user name and password input box and login button. In addition, consider whether the App has logged in the account before startup. The process of logged in scenario is different from that of not logged in scenario.
3. Note: the following content needs to be configured in capability when sending_keys() is transferred into Chinese:

desired_caps['unicodeKeyboard']="True"
desired_caps['resetKeyboard']="True"

Code implementation:
capability.py

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

desired_caps={}
desired_caps['platformName']='Android'
desired_caps['deviceName']='127.0.0.1:62025'
desired_caps['platforVersion']='5.1.1'

# desired_caps['deviceName']='JDN-W09'
# desired_caps['platforVersion']='6.0.1'
# desired_caps['udid']='7YRBBDB7B0702188'

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

desired_caps['noReset']='true'  #Simulated user not started for the first time
desired_caps['unicodeKeyboard']="true"  #Login in Chinese, code to be configured
desired_caps['resetKeyboard']="true"    #Reset keyboard to true

driver=webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)
driver.implicitly_wait(2)


def check_cancelBtn():
    print('check cancelBtn')

    try:
        cancelBtn=driver.find_element_by_id('android:id/button2').click()   #Find this element
    except NoSuchElementException:
        print('no cancelBtn')   #When there is no such element, no cancelBtn will be printed out
    else:
        cancelBtn.click()   #Click when there is this element

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()

kyb_login.py

from find_element.capability import driver,NoSuchElementException

def login():
    driver.find_element_by_id('com.tal.kaoyan:id/login_email_edittext').clear() #Clear the input box first
    driver.find_element_by_id('com.tal.kaoyan:id/login_email_edittext').send_keys('Self study network 2018') #Then pass in the corresponding value Send Keys

    driver.find_element_by_id('com.tal.kaoyan:id/login_password_edittext').send_keys('zxw2018') #Password does not need to be cleared
    driver.find_element_by_id('com.tal.kaoyan:id/login_login_btn').click()  #Login button

try:    #Last login information is reserved for last login
    driver.find_element_by_id('com.tal.kaoyan:id/mainactivity_button_mysefl')   #Click "I"
except NoSuchElementException:
    login() #If there is no such element, directly enter the login interface and call login()
else:
    driver.find_element_by_id('com.tal.kaoyan:id/mainactivity_button_mysefl').click() #If you have this element, click me
    driver.find_element_by_id('com.tal.kaoyan:id/activity_usercenter_username').click() #Then click not logged in
    login() #To call login()

Then run kyb_login.py
Be careful:
After using Appium to do the input operation, if the input method cannot be recalled, you can replace the current input method with system input method or other input methods in system settings - language and input method.

Posted by bucko on Fri, 20 Dec 2019 08:34:50 -0800