Open uiautomatorViewe 2. Appium common operations 1. What if I get an error when I use Layui to position an app element? 2. Will an error be reported if I go directly to the element without waiting? 3. If it is Web automation, it will import By. In Appium, MobileBy has 8 positioning methods. If we still use By, we can’t use UIAutomator and accessibility_id. 4. What if the welcome page does not have this element? 3. Open app and log in 4. Special operations on mobile terminal 1. If you can write an action that works on all phones, shouldn’t you consider the size of the screen? 3. Is there any way to get the size of the entire device? 4. How to get the size of the screen? 5. This thing wants to slide it in one breath, but it can’t slide back in the middle. If I slide from right to left, where do I start and where do I end? 6. How long are you going to slide?

Open uiautomatorVieWe and use this tool to position you:Implement a screenshot (usually used this way, you can take a successful screenshot).

1. How to use Layui to do app element positioning error? Layui is not recommended. Layui has problems locating elements in some cases. It doesn’t capture screenshots when the environment is basically correct. So instead of layUI, you can use the built-in UIAutomatorViewer (which supports all the positioning methods you now have).

2. Will an error be reported if I go directly to the element without waiting? As with Web automation, Appium takes time to execute this command. This line of code is going into the app, and the app is doing one thing in the process, so even if you’re only running this line of code, it’s doing a lot of things.

It feels like a longer wait than the Web, but it’s faster if you’re using the real thing than the emulator.

So wait a little bit before you do that. The WebDriverWait and EC conditional expressions are used when the Web automation waits. The same is true here, because the page is waiting for the element to appear, for the element to be visible.

3. If it is Web automation, it will import By. In Appium, MobileBy has 8 positioning methods. If we still use By, we can’t use UIAutomator and accessibility_id. So the code in the middle of the mobile terminal: from selenium.webdriver.com mon. By the import by

To change to: the from appium.webdriver.com mon. Mobileby import mobileby

We don’t need to use “By” anymore. “By” has all the ids, all the classes. So, wait for this ID to appear in this place, which is:

WebDriverWait(driver,20).until(EC.visibility_of_element_located((MobileBy.ID,’com.huyu.yuncaidian:id/id_text’)))

This is what you must do when you open the app.

4. What if it’s a welcome page without this element? If you go to the welcome screen by default, and you want to swipe left and right, then sleep, because you don’t have any recognizable elements.

It is useless to identify the Activity by its name, because it is also called an Activity.It can be found, but it doesn’t mean it’s out.

Don’t use time.sleep if you have explicit elements. We just wait for the element to appear, and then we manipulate the element.

This element positioning is the same as Web element positioning, in a number of ways.

Android and ios screens are limited in size, so you don’t have too many elements in one page, and you don’t have too many elements in one page. Because it requires you not only to be able to see it but to touch it with your hands. So it will make a pattern with less content on it, and it will have a larger spacing.

After clicking “Mine”, the page content switches. Page content switch, you have to wait, it also has to load time.

3. Open the APP and log in

# a app 2.9.0 quasi environment from appium import webdrive import time from the selenium. Webdriver. Support. Wait the import WebDriverWait the from selenium.webdriver.support import expected\_conditions as EC from appium.webdriver.common.mobileby import MobileBy Desired \_caps["platformName"]="Android" desired\_caps["platformVersion"]="7.0" # Device name Desired \_caps["deviceName"]="XPUDU17713003790" desired\_caps["appPackage"]=" privacy "# app entry acitivity Desired \_caps["appActivity"]=" privacy "# Connect to Appium server. Prerequisite: Appium Desktop is to be started. There is a listening port. # Send desired\_caps to the appium server. Open the app driver = webdriver. Remote (' http://127.0.0.1:4723/wd/hub ', desired \ _caps) # before running the code: # 1. Appium server started successfully. #2. The simulator/real machine must be recognized by the computer. That is, ADB Devices can recognize the device to operate. Driver.find \_element\_by\_xpath("//\*[@resource-id='com.tfffc.cf:id/id\_text' and "//\*[@resource-id='com.tfffc.cf:id/id\_text' and "//\*[@resource-id='com.tfffc.cf:id/id\_text' and @text=' my ']").click() # WebDriverWait(driver,20).until(EC.visibility\_of\_element\_located((MobileBy.ID,'com.tfffc.cf:id/tv\_phone\_passwad'))) Driver.find \_element\_by\_id('com.tfffc.cf:id/ TV \_phone\_passwad').click() # Enter user name, password and click the login button WebDriverWait(driver,20).until(EC.visibility\_of\_element\_located((MobileBy.ID,'com.tfffc.cf:id/editview\_phone'))) Driver.find \_element\_by\_id('com.tfffc.cf:id/editview\_phone').send\_keys(' input phone number ') Driver.find \_element\_by\_id('com.tfffc.cf:id/editview\_phone\_password').send\_keys(' input password') driver.find\_element\_by\_id('com.tfffc.cf:id/phone\_password\_login').click()Copy the code

Swipe function of Appium swipes according to the coordinates on the screen.

Swipe functions are available on both Android and IOS devices.If you slide from one point to another, then each point has an x value and a y value. Swipe has four parameters. So start x, start y, end x, end y.

