Recently studied automated testing for Android apps. The first problem is that when a session is established, the first entry is the Welcome page and the Guide page, the Guide page has three, the last one shows the "Enter" button, click to enter the main interface.
Welcome page plus Guide page, these two pages are unavoidable every time you enter the app, how to do the code to skip them into the main interface of the operation?
1. Set up session
def test_enterApp(self): desired_caps = {} desired_caps[‘platformName‘] = ‘Android‘ desired_caps[‘platformVersion‘] = ‘4.4.4‘ desired_caps[‘app‘] = ‘/Users/a140/Downloads/app.apk‘ desired_caps[‘deviceName‘] = ‘03083025d0250909‘ self.driver = webdriver.Remote(‘http://localhost:4723/wd/hub‘, desired_caps) self.driver.implicitly_wait(5)
2. Use code to simulate the right-to-left swipe of your finger
#获取屏幕宽度和高度 def getSize(self): x = self.driver.get_window_size()[‘width‘] y = self.driver.get_window_size()[‘height‘] return (x, y) #向左滑动 def swipeLeft(self): l = self.getSize() x1 = int(l[0] * 0.9) y1 = int(l[1] * 0.5) x2 = int(l[0] * 0.1) self.driver.swipe(x1, y1, x2, y1)
Because the size of the phone screen is diverse, it does not set a fixed width and height value, but encapsulates a way to get a wide screen height, which calculates the coordinates and distances of the screen slide.
3, call the Swipeleft () method to swipe left, finally through FIND_ELEMENT_BY_ID () find the "Enter" button, and then click to enter the main interface
#向左滑动跳过引导页 x = 0 while x < 3: self.swipeLeft() x += 1 enterApp = self.driver.find_element_by_id("com.app.night:id/enter") enterApp.click()
The complete code is as follows:
Import unittestfrom appium import Webdriverclass HelloWorld (unittest. TestCase): def test_enterfilter (self): Desired_caps = {} desired_caps[' platformname '] = ' Android ' desired_caps[' platformversion ' = ' 4.4.4 ' desired_caps[' app '] = '/users/a140/downloads/app.apk ' desired_caps [' devicename '] = ' 03083025d0250909 ' self.driver = webdriver. Remote (' Http://localhost:4723/wd/hub ', Desired_caps) self.driver.implicitly_wait (5) #向左滑动跳过引导页 x = 0 While x < 3:self.swipeleft () x + = 1 Enterapp = self.driver.find_element_by_id ("com . App.night:id/enter ") Enterapp.click () #获取屏幕宽度和高度 def getsize (self): x = Self.driver.get_window_size () [' width '] y = self.driver.get_window_size () [' Height '] return (x, y) #向左滑动 def swipeleft (self): L = self.getsize () x1 = Int (l[0] * 0.9) y1 = int (l[1] * 0.5) x2 = Int (l[0] * 0.1) self.driver. Swipe (x1,Y1, x2, y1) if __name__ = = ' __main__ ': Suite = unittest. Testloader (). Loadtestsfromtestcase (HelloWorld) unittest. Texttestrunner (verbosity=2). Run (Suite)
Python&appium implement slide guide page into app