-
-
Save maticrivo/10531472a7dceb109bc1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import time | |
import sys | |
import unittest | |
from appium import webdriver | |
class TestCase(unittest.TestCase): | |
def setUp(self): | |
appium_Url = 'http://localhost:4723/wd/hub' | |
self.desired_caps = { | |
'platformName': 'Android', | |
'deviceName': 'Nexus 4', | |
'device': 'Android', | |
'appPackage': 'me.everything.launcher', | |
'appActivity': 'me.everything.launcher.EverythingLauncher', | |
'app': os.getenv('APK_PATH') | |
} | |
self.driver = webdriver.Remote(appium_Url, self.desired_caps) | |
def tearDown(self): | |
self.driver.quit() | |
def test_boarding(self): | |
# select country | |
selectbox_element = self.wait_for_element_by_id('boarding_dropdown_list') | |
if (selectbox_element): | |
selectbox_element.click() | |
else: | |
self.raise_error('Can\'t find the selectbox element') | |
country = self.find_element_by_android_uiautomator('new UiScrollable(new UiSelector().scrollable(true).instance(0)).getChildByText(new UiSelector().className("android.widget.TextView"), "United States")') | |
if (country): | |
country.click() | |
else: | |
self.raise_error('Couldn\'t find country') | |
# pass 'Select Country' screen | |
next = self.wait_for_element_by_id('next_btn') | |
if (next): | |
next.click() | |
else: | |
self.raise_error('Can\'t find the next button on the Select Country boarding screen') | |
# pass 'Personal Search' screen | |
next = self.wait_for_element_by_id('next_btn') | |
if (next): | |
next.click() | |
else: | |
self.raise_error('Can\'t find the next button on the Personal Search boarding screen') | |
# pass 'Personal Folders' screen | |
next = self.wait_for_element_by_id('next_btn') | |
if (next): | |
next.click() | |
else: | |
self.raise_error('Can\'t find the next button on the Personal Folders boarding screen') | |
# pass 'Personal Apps' screen | |
next = self.wait_for_element_by_id('done_btn', 20) | |
if (next): | |
next.click() | |
else: | |
self.raise_error('Can\'t find the next button on the Personal Apps boarding screen') | |
# pass 'Set default example' screen | |
next = self.wait_for_element_by_id('done_btn', 20) | |
if (next): | |
next.click() | |
else: | |
self.raise_error('Can\'t find the next button on the Set default example boarding screen') | |
self.driver.find_element_by_name('EverythingMe').click() | |
self.driver.find_element_by_name('Always').click() | |
try: | |
self.wait_for_element_by_name('OK').click() | |
except Exception: | |
pass | |
# pass the 'Organize your Apps' screen | |
next = self.wait_for_element_by_id('next_btn', 20) | |
if (next): | |
next.click() | |
else: | |
self.raise_error('Can\'t find the next button on the Organize your Apps screen') | |
# pass 'EverythingMe is ready' screen | |
get_started = self.wait_for_element_by_id('get_started', 25) | |
if (get_started): | |
get_started.click() | |
else: | |
self.raise_error('Can\'t find the get started button on the EverythingMe is ready tutorial screen') | |
def wait_for_element_by_id(self, element_id, timeout=15): | |
start_time = time.time() | |
element = self.find_by_id(element_id) | |
time_elapsed = time.time() - start_time | |
while not element and time_elapsed < timeout: | |
element = self.find_by_id(element_id) | |
time_elapsed = time.time() - start_time | |
return element | |
def find_by_id(self, id): | |
try: | |
element = self.driver.find_element_by_id('%s:id/%s' % (self.desired_caps['appPackage'], id)) | |
except Exception, e: | |
return False | |
return element | |
def raise_error(self, msg): | |
raise Exception(msg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment