Appium+python Note Screenshots, Mobile Controls, Double Finger Enlarged Pictures

Appium+pyhton screenshot, using driver.get_screenshot_as_file("storage path").

(Used to test screenshots using the Flat + uiautomator framework before, no permission to report errors, probably root)

As for mobile controls, I didn't know at first. TouchAction was used and emmmmm later found that this could be done:

Self. driver. drag_and_drop (source control, destination control) is the end of the sentence ~(((> <)/~La, is when familiar with TouchAction.

Double fingers zoom in pinch and zoom, which seems to be called driver.pinch () directly. However, when using this method, direct error reporting during execution is not the method.

Ah, I have to use MultiAction to write it first. I only need to change the data to zoom in and zoom out.

Actual testing still encounters some problems, no experience, on the small details of the problem, grinding for half a day, the key should not be common, but also solved.

It feels a little slow when it actually runs on the flat panel.

Check that the WebdriverWait comment was written incorrectly and the parameters were set for a total of 6 seconds.

Test code:

#coding=utf-8
import unittest
from appium import webdriver
from appium.webdriver.common.multi_action import MultiAction
from appium.webdriver.common.touch_action import TouchAction
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
import CaptureScreenShot

class Test(unittest.TestCase):

    def setUp(self):
        desired_caps={}
        desired_caps['platformVersion']='5.1.1'
        desired_caps['platformName']='Android'
        desired_caps['deviceName']='G0B0ME036482001L'
        desired_caps['appPackage']='com.kugou.android'
        desired_caps['appActivity']='.app.splash.SplashActivity'
        desired_caps['noReset']='true'
        self.driver=webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)
        self.driver.implicitly_wait(3)  #Implicit Wait, Continuous Search and Wait for Control to Appear in 3 seconds
        
    def tearDown(self):
        self.driver.quit()

    def test_capture(self):
        '''
        #Display wait
        #Write the query methods and conditions in the form of lists. Write them directly in the method, of course.   
        loc=("xpath", "//android.view.View[@index='1']")  
        #Obtain the webDriverWait object through webdriver and set it to query conditionally every other second for a total of 10 seconds.
        waitForElement=WebDriverWait(self.driver,6,1)
        #Wait through WebDriverWait.Util() and return to the "skip" in the upper right corner; dynamic wait condition expected_conditions. presence_of_element_location()
        el=waitForElement.until(EC.presence_of_element_located(loc))
        el.click()
        #Click on the top left corner "*" and do not register
        el=waitForElement.until(EC.presence_of_element_located((By.ID,'com.kugou.android:id/uv')))
        el.click()     
        '''
        #Implicit wait, you can get the control directly through find_element_by_method
        #Click "skip"
        el=self.driver.find_element_by_xpath("//android.view.View[@index='1']")
        el.click()
        #Click on the top left corner "*" and do not register
        el=self.driver.find_element_by_id("com.kugou.android:id/uv")
        el.click()
        #Screenshots, keep the original
        CaptureScreenShot.captureScreen(self,'test_find_Skip')
        #Get the Leku control
        musicBox=self.driver.find_element_by_id('com.kugou.android:anim/dr')
        #Setting up TouchAction
        touchAction=TouchAction(self.driver)
        #Long press "Leku" control to make it mobile
        touchAction.long_press(musicBox)
        #Get the Song List control
        musicList=self.driver.find_element_by_id('com.kugou.android:anim/ds')
        #Moving "Music Library" to "Song List" is equivalent to swapping seats.
        touchAction.move_to(musicList).release().perform()
        #emmmmm, later found that this can be: self. driver. drag_and_drop (music Box, music List) sentence is over
        #Take another screenshot, so that you can compare the original image and verify it.
        CaptureScreenShot.captureScreen(self,'Test_Chang_Location')
    def test_zoom(self):
        #Open the camera, browse a photograph taken, and enlarge it.
        self.driver.start_activity('com.amazon.camera', '.AmazonCameraActivity')
        #Click on the photo to browse the area
        self.driver.find_element_by_id('com.amazon.camera:id/thumbnail').click()  
        #Get the current photo display control, using the same length and width of the tablet
        imageView=self.driver.find_element_by_id('com.amazon.photos:id/photo_view')
        #Get screen height and width
        srcHeight=self.driver.get_window_size()['height']
        srcWidth=self.driver.get_window_size()['width']
        #Set up MultiAction to be multi-touch
        multiAction=MultiAction(self.driver)
        #Set up two "single point" actions
        t1=TouchAction(self.driver)
        t2=TouchAction(self.driver)
        #Divide two points to hold the photo for 0.25 seconds (if the middle is not equal, it may be that the program point is too fast or something, it will quit the browsing mode or do not enlarge the function), so little at first can not understand that it takes a lot of time to waste some time, the experimental tablet has a pit, and the mobile phone will not casually withdraw from the browsing mode); the X axis is fixed, moving upward and downward from the middle of the screen.
        t1.long_press(imageView,srcWidth/2,srcHeight/2 - 100).wait(250).move_to(imageView,srcWidth/2,srcHeight/2-130).release()
        t2.long_press(imageView,srcWidth/2,srcHeight/2 + 100).wait(250).move_to(imageView,srcWidth/2,srcHeight/2+125).release()
        #Only one add () can be added separately, unlike Java methods, multiAction.add(t1).add(t2)
        multiAction.add(t1)
        multiAction.add(t2)
        multiAction.perform()
    
if __name__ == "__main__":
    unittest.main()

Screenshot file: CaptureScreenShot.py

#coding=utf-8
'''
Created on 2019 August 30th 2013
@author: derik
'''
import time
from appium import webdriver
#Pass Picture Name Parameters
def captureScreen(self,filename):
        #Get the system time and convert the format as the image name, 20190830161035
        date=time.strftime("%Y%m%d%H%M%S",time.localtime())
        #Splicing storage path, computer path + time + picture name +.png
        storeFile='/home/derik/picture/'+date+filename+'.png'
        #The key sentence is get_screenshot_as_file
        self.driver.get_screenshot_as_file(storeFile)

Record screen separately, effect record 1 (running for 35 seconds):

       

Zoom in (22 seconds):

Keywords: Android Mobile Selenium Java

Added by melody on Thu, 03 Oct 2019 07:12:07 +0300