The article for reprint, thank you predecessors of the collation and efforts
9.1 Use of the wait function 9.1.1 Why to use the wait function
We're not very good at automating things, not because of the app problem, our script is not a problem, but a lot of times will be an error, such as a page originally has ID 1 of this element, but I no matter how positioning he can not operate, and then the error, this is how the situation. Because when our app opens a page, our Appium runs too fast, so it's possible that we don't have the resources to parse the page and then you're going to do it. Certainly not, so that no error. So in a lot of times we all need to load the waiting time. Then we are not blindly go to each page load wait time. 9.1.2 When to use the wait function
The answer is definitely no, the purpose of automation is efficient, but the efficiency of the execution is greatly reduced if you add the wait time to each page. It's time for your leader to talk to you. In the load wait time we need to increase according to their own judgment, such as some page resources more load slow then you definitely need to add. Is that what it is all about. Not really, so this has the following knowledge points we need to talk about, several different types of waiting. 9.2 Force-waiting 9.2.1 What is forced wait
Therefore, the name of righteousness is that you must give me a little bullying meaning. For example: I entered the landing page, just have a mandatory waiting function, then the result is no matter whether the resources of the page after loading, you have to wait for me. Do you understand. As long as the time has not arrived you will wait for me. Haha, just like that what kind of unreasonable ah. 9.2.2 force wait to use
In Python this is better, he calls the wait function under the time package, and the code is as follows:
1 2 3 |
#coding = "Utf-8" Import Time Time.sleep (10) |
First is the need to import time package, the following sentence is done, is not convenient and practical. It's good to write when you debug a program, and don't use it in actual projects. Because this time wait is the Deng of the thread, that is to execute the statement anyway, if you run it in the actual project then you will find the efficiency is very slow. So the actual project is not recommended.
Note: Time is calculated in seconds 9.2.3 forced to wait for package combat
We've learned about the encapsulation of functions, and if we need to use this wait function in a lot of places, it's not everywhere. Not really, the most important purpose of the program is that we can write less even a word we have to encapsulate, this is my understanding. To achieve the same function why not pick a simple way to do it. Right. See Package code:
1 2 3 4 5 6 7 8 (9) "#conding =" utf. -8 "Import time from appium import webdriver import os def case (PlatformName, platformversion,devicename,app,apppackage,appactivity): path = lambda p: Os.path.abspath (Os.path.join (Os.path.dirname (__file__), p)) #print getconfig ("baseconf", "PlatformName ") desired_caps = {} desired_caps[' PlatformName ' |