Python&appium Implement slide guide page into app

Source: Internet
Author: User
Tags appium

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.