Skip to content

Commit

Permalink
Moving to options and using find_element
Browse files Browse the repository at this point in the history
  • Loading branch information
diemol committed Jan 30, 2025
1 parent 58d26a7 commit cab115b
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 35 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/mobile_native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ jobs:
python-tests:
name: Tests
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
test: [ best-practice-mobile-native-us-android, best-practice-mobile-native-us-ios]
steps:
- uses: actions/checkout@v4
- name: Setup Python
Expand All @@ -19,8 +22,8 @@ jobs:
uses: dschep/install-pipenv-action@v1
- name: Install dependencies
run: pipenv install
- name: Run Desktop Best Practice Tests
- name: Run RDC Mobile Tests
env:
SAUCE_USERNAME: ${{ secrets.SAUCE_USERNAME }}
SAUCE_ACCESS_KEY: ${{ secrets.SAUCE_ACCESS_KEY }}
run: pipenv run best-practice-mobile-native-us-android
run: pipenv run ${{ matrix.test }}
40 changes: 24 additions & 16 deletions best_practice/conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import pytest
from os import environ

from appium.options.android import UiAutomator2Options
from appium.options.ios import XCUITestOptions
from selenium import webdriver
from appium import webdriver as appiumdriver
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.remote.client_config import ClientConfig

import urllib3

urllib3.disable_warnings()

emusim_browsers = [
Expand Down Expand Up @@ -190,23 +194,25 @@ def android_rdc_driver(request, data_center):

username_cap = environ['SAUCE_USERNAME']
access_key_cap = environ['SAUCE_ACCESS_KEY']

caps = {

options = UiAutomator2Options()
options.platform_name = 'Android'
options.device_name = 'Google.*'
options.app = 'https://github.com/saucelabs/sample-app-mobile/releases/download/2.7.1/Android.SauceLabs.Mobile.Sample.app.2.7.1.apk'
sauce_options = {
'username': username_cap,
'accessKey': access_key_cap,
'deviceName': 'Google.*',
'platformName': 'Android',
'build': 'RDC-Android-Python-Best-Practice',
'name': request.node.name,
'app': "https://github.com/saucelabs/sample-app-mobile/releases/download/2.7.1/Android.SauceLabs.Mobile.Sample.app.2.7.1.apk"
}
options.set_capability('sauce:options', sauce_options)

if data_center and data_center.lower() == 'eu':
sauce_url = 'http://ondemand.eu-central-1.saucelabs.com/wd/hub'
sauce_url = 'https://ondemand.eu-central-1.saucelabs.com/wd/hub'
else:
sauce_url = 'http://ondemand.us-west-1.saucelabs.com/wd/hub'
sauce_url = 'https://ondemand.us-west-1.saucelabs.com/wd/hub'

driver = appiumdriver.Remote(sauce_url, desired_capabilities=caps)
driver = appiumdriver.Remote(sauce_url, options=options)
yield driver
sauce_result = "failed" if request.node.rep_call.failed else "passed"
driver.execute_script("sauce:job-result={}".format(sauce_result))
Expand All @@ -217,23 +223,25 @@ def ios_rdc_driver(request, data_center):

username_cap = environ['SAUCE_USERNAME']
access_key_cap = environ['SAUCE_ACCESS_KEY']

caps = {

options = XCUITestOptions()
options.platform_name = 'iOS'
options.device_name = 'iPhone.*'
options.app = 'https://github.com/saucelabs/sample-app-mobile/releases/download/2.7.1/iOS.RealDevice.SauceLabs.Mobile.Sample.app.2.7.1.ipa'
sauce_options = {
'username': username_cap,
'accessKey': access_key_cap,
'deviceName': 'iPhone.*',
'platformName': 'iOS',
'build': 'RDC-iOS-Python-Best-Practice',
'name': request.node.name,
'app': 'https://github.com/saucelabs/sample-app-mobile/releases/download/2.7.1/iOS.RealDevice.SauceLabs.Mobile.Sample.app.2.7.1.ipa'
}
options.set_capability('sauce:options', sauce_options)

if data_center and data_center.lower() == 'eu':
sauce_url = "http://ondemand.eu-central-1.saucelabs.com/wd/hub"
sauce_url = "https://ondemand.eu-central-1.saucelabs.com/wd/hub"
else:
sauce_url = "http://ondemand.us-west-1.saucelabs.com/wd/hub"
sauce_url = "https://ondemand.us-west-1.saucelabs.com/wd/hub"

driver = appiumdriver.Remote(sauce_url, desired_capabilities=caps)
driver = appiumdriver.Remote(sauce_url, options=options)
yield driver
sauce_result = "failed" if request.node.rep_call.failed else "passed"
driver.execute_script("sauce:job-result={}".format(sauce_result))
Expand Down
11 changes: 7 additions & 4 deletions best_practice/mobile_native/android/test_invald_login.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from appium.webdriver.common.appiumby import AppiumBy


def test_blank_credentials(android_rdc_driver):
android_rdc_driver.find_element_by_accessibility_id("test-Username").send_keys("")
android_rdc_driver.find_element_by_accessibility_id("test-Password").send_keys("")
android_rdc_driver.find_element_by_accessibility_id("test-LOGIN").click()
android_rdc_driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='test-Username').send_keys("")
android_rdc_driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='test-Password').send_keys("")
android_rdc_driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='test-LOGIN').click()

