Skip to content

Commit b154de8

Browse files
Add support for w3c session
1 parent a7e09fe commit b154de8

4 files changed

Lines changed: 51 additions & 58 deletions

File tree

android/browserstack_sample.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from appium import webdriver
22
from appium.options.android import UiAutomator2Options
3-
from appium.webdriver.common.mobileby import MobileBy
3+
from appium.webdriver.common.appiumby import AppiumBy
44
from selenium.webdriver.support.ui import WebDriverWait
55
from selenium.webdriver.support import expected_conditions as EC
66
import time
@@ -15,13 +15,13 @@
1515
"deviceName" : "Google Pixel 3",
1616

1717
# Set URL of the application under test
18-
"app" : "<bs://app-id>",
18+
"app" : "bs://<app-id>",
1919

2020
# Set other BrowserStack capabilities
2121
'bstack:options' : {
2222
"projectName" : "First Python project",
2323
"buildName" : "browserstack-build-1",
24-
"sessionName" : "first_test",
24+
"sessionName" : "BStack first_test",
2525

2626
# Set your access credentials
2727
"userName" : "YOUR_USERNAME",
@@ -30,22 +30,22 @@
3030
})
3131

3232
# Initialize the remote Webdriver using BrowserStack remote URL
33-
# and desired capabilities defined above
33+
# and options defined above
3434
driver = webdriver.Remote("http://hub-cloud.browserstack.com/wd/hub", options=options)
3535

3636
# Test case for the BrowserStack sample Android app.
3737
# If you have uploaded your app, update the test case here.
3838
search_element = WebDriverWait(driver, 30).until(
39-
EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID, "Search Wikipedia"))
39+
EC.element_to_be_clickable((AppiumBy.ACCESSIBILITY_ID, "Search Wikipedia"))
4040
)
4141
search_element.click()
4242
search_input = WebDriverWait(driver, 30).until(
4343
EC.element_to_be_clickable(
44-
(MobileBy.ID, "org.wikipedia.alpha:id/search_src_text"))
44+
(AppiumBy.ID, "org.wikipedia.alpha:id/search_src_text"))
4545
)
4646
search_input.send_keys("BrowserStack")
4747
time.sleep(5)
48-
search_results = driver.find_elements_by_class_name("android.widget.TextView")
48+
search_results = driver.find_elements(AppiumBy.CLASS_NAME, "android.widget.TextView")
4949
assert (len(search_results) > 0)
5050

5151
# Invoke driver.quit() after the test is done to indicate that the test is completed.

android/browserstack_sample_local.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from appium import webdriver
2-
from appium.webdriver.common.mobileby import MobileBy
2+
from appium.options.android import UiAutomator2Options
3+
from appium.webdriver.common.appiumby import AppiumBy
34
from selenium.webdriver.support.ui import WebDriverWait
45
from selenium.webdriver.support import expected_conditions as EC
56
from browserstack.local import Local
@@ -9,7 +10,10 @@
910
userName = "YOUR_USERNAME"
1011
accessKey = "YOUR_ACCESS_KEY"
1112

12-
desired_caps = {
13+
# Options are only available since client version 2.3.0
14+
# If you use an older client then switch to desired_capabilities
15+
# instead: https://github.com/appium/python-client/pull/720
16+
options = UiAutomator2Options().load_capabilities({
1317
# Set URL of the application under test
1418
"app" : "bs://<app-id>",
1519

@@ -18,21 +22,16 @@
1822
"platformName": "android",
1923
"platformVersion": "9.0",
2024

21-
# Set other BrowserStack capabilities
22-
"project" : "First Python Local project",
23-
"build" : "browserstack-build-1",
24-
"name" : "local_test",
25-
2625
# Set other BrowserStack capabilities
2726
"bstack:options": {
2827
"userName" : userName,
2928
"accessKey" : accessKey,
3029
"projectName" : "First Python Local project",
3130
"buildName" : "browserstack-build-1",
32-
"sessionName" : "local_test",
33-
"local" : True
31+
"sessionName" : "BStack local_test",
32+
"local" : "true"
3433
}
35-
}
34+
})
3635

