-
Notifications
You must be signed in to change notification settings - Fork 34
Update Appium Python Client to W3C standards #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Mahaklambda1811
wants to merge
2
commits into
LambdaTest:master
Choose a base branch
from
Mahaklambda1811:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,87 +1,99 @@ | ||||||
| from appium import webdriver | ||||||
| from appium.webdriver.common.mobileby import MobileBy | ||||||
| # FIXED: Changed MobileBy to AppiumBy | ||||||
| from appium.webdriver.common.appiumby import AppiumBy | ||||||
| from selenium.webdriver.support.ui import WebDriverWait | ||||||
| from selenium.webdriver.support import expected_conditions as EC | ||||||
| from appium.options.common import AppiumOptions | ||||||
| import time | ||||||
| import os | ||||||
|
|
||||||
| desired_caps = { | ||||||
| "deviceName": "Galaxy S20", | ||||||
| "platformName": "Android", | ||||||
| "platformVersion": "10", | ||||||
| "app": "lt://proverbial-android", # Enter app_url here | ||||||
| "isRealMobile": True, | ||||||
| "build": "Python Vanilla Android", | ||||||
| "name": "Sample Test - Python", | ||||||
| "network": False, | ||||||
| "visual": True, | ||||||
| "video": True | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| def startingTest(): | ||||||
| if os.environ.get("LT_USERNAME") is None: | ||||||
| # Enter LT username here if environment variables have not been added | ||||||
| username = "username" | ||||||
| else: | ||||||
| username = os.environ.get("LT_USERNAME") | ||||||
| if os.environ.get("LT_ACCESS_KEY") is None: | ||||||
| # Enter LT accesskey here if environment variables have not been added | ||||||
| accesskey = "accesskey" | ||||||
| else: | ||||||
| accesskey = os.environ.get("LT_ACCESS_KEY") | ||||||
|
|
||||||
| # Credentials | ||||||
| username = "##" | ||||||
| accesskey = "##" | ||||||
|
|
||||||
| # 1. Modern W3C Capabilities | ||||||
| options = AppiumOptions() | ||||||
| options.platform_name = "Android" | ||||||
|
|
||||||
| lt_options = { | ||||||
| "w3c": True, | ||||||
| "deviceName": "Galaxy S20", | ||||||
| "platformVersion": "10", | ||||||
| "isRealMobile": True, | ||||||
| "app": "lt://APP1016034271771502068985212", | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| "build": "Python Vanilla Android", | ||||||
| "name": "Sample Test - Python", | ||||||
| "network": True, | ||||||
| "visual": True, | ||||||
| "video": True | ||||||
| } | ||||||
| options.set_capability("lt:options", lt_options) | ||||||
|
|
||||||
| remote_url = f"https://{username}:{accesskey}@mobile-hub.lambdatest.com/wd/hub" | ||||||
|
|
||||||
| driver = None | ||||||
| try: | ||||||
| driver = webdriver.Remote(desired_capabilities=desired_caps, command_executor="https://" + | ||||||
| username+":"+accesskey+"@mobile-hub.lambdatest.com/wd/hub") | ||||||
| colorElement = WebDriverWait(driver, 20).until(EC.element_to_be_clickable( | ||||||
| (MobileBy.ID, "com.lambdatest.proverbial:id/color"))) | ||||||
| print("Initializing Android session on LambdaTest...") | ||||||
| driver = webdriver.Remote(command_executor=remote_url, options=options) | ||||||
|
|
||||||
| print("Session started. Running Android tests...") | ||||||
| wait = WebDriverWait(driver, 20) | ||||||
|
|
||||||
| # FIXED: Changed (MobileBy.ID, ...) to (AppiumBy.ID, ...) | ||||||
| colorElement = wait.until(EC.element_to_be_clickable( | ||||||
| (AppiumBy.ID, "com.lambdatest.proverbial:id/color"))) | ||||||
| colorElement.click() | ||||||
|
|
||||||
| textElement = WebDriverWait(driver, 20).until( | ||||||
| EC.element_to_be_clickable((MobileBy.ID, "com.lambdatest.proverbial:id/Text"))) | ||||||
| textElement = wait.until(EC.element_to_be_clickable( | ||||||
| (AppiumBy.ID, "com.lambdatest.proverbial:id/Text"))) | ||||||
| textElement.click() | ||||||
|
|
||||||
| toastElement = WebDriverWait(driver, 20).until(EC.element_to_be_clickable( | ||||||
| (MobileBy.ID, "com.lambdatest.proverbial:id/toast"))) | ||||||
| toastElement = wait.until(EC.element_to_be_clickable( | ||||||
| (AppiumBy.ID, "com.lambdatest.proverbial:id/toast"))) | ||||||
| toastElement.click() | ||||||
|
|
||||||
| notification = WebDriverWait(driver, 20).until(EC.element_to_be_clickable( | ||||||
| (MobileBy.ID, "com.lambdatest.proverbial:id/notification"))) | ||||||
| notification = wait.until(EC.element_to_be_clickable( | ||||||
| (AppiumBy.ID, "com.lambdatest.proverbial:id/notification"))) | ||||||
| notification.click() | ||||||
|
|
||||||
| geolocation = WebDriverWait(driver, 20).until(EC.element_to_be_clickable( | ||||||
| (MobileBy.ID, "com.lambdatest.proverbial:id/geoLocation"))) | ||||||
| geolocation = wait.until(EC.element_to_be_clickable( | ||||||
| (AppiumBy.ID, "com.lambdatest.proverbial:id/geoLocation"))) | ||||||
| geolocation.click() | ||||||
|
|
||||||
| time.sleep(5) | ||||||
|
|
||||||
| driver.back() | ||||||
|
|
||||||
| home = WebDriverWait(driver, 20).until(EC.element_to_be_clickable( | ||||||
| (MobileBy.ID, "com.lambdatest.proverbial:id/buttonPage"))) | ||||||
| home = wait.until(EC.element_to_be_clickable( | ||||||
| (AppiumBy.ID, "com.lambdatest.proverbial:id/buttonPage"))) | ||||||
| home.click() | ||||||
|
|
||||||
| speedTest = WebDriverWait(driver, 20).until(EC.element_to_be_clickable( | ||||||
| (MobileBy.ID, "com.lambdatest.proverbial:id/speedTest"))) | ||||||
| speedTest = wait.until(EC.element_to_be_clickable( | ||||||
| (AppiumBy.ID, "com.lambdatest.proverbial:id/speedTest"))) | ||||||
| speedTest.click() | ||||||
|
|
||||||
| time.sleep(5) | ||||||
|
|
||||||
| driver.back() | ||||||
|
|
||||||
| browser = WebDriverWait(driver, 20).until(EC.element_to_be_clickable( | ||||||
| (MobileBy.ID, "com.lambdatest.proverbial:id/webview"))) | ||||||
| browser = wait.until(EC.element_to_be_clickable( | ||||||
| (AppiumBy.ID, "com.lambdatest.proverbial:id/webview"))) | ||||||
| browser.click() | ||||||
|
|
||||||
| url = WebDriverWait(driver, 20).until(EC.element_to_be_clickable( | ||||||
| (MobileBy.ID, "com.lambdatest.proverbial:id/url"))) | ||||||
| url.send_keys("https://www.lambdatest.com") | ||||||
| url_field = wait.until(EC.element_to_be_clickable( | ||||||
| (AppiumBy.ID, "com.lambdatest.proverbial:id/url"))) | ||||||
| url_field.send_keys("https://www.lambdatest.com") | ||||||
|
|
||||||
| find = WebDriverWait(driver, 20).until(EC.element_to_be_clickable( | ||||||
| (MobileBy.ID, "com.lambdatest.proverbial:id/find"))) | ||||||
| find.click() | ||||||
| driver.quit() | ||||||
| except: | ||||||
| driver.quit() | ||||||
| find_btn = wait.until(EC.element_to_be_clickable( | ||||||
| (AppiumBy.ID, "com.lambdatest.proverbial:id/find"))) | ||||||
| find_btn.click() | ||||||
|
|
||||||
| print("Android test completed successfully!") | ||||||
|
|
||||||
| except Exception as e: | ||||||
| print(f"Test failed with error: {e}") | ||||||
| finally: | ||||||
| if driver: | ||||||
| driver.quit() | ||||||
|
|
||||||
| startingTest() | ||||||
| if __name__ == "__main__": | ||||||
| startingTest() | ||||||
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,62 +1,71 @@ | ||
| from appium import webdriver | ||
| from appium.webdriver.common.mobileby import By | ||
| # For Web tests, we use the standard Selenium 'By' | ||
| from selenium.webdriver.common.by import By | ||
| from selenium.webdriver.support.ui import WebDriverWait | ||
| from selenium.webdriver.support import expected_conditions as EC | ||
| from appium.options.common import AppiumOptions | ||
| import time | ||
| import os | ||
|
|
||
| desired_caps = { | ||
| "deviceName": "Galaxy .*", | ||
| "platformName": "Android", | ||
| "platformVersion": "10", | ||
| "isRealMobile": True, | ||
| "build": "Python Vanilla Android", | ||
| "name": "Sample Test - Python", | ||
| "network": False, | ||
| "visual": True, | ||
| "video": True | ||
| } | ||
|
|
||
|
|
||
| def startingTest(): | ||
| # Credentials | ||
| username = "LT_Username" | ||
| accesskey = "LT_ACCESS_KEY" | ||
|
|
||
| # 1. Modern W3C Capabilities for Mobile Web | ||
| options = AppiumOptions() | ||
| options.platform_name = "Android" | ||
|
|
||
| lt_options = { | ||
| "w3c": True, | ||
| "deviceName": "Galaxy .*", | ||
| "platformVersion": "11", | ||
| "isRealMobile": True, | ||
| "browserName": "Chrome", | ||
| "build": "Python Vanilla Android Web", | ||
| "name": "Sample Web Test - Python", | ||
| "network": True, | ||
| "visual": True, | ||
| "video": True | ||
| } | ||
| options.set_capability("lt:options", lt_options) | ||
|
|
||
| if os.environ.get("LT_USERNAME") is None: | ||
| # Enter LT username here if environment variables have not been added | ||
| username = "username" | ||
| else: | ||
| username = os.environ.get("LT_USERNAME") | ||
| if os.environ.get("LT_ACCESS_KEY") is None: | ||
| # Enter LT accesskey here if environment variables have not been added | ||
| accesskey = "accesskey" | ||
| else: | ||
| accesskey = os.environ.get("LT_ACCESS_KEY") | ||
| remote_url = f"https://{username}:{accesskey}@mobile-hub.lambdatest.com/wd/hub" | ||
|
|
||
| driver = None | ||
| try: | ||
| driver = webdriver.Remote(desired_capabilities=desired_caps, command_executor="https://" + | ||
| username+":"+accesskey+"@mobile-hub.lambdatest.com/wd/hub") | ||
|
|
||
| print("Initializing Android Web session on LambdaTest...") | ||
| driver = webdriver.Remote(command_executor=remote_url, options=options) | ||
|
|
||
| print("Opening URL: https://mfml.in/api/getInfo") | ||
| driver.get("https://mfml.in/api/getInfo") | ||
| colorElement = WebDriverWait(driver, 30).until(EC.element_to_be_clickable( | ||
| (By.ID, "resolution"))) | ||
|
|
||
| wait = WebDriverWait(driver, 30) | ||
|
|
||
| # 2. Fixed Element Locators (using standard By.ID) | ||
| print("Interacting with page elements...") | ||
|
|
||
| colorElement = wait.until(EC.element_to_be_clickable((By.ID, "resolution"))) | ||
| colorElement.click() | ||
|
|
||
| textElement = WebDriverWait(driver, 30).until( | ||
| EC.element_to_be_clickable((By.ID, "location"))) | ||
| textElement = wait.until(EC.element_to_be_clickable((By.ID, "location"))) | ||
| textElement.click() | ||
|
|
||
| toastElement = WebDriverWait(driver, 30).until(EC.element_to_be_clickable( | ||
| (By.ID, "details"))) | ||
| toastElement = wait.until(EC.element_to_be_clickable((By.ID, "details"))) | ||
| toastElement.click() | ||
|
|
||
| notification = WebDriverWait(driver, 30).until(EC.element_to_be_clickable( | ||
| (By.ID, "timezone"))) | ||
| notification = wait.until(EC.element_to_be_clickable((By.ID, "timezone"))) | ||
| notification.click() | ||
|
|
||
| time.sleep(5) | ||
| print("Web test completed successfully!") | ||
|
|
||
| driver.quit() | ||
| except: | ||
| driver.quit() | ||
|
|
||
| except Exception as e: | ||
| print(f"Test failed with error: {e}") | ||
| finally: | ||
| if driver: | ||
| print("Closing session...") | ||
| driver.quit() | ||
|
|
||
| startingTest() | ||
| if __name__ == "__main__": | ||
| startingTest() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the Readme.md as well