12.1 What is the hybrid App12.1.1 hybrid app definition
What is the hybrid app, in fact, this is self-evident, our app should be native, but the actual work is not, anyway, there are various reasons for our app will have native and there will be H5 page, this is actually what we often say the mix, of course, there is a kind of pure H5, But here we don't do too much explaining.
12.2 Mixed app Combat Ideas 12.2.1 Code Combat
In the previous chapter embedded H5 page Positioning we have already talked about this problem, in fact, the contents of this talk we can carefully put the positioning of the embedded H5 positioning issues to review again then you can understand the things here, there will be a problem is that in our app Automation and Web Automation will have some differences, Here are some APIs to use to pay attention to. Let's look at a process below and see two images below:
The first photo is the native page of our app:
The second picture is the interface of our WebView:
We said in the previous chapters that if we need to switch from the first page to the second page we need to switch to the "context", and only after we have switched it can we proceed further with the page, see the following code:
def view (self): #获取当前页面所有的contexts time.sleep (5) WebView = self.driver.contexts #在获取到的contexts List inside to cycle for the context in WebView: #判断循环中单个的context是否是webview, if it is to switch, and jump out of the loop if ' WebView ' in the context: Self.driver.switch_to.context (context) break self.driver.find_element_by_link_text (' JAVA '). Click ( )
So far we have been able to easily and freely operate the app's embedded H5 page. Let's do it.
Note: If you use the real machine has been unable to switch, do not be excited this is normal, use the simulator to try, because the real machine has a lot of restrictions, you can try to root after the test.
12.3 Mixed App Combat
The above knowledge I believe that everyone is easy to understand, but in the actual operation we will meet a minimum problem, the above questions to see we explain below, in our normal operation, we are not operating the second page should close the page and then go directly to operate other pages? So we have the following code:
def view (self): #获取当前页面所有的contexts time.sleep (webview) = self.driver.contexts #在获取到的contexts List inside to cycle for the context in WebView: #判断循环中单个的context是否是webview, if it is to switch, and jump out of the loop if ' WebView ' in the context: Self.driver.switch_to.context (context) break self.driver.find_element_by_link_text (' JAVA '). Click ( ) #关闭按钮定位 self.driver.find_element_by_id ("Cn.com.open.mooc:id/left_icon"). Click
Moving hands of the small partner will know the problem, you can not operate the Close button or close the operation of other pages of the element, the above code anyway to close the error, right! But when you think about it, we've talked about switching from the native app to the H5 page, so is the driver still in H5 now? Think about thinking!!! You are still H5 home, and then you let him to operate the original driver things can do? The answer is definitely no, so you need to switch driver to the original driver at this time.
Think: If your app has super-many H5 pages then do you need to constantly switch during the test? Are you in trouble? Yes, sure. Every time you switch to write this method you do not abandon tired I do not want to tired. So, do we need to think about solutions here? So did the function encapsulation that we said before in Python work? Here for everyone to leave a study questions, if you do an efficient package.
Note: This is often used in the work, we must go to practice this study questions.
Tip: A clumsy approach is encapsulated into two methods, which are packaged into a single method and then implemented by passing parameters.
Appium Python automation Test series Hybrid app Combat (11)