|
| 1 | +from appium import webdriver |
| 2 | +from appium.webdriver.common.mobileby import MobileBy |
| 3 | +from selenium.webdriver.support.ui import WebDriverWait |
| 4 | +from selenium.webdriver.support import expected_conditions as EC |
| 5 | +from browserstack.local import Local |
| 6 | +import os |
| 7 | + |
| 8 | +userName = "BROWSERSTACK_USERNAME" |
| 9 | +accessKey = "BROWSERSTACK_ACCESS_KEY" |
| 10 | + |
| 11 | +desired_caps = { |
| 12 | + "build": "Python iOS Local", |
| 13 | + "realMobile": True, |
| 14 | + "device": "iPhone 7", |
| 15 | + "automationName": "XCUITest", |
| 16 | + "browserstack.local": True, |
| 17 | + "app": "bs://<hashed app-id>" |
| 18 | +} |
| 19 | + |
| 20 | +bs_local = None |
| 21 | + |
| 22 | +def start_local(): |
| 23 | + global bs_local |
| 24 | + bs_local = Local() |
| 25 | + bs_local_args = { "key": accessKey, "forcelocal": "true" } |
| 26 | + bs_local.start(**bs_local_args) |
| 27 | + |
| 28 | +def stop_local(): |
| 29 | + global bs_local |
| 30 | + bs_local.stop() |
| 31 | + |
| 32 | +def existence_lambda(s): |
| 33 | + result = s.find_element_by_accessibility_id("ResultBrowserStackLocal").get_attribute("value") |
| 34 | + return result and len(result) > 0 |
| 35 | + |
| 36 | +start_local() |
| 37 | +driver = webdriver.Remote("http://" + userName + ":" + accessKey + "@hub.browserstack.com/wd/hub", desired_caps) |
| 38 | + |
| 39 | +test_button = WebDriverWait(driver, 30).until( |
| 40 | + EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID, "TestBrowserStackLocal")) |
| 41 | +) |
| 42 | +test_button.click() |
| 43 | + |
| 44 | +WebDriverWait(driver, 30).until(existence_lambda) |
| 45 | +result_element = driver.find_element_by_accessibility_id("ResultBrowserStackLocal") |
| 46 | +result_string = result_element.text.lower() |
| 47 | + |
| 48 | +if result_string.__contains__("not working"): |
| 49 | + screenshot_file = "%s/screenshot.png" % os.getcwd() |
| 50 | + driver.save_screenshot(screenshot_file) |
| 51 | + print "Screenshot stored at %s" % screenshot_file |
| 52 | + print "Unexpected BrowserStackLocal test result" |
| 53 | +else: |
| 54 | + assert(result_string.__contains__("up and running")) |
| 55 | + |
| 56 | +driver.quit() |
| 57 | +stop_local() |
0 commit comments