? 5.1 Capability Introduction 5.1.1 What is capability
Before talking about capability, do you remember the log at startup when you told us about log? In our entire boot log there will be some configuration information, in fact, that information is capability carry configuration information, if we start through the code we can see the configuration information as follows:
PATH = Lambda P:os.path.abspath (os.path.join (Os.path.dirname (__file__), p)) capabilities = {}capabilities[' PlatformName '] = ' Android ' #设置平台capabilities [' platformversion '] = ' 4.1 ' #系统版本capabilities [' devicename '] = ' 127.0.0.1:62001 ' #设备idcapabilities [' autoLaunch '] = ' true ' #是否自动启动capabilities [' app '] = PATH (' ... /apps/mukewang.apk ') #安装包路径, placed in the directory of the py file) capabilities[' apppackage '] = ' CN.COM.OPEN.MOOC ' #包名capabilities [' Appactivity '] = ' cn.com.open.mooc.aindex.splash.MCSplashActivity ' #启动的activityself. Driver = Webdriver. Remote (' Http://localhost:4723/wd/hub ', capabilities)
Through the configuration information above, we can see that in Python we are talking about a capability is actually a dictionary (we say this for the moment, because each language is different).
The role of 5.1.2 capability
Do we know if capability is a dictionary and do we need to know what his role is? After we have configured the app in Appium, we can see that the information inside is the necessary configuration to start, through the configuration information above, I can also see that the capability configuration is the necessary information of our automation. He mostly tells the server whether we have a browser or app, iOS or Android and Android version information. If capability does not tell the server, then the server will not know you and will not be able to complete our automated tests.
5.2 Common capability Configuration explanation 5.2.1 common capability
If someone who has known capability will find a problem, he is basically divided into three parts: the public part, the iOS part, the Android part, if you want to use iOS for Android that is impossible, so, honestly to understand what each platform, what their role is. Below we introduce some common common
In the automated testing process these common capability use more time, we need to remember, to familiarize himself with his usage.
5.2.2 Android Exclusive Capability
In the automated testing process if you only know some of the commonly used parameters configuration, this is far from the requirements, because you do not know when the unexpected situation occurs, so you need to understand appium all the most commonly used configuration parameters, of course, you can master all, so better, practice makes perfect. Let's look at the Android capability.
The above is just a few simple examples, the main function is to tell you, these are we often use, if you meet a similar demand so can be used directly, but also hope that you see here when you start to operate, to see the results of his implementation is how. Only in this way can you calculate the master, just see again or not.
5.2.3 iOS exclusive capability
When I chose Appium, the main reason is that he can support both iOS and Android, and iOS has his own unique part in the basic parameter configuration, not the same as Android, let's take a look around:
Boundleid: This is a must, if not configured to start the iOS app, this is the app's unique logo. Eg:caps.setCapability ("Boundleid", "ios.mooc.test"), this is just a simple example.
Autoacceptalerts: This is very practical in our actual project, he would like a Web side of a JS pop-up window, by default is False, if you have a similar situation in the app is suggested to open. Eg:caps.setCapability ("Autoacceptalerts", "true")
5.3 Capability Combat
When we know how the basics of capability are used, do we feel that we can do it all now? In fact, yes, it is possible to carry out the same. But have you ever thought about a problem? What if your app has changed? Your package has changed? Has your phone changed? Your version is changing, and so how do you do it? Do you still need to go inside the program to change the code? Is it low? We'll look down if we don't.
1 deftestCase (platformname,platformversion,devicename,app,apppackage,appactivity,port):2PATH =LambdaP:os.path.abspath (Os.path.join (Os.path.dirname (__file__), p))3Desired_caps = {}4desired_caps['PlatformName'] = PlatformName#setting up the platform5desired_caps['platformversion'] = Platformversion#System Version6desired_caps['devicename'] = DeviceName#Device ID7desired_caps['AutoLaunch'] ='true' #whether to start automatically8desired_caps['app'] = PATH (APP)#Install the package path, placed in the directory of the py file)9desired_caps['Apppackage'] = Apppackage#Package NameTendesired_caps['appactivity'] = appactivity#Activated activity OneSelf.driver = Webdriver. Remote ('Http://localhost:%s/wd/hub', desired_caps)% port
From the above code we can compare with the previous code, we have found some differences. We have to maintain the flexibility of the data when we do automation, so here we make some small changes, we change all the data into variables, where the variables come from we will say later, this will read the configuration file. Is it more readable now from the code level than the previous code? In fact, this is not the case, there is a more advanced version, this is said later.
In the 11th line of code, there's a problem. No, in the middle of a string I used a%s, which in Python means to take a variable, which is the value of the variable that I followed in port, the only problem here is here.
Capability Introduction to the Appium Python Automation Test series (v)