Update python sample code (#12681)

This commit is contained in:
Isaac A. Murchie
2019-05-23 09:37:40 -04:00
committed by GitHub
parent 240810d028
commit eb4ddafc36
15 changed files with 215 additions and 147 deletions

View File

@@ -1,35 +1,40 @@
import unittest
import os
import copy
import sys
from time import sleep
from appium import webdriver
from helpers import take_screenhot_and_logcat, ANDROID_APP_PATH, EXECUTOR
from selenium.common.exceptions import InvalidSessionIdException
from helpers import report_to_sauce, ANDROID_BASE_CAPS, EXECUTOR
from selenium.common.exceptions import WebDriverException
# Run standard unittest base.
class TestAndroidSelectors(unittest.TestCase):
class TestAndroidCreateSession(unittest.TestCase):
def tearDown(self):
report_to_sauce(self.driver.session_id)
def test_should_create_and_destroy_android_session(self):
caps = copy.copy(ANDROID_BASE_CAPS)
caps['name'] = 'test_should_create_and_destroy_android_session'
def setUp(self):
self.driver = webdriver.Remote(
command_executor=EXECUTOR,
desired_capabilities={
'app': ANDROID_APP_PATH,
'platformName': 'Android',
'automationName': 'UIAutomator2',
'platformVersion': os.getenv('ANDROID_PLATFORM_VERSION') or '7.1',
'deviceName': os.getenv('ANDROID_DEVICE_VERSION') or 'Android',
}
desired_capabilities=caps
)
self.driver.implicitly_wait(10)
def test_should_create_and_destroy_android_session(self):
activity = self.driver.current_activity
pkg = self.driver.current_package
# make sure the right package and activity were started
self.assertEquals('io.appium.android.apis', self.driver.current_package)
self.assertEquals('.ApiDemos', self.driver.current_activity)
self.assertEquals('io.appium.android.apis.ApiDemos', '{}{}'.format(pkg, activity))
self.driver.quit()
with self.assertRaises(InvalidSessionIdException) as excinfo:
sleep(5)
# should not be able to use the driver anymore
with self.assertRaises(WebDriverException) as excinfo:
self.driver.title
self.assertEquals('A session is either terminated or not started', excinfo.exception.msg)
self.assertTrue('has already finished' in str(excinfo.exception.msg))