[Appium] API for getting started with appium automation (middle)

Sorry, work reasons, pigeons a day, today more and more a bar
in additionWelcome everyone in to remind, Click and enter the password: CSDN

The previous article introduced the use of small tools to start the app and two positioning elements on appium. This article is a small method from appium:remote controlAnd how to put on appiumAdjust the input method to Chinese, Be regarded asTwo tipsBar

Environment Setup [appium] Environment Setup of Appium Automation Introduction ( Part 1 ) The
book continues [appium] API of Appium Automation Introduction (top) and the
following guide [appium] API of Appium Automation Introduction (bottom)-20,000 characters API length Text, recommended collection

text

2.4 Remote

Preface

When starting the app, there is a line of code driver= webdriver.Remote('http://192.168.1.1:4723/wd/hub', desired_caps), many friends don’t know where this ip and port come from, so I edited Decided to write an article about the server ip of this appium!

Generally speaking, the default address of 127.0.0.1 in appium does not need to be modified. In the process of automation, this function can come in handy if you encounter remote operation. Think about it, if the company gives you a separate computer to run automated tests, thenWrite scripts on your own computer and run scripts on automated machinesIsn’t it cool to automate the work in this way?

2.4.1 Set IP

  1. Open appium>General Setting interface
    Insert picture description here

  2. Here we use the appium's default server address, 127.0.0.1, port 4723, == generally debugging on your own machine, no need to modify ==

2.4.2 Access address

  1. Where does the address in the code point to?
    After starting the appium service, enter http://127.0.0.1:4723/wd/hub in the browser. The following figure appears, indicating that the service started successfully, and appium can be seen as a server.
    Insert picture description here

2.4.3 Configure the test machine

  1. A working computer, a computer running automated testing, how to use the working computer to remotely control the computer for automated testing?

  2. Change the appium service address on the test computer to the local IP address such as: 192.168.1.1 (knock on the blackboard, remember the key!If here is the ip address of the machine
    Insert picture description here

  3. start upTest computerOn the appium.
    Insert picture description here

2.4.4 Remote operation

  1. Open the browser on your work computer and enter: 192.168.1.1:4723/wd/hub. This step is very important. Be sure to see the following interface to confirm that the remote link is successful.
    Insert picture description here

  2. Modify the code in the script to the address

  3. After the environment on the test machine is ready, run the script on the machine, so the test machine can run automatically.

# coding=utf-8
from appium import webdriver
import time
desired _caps={
    
    
 'platformName':'Android,
 'deviceName':'30d4e606',
 'platformVersion':'5:0',
 'appPackage':'com.taobao.taobao',
 'appActivity':'com.taobao.tao.welcome.welcome',
 'unicodeKeyboard':True,
 'resetKeyboard':True
 }
driver=webdriver.Remote('http://192.168.1.1:4723/wd/hub',desired_caps)

2.5 Input Chinese

Preface

There are many pitfalls in the process of app automation. We are all using Chinese apps, so firstSolve the problem of Chinese input!
This article passedShield soft keyboard, Bypass the mobile phone's soft keyboard method to solve the Chinese input problem.

2.5.1 Location search

  1. Open the Taobao point search button and enter the search page
  2. Then locate the search box and use the sendkeys method to enter "hao", here to locate the element, use the uiautomatorviewer tool described in the fourth part.
  3. The script is as shown below
# coding=utf-8
from appium import webdriver
import time
desired _caps={
    
    
 'platformName':'Android,
 'deviceName':'30d4e606',
 'platformVersion':'5:0',
 'appPackage':'com.taobao.taobao',
 'appActivity':'com.taobao.tao.welcome.welcome',}
driver=webdriver.Remote('http://192.168.1.1:4723/wd/hub',desired_caps)
# 休眠五秒等待页面加载完成
time.sleep(5)
driver.find_element_by_id("come.taobao.taobao:id/home_searchedit").click()
time.sleep(2)
driver.find_element_by_id("come.taobao.taobao:id/")click()
driver.find_element_by_id("come.taobao.taobao:id/").send_keys(u"hao")

2.5.2 Run script

1. First confirm what input method the input method on the mobile phone is used. If == defaults to the Chinese input method, the following situation will appear after startup, and the input cannot be successful ==
Insert picture description here

2. So you can first change the input method on the phone to English, so that you can input English strings.

2.5.3 Shield soft keyboard

  1. Through the previous operations, you can probably know that the input string in the APP is input by the invoked soft keyboard. Is there a way to do it directly like selenium does web automation? sendkeys bypasses keyboard inputWhat?

  2. So you can find a way to block the soft keyboard, justAdd two parameters in the desired_caps{} setting(Knock on the blackboard, remember the important points!) Insert picture description here

  3. unicodeKeyboard uses unicode encoding to send strings

  4. resetKeyboard is to hide the keyboard

2.5.4 Input Chinese characters

  1. Change the above code to input Chinese u "Like", and then run the script to view the result on the phone. (Add u before Chinese
# coding=utf-8
from appium import webdriver
import time
desired _caps={
    
    
 'platformName':'Android,
 'deviceName':'30d4e606',
 'platformVersion':'5:0',
 'appPackage':'com.taobao.taobao',
 'appActivity':'com.taobao.tao.welcome.welcome',}
driver=webdriver.Remote('http://192.168.1.1:4723/wd/hub',desired_caps)
# 休眠五秒等待页面加载完成
time.sleep(5)
driver.find_element_by_id("come.taobao.taobao:id/home_searchedit").click()
time.sleep(2)
driver.find_element_by_id("come.taobao.taobao:id/")click()
driver.find_element_by_id("come.taobao.taobao:id/").send_keys(u"点赞")

  1. If the Chinese characters are garbled, Add "#–coding:gb18030–" in front
  2. As shown below:
    Insert picture description here

2.5.5 Restore settings

  1. After running the above script, I found that the soft keyboard cannot be called up when I manually enter it. How to restore it?
  2. Open the phone settings and find the input method setting option, you will find that the default input method has been changed to the appium input method. So just change the settings here,Revert to the original input method and click OK
    Insert picture description here

2.5.6 Final script

# coding=utf-8
from appium import webdriver
import time
desired _caps={
    
    
'platformName':'Android,
'deviceName':'30d4e606',
'platformVersion':'5:0',
'appPackage':'com.taobao.taobao',
'appActivity':'com.taobao.tao.welcome.welcome',}
driver=webdriver.Remote('http://192.168.1.1:4723/wd/hub',desired_caps)
# 休眠五秒等待页面加载完成
time.sleep(5)
driver.find_element_by_id("come.taobao.taobao:id/home_searchedit").click()
time.sleep(2)
driver.find_element_by_id("come.taobao.taobao:id/")click()
driver.find_element_by_id("come.taobao.taobao:id/").send_keys(u"hao")

Afterword

I hope these two tips are helpful for shouting. If you have any questions or need to know, you can click and enter the password: CSDN

Insert picture description here
The next trailer:Detailed API instructions

Guess you like

Origin blog.csdn.net/Chaqian/article/details/109084219