3736
bs_local = None
3837

@@ -50,23 +49,20 @@ def stop_local():
5049
start_local()
5150

5251
# Initialize the remote Webdriver using BrowserStack remote URL
53-
# and desired capabilities defined above
54-
driver = webdriver.Remote(
55-
command_executor="http://hub-cloud.browserstack.com/wd/hub",
56-
desired_capabilities=desired_caps
57-
)
52+
# and options defined above
53+
driver = webdriver.Remote("http://hub-cloud.browserstack.com/wd/hub", options=options)
5854

5955
# Test case for the BrowserStack sample Android app.
6056
# If you have uploaded your app, update the test case here.
6157
test_button = WebDriverWait(driver, 30).until(
62-
EC.element_to_be_clickable((MobileBy.ID, "com.example.android.basicnetworking:id/test_action"))
58+
EC.element_to_be_clickable((AppiumBy.ID, "com.example.android.basicnetworking:id/test_action"))
6359
)
6460
test_button.click()
6561
WebDriverWait(driver, 30).until(
66-
EC.element_to_be_clickable((MobileBy.CLASS_NAME, "android.widget.TextView"))
62+
EC.element_to_be_clickable((AppiumBy.CLASS_NAME, "android.widget.TextView"))
6763
)
6864
test_element = None
69-
search_results = driver.find_elements_by_class_name("android.widget.TextView")
65+
search_results = driver.find_elements(AppiumBy.CLASS_NAME,"android.widget.TextView")
7066
for result in search_results:
7167
if result.text.__contains__("The active connection is"):
7268
test_element = result

ios/browserstack_sample.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
from appium import webdriver
2-
from appium.webdriver.common.mobileby import MobileBy
2+
from appium.options.ios import XCUITestOptions
3+
from appium.webdriver.common.appiumby import AppiumBy
34
from selenium.webdriver.support.ui import WebDriverWait
45
from selenium.webdriver.support import expected_conditions as EC
56
import time
67

7-
desired_cap = {
8+
# Options are only available since client version 2.3.0
9+
# If you use an older client then switch to desired_capabilities
10+
# instead: https://github.com/appium/python-client/pull/720
11+
options = XCUITestOptions().load_capabilities({
812
# Set URL of the application under test
913
"app" : "bs://<app-id>",
1014

@@ -19,30 +23,27 @@
1923
"accessKey" : "YOUR_ACCESS_KEY",
2024
"projectName" : "First Python project",
2125
"buildName" : "browserstack-build-1",
22-
"sessionName" : "first_test"
26+
"sessionName" : "BStack first_test"
2327
}
24-
}
28+
})
2529

2630
# Initialize the remote Webdriver using BrowserStack remote URL
27-
# and desired capabilities defined above
28-
driver = webdriver.Remote(
29-
command_executor="http://hub-cloud.browserstack.com/wd/hub",
30-
desired_capabilities=desired_cap
31-
)
31+
# and options defined above
32+
driver = webdriver.Remote("http://hub-cloud.browserstack.com/wd/hub", options=options)
3233

33-
# Test case for the BrowserStack sample Android app.
34+
# Test case for the BrowserStack sample iOS app.
3435
# If you have uploaded your app, update the test case here.
3536
text_button = WebDriverWait(driver, 30).until(
36-
EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID, "Text Button"))
37+
EC.element_to_be_clickable((AppiumBy.ACCESSIBILITY_ID, "Text Button"))
3738
)
3839
text_button.click()
3940
text_input = WebDriverWait(driver, 30).until(
40-
EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID, "Text Input"))
41+
EC.element_to_be_clickable((AppiumBy.ACCESSIBILITY_ID, "Text Input"))
4142
)
4243
text_input.send_keys("hello@browserstack.com"+"\n")
4344
time.sleep(5)
4445
text_output = WebDriverWait(driver, 30).until(
45-
EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID, "Text Output"))
46+
EC.element_to_be_clickable((AppiumBy.ACCESSIBILITY_ID, "Text Output"))
4647
)
4748
if text_output!=None and text_output.text=="hello@browserstack.com":
4849
assert True