assert android_rdc_driver.find_element_by_accessibility_id("test-Error message").is_displayed()
assert android_rdc_driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='test-Error message').is_displayed()
11 changes: 7 additions & 4 deletions best_practice/mobile_native/android/test_valid_login.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from appium.webdriver.common.appiumby import AppiumBy


def test_standard_user(android_rdc_driver):
android_rdc_driver.find_element_by_accessibility_id("test-Username").send_keys("standard_user")
android_rdc_driver.find_element_by_accessibility_id("test-Password").send_keys("secret_sauce")
android_rdc_driver.find_element_by_accessibility_id("test-LOGIN").click()
android_rdc_driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='test-Username').send_keys("standard_user")
android_rdc_driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='test-Password').send_keys("secret_sauce")
android_rdc_driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='test-LOGIN').click()

assert android_rdc_driver.find_element_by_accessibility_id("test-PRODUCTS").is_displayed()
assert android_rdc_driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='test-PRODUCTS').is_displayed()
11 changes: 7 additions & 4 deletions best_practice/mobile_native/ios/test_invald_login.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from appium.webdriver.common.appiumby import AppiumBy


def test_blank_credentials(ios_rdc_driver):
ios_rdc_driver.find_element_by_accessibility_id("test-Username").send_keys("")
ios_rdc_driver.find_element_by_accessibility_id("test-Password").send_keys("")
ios_rdc_driver.find_element_by_accessibility_id("test-LOGIN").click()
ios_rdc_driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='test-Username').send_keys("")
ios_rdc_driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='test-Password').send_keys("")
ios_rdc_driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='test-LOGIN').click()

assert ios_rdc_driver.find_element_by_accessibility_id("test-Error message").is_displayed()
assert ios_rdc_driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='test-Error message').is_displayed()
11 changes: 7 additions & 4 deletions best_practice/mobile_native/ios/test_valid_login.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from appium.webdriver.common.appiumby import AppiumBy


def test_standard_user(ios_rdc_driver):
ios_rdc_driver.find_element_by_accessibility_id("test-Username").send_keys("standard_user")
ios_rdc_driver.find_element_by_accessibility_id("test-Password").send_keys("secret_sauce")
ios_rdc_driver.find_element_by_accessibility_id("test-LOGIN").click()
ios_rdc_driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='test-Username').send_keys("standard_user")
ios_rdc_driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='test-Password').send_keys("secret_sauce")
ios_rdc_driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='test-LOGIN').click()

assert ios_rdc_driver.find_element_by_accessibility_id("test-PRODUCTS").is_displayed()
assert ios_rdc_driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='test-PRODUCTS').is_displayed()

0 comments on commit cab115b

Please sign in to comment.