2. If you can write an action that works on all phones, should you consider the size of the screen? There are 5 – inch, 4.4 – inch and 5.7 – inch phones. The resolution is 1280×700, so its largest coordinate point is 1280×700. Different Android manufacturers, different sizes, its resolution is not the same, its coordinate value is absolutely different.

What about this? What’s a good way to incorporate this feature?

There is no need to write a piece of code for each version of the phone, all common.

There is a drawback to using coordinates: it might work on one type of phone, but not on another because the coordinates don’t match.

3. Is there any way to get the size of the entire device? Let’s just get what its width and height are. I’m sliding at a point on the screen, not at an element. The whole screen slide is left slide right slide up slide down.

Set the percentage of slides. If you slide 40 to 50 percent, it won’t feel like you can slide through. If you can get the size of the whole screen, slide it by percentage, and the distance is 70-90%, you’ll be able to slide through.

According to the x axis and y axis of each phone, determine the percentage of its slide screen, so that any kind of phone can slide the screen. So when you implement this slide, you first get the size of the screen.

4. How to get the size of the screen? There is a special function: get_window_size that returns the width and height of the window.If you slide from one point to another, then each point has an x value and a y value. Swipe has four parameters. So start x, start y, end x, end y.

2. If you can write an action that works on all phones, should you consider the size of the screen? There are 5 – inch, 4.4 – inch and 5.7 – inch phones. The resolution is 1280×700, so its largest coordinate point is 1280×700. Different Android manufacturers, different sizes, its resolution is not the same, its coordinate value is absolutely different.

What about this? What’s a good way to incorporate this feature?

There is no need to write a piece of code for each version of the phone, all common.

There is a drawback to using coordinates: it might work on one type of phone, but not on another because the coordinates don’t match.

3. Is there any way to get the size of the entire device? Let’s just get what its width and height are. I’m sliding at a point on the screen, not at an element. The whole screen slide is left slide right slide up slide down.

Set the percentage of slides. If you slide 40 to 50 percent, it won’t feel like you can slide through. If you can get the size of the whole screen, slide it by percentage, and the distance is 70-90%, you’ll be able to slide through.

According to the x axis and y axis of each phone, determine the percentage of its slide screen, so that any kind of phone can slide the screen. So when you implement this slide, you first get the size of the screen.

4. How to get the size of the screen? There is a special function: get_window_size that returns the width and height of the window.Get_window_size () : returns a dictionary.

5. This thing wants to slide it in one breath, but it can’t slide back in the middle. If I slide from right to left, where do I start and where do I end? Swipe has two coordinate points, so the first thing to do is to get start_x.

The X-axis is width. Size [‘width’] is the maximum value of the X-axis.

What everyone does: The screen slides right in the middle or slightly down. As you slide from page to page, the Y-axis doesn’t change.

So the y value is fixed, so let’s take a median value of 0.5:

#height, width size= driver.get\_window\_size() start\_x=size['width']\*0.9 start\_y=size['height']\*0.5Copy the code

It is better to slide with an interval of 80% or more, so that the interval is 0.8:

#height, width size= driver.get\_window\_size() start\_x=size['width']\*0.9 start\_y=size['height']\*0.5 End \ _x = size "width" \ * 0.1Copy the code

Swipe also has a parameter called duration, which is in milliseconds.

6. How long are you going to slide? Look at the operation of the phone, if you swipe too fast, there is no effect. Sometimes it slides so fast that it’s over before it can respond. A duration can be set to slow it down a bit, which is more stable.

When I slide up and down, what is start_x? I’m going to slide up and down, and I’m going to keep my X-axis the same, and I’m going to take the middle. But as you go down the Y-axis, it gets smaller and smaller.

This can encapsulate it, and you can just call it when you need it, and it’s the same on any device. If there are methods in WebDriver that indicate that they are ios or Android only, they are only available on that platform.

If a function is not specified, then it is used by everyone, equally.

#height, width size= driver.get\_window\_size() start\_x=size['width']\*0.9 start\_y=size['height']\*0.5 End \ _x = the size \ * 0.1 end \ [" width "] _y = the size \ [' height '] * 0.5 # slip driver from right to left. Swipe (start \ _x, start \ _y, end \ _x, end \ _y, 200) # slide from left to right Swipe (end\_x,end\_y,start\_x,start\_y,200) Constant x axis, y from big to small driver. The swipe (size "width" \ * 0.5, size "heigth" \ * 0.9, size "width" \ * 0.5, size/heigth "\ * 0.1) # sliding upwards: X constant, since the childhood y driver. Swipe (size "width" \ * 0.5, size "heigth" \ * 0.1, size "width" \ * 0.5, size/heigth "\ * 0.9)Copy the code

Finally: [May give you some help]

These data, for [software testing] friends should be the most comprehensive and complete preparation warehouse, this warehouse also accompanies tens of thousands of test engineers through the most difficult journey, hope to help you!

Follow my wechat public number [software test small DAO] free access ~

My learning exchange group: 644956177 there are technical experts to communicate and share together in the group ~

If my blog is helpful to you, if you like my blog content, please “like” “comment” “collection” one key three!