ios/browserstack_sample_local.py

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from appium import webdriver
2-
from appium.webdriver.common.mobileby import MobileBy
2+
from appium.options.ios import XCUITestOptions
3+
from appium.webdriver.common.appiumby import AppiumBy
34
from selenium.webdriver.support.ui import WebDriverWait
45
from selenium.webdriver.support import expected_conditions as EC
56
from browserstack.local import Local
@@ -9,30 +10,28 @@
910
userName = "YOUR_USERNAME"
1011
accessKey = "YOUR_ACCESS_KEY"
1112

12-
desired_caps = {
13+
# Options are only available since client version 2.3.0
14+
# If you use an older client then switch to desired_capabilities
15+
# instead: https://github.com/appium/python-client/pull/720
16+
options = XCUITestOptions().load_capabilities({
1317
# Set URL of the application under test
1418
"app" : "bs://<app-id>",
1519

1620
# Specify device and os_version for testing
17-
"deviceName": "iPhone 11 Pro",
21+
"deviceName": "iPhone XS",
1822
"platformName": "ios",
19-
"platformVersion": "13",
20-
21-
# Set other BrowserStack capabilities
22-
"project" : "First Python Local project",
23-
"build" : "browserstack-build-1",
24-
"name" : "local_test",
23+
"platformVersion": "12",
2524

2625
# Set other BrowserStack capabilities
2726
"bstack:options": {
2827
"userName" : userName,
2928
"accessKey" : accessKey,
3029
"projectName" : "First Python Local project",
3130
"buildName" : "browserstack-build-1",
32-
"sessionName" : "local_test",
33-
"local" : True
31+
"sessionName" : "BStack first_test",
32+
"local" : "true"
3433
}
35-
}
34+
})
3635

3736
bs_local = None
3837

@@ -47,27 +46,24 @@ def stop_local():
4746
bs_local.stop()
4847

4948
def existence_lambda(s):
50-
result = s.find_element_by_accessibility_id("ResultBrowserStackLocal").get_attribute("value")
49+
result = s.find_element(AppiumBy.ACCESSIBILITY_ID, "ResultBrowserStackLocal").get_attribute("value")
5150
return result and len(result) > 0
5251

5352
# Start BrowserStack local binary
5453
start_local()
5554

5655
# Initialize the remote Webdriver using BrowserStack remote URL
57-
# and desired capabilities defined above
58-
driver = webdriver.Remote(
59-
command_executor="http://hub-cloud.browserstack.com/wd/hub",
60-
desired_capabilities=desired_caps
61-
)
56+
# and options defined above
57+
driver = webdriver.Remote("http://hub-cloud.browserstack.com/wd/hub", options=options)
6258

6359
# Test case for the BrowserStack sample iOS app.
6460
# If you have uploaded your app, update the test case here.
6561
test_button = WebDriverWait(driver, 30).until(
66-
EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID, "TestBrowserStackLocal"))
62+
EC.element_to_be_clickable((AppiumBy.ACCESSIBILITY_ID, "TestBrowserStackLocal"))
6763
)
6864
test_button.click()
6965
WebDriverWait(driver, 30).until(existence_lambda)
70-
result_element = driver.find_element_by_accessibility_id("ResultBrowserStackLocal")
66+
result_element = driver.find_element(AppiumBy.ACCESSIBILITY_ID, "ResultBrowserStackLocal")
7167
result_string = result_element.text.lower()
7268
if result_string.__contains__("not working"):
7369
screenshot_file = "%s/screenshot.png" % os.getcwd()

0 commit comments

Comments
 (0)