From d17450cfe99f626ed0f00a4a0c197d65ee143296 Mon Sep 17 00:00:00 2001 From: Aniket Sen Date: Sun, 18 Jun 2023 15:56:51 +0530 Subject: [PATCH 1/5] Update lambdatest.py changes for desired_capibilities in the latest selinium update --- lambdatest.py | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/lambdatest.py b/lambdatest.py index 76a5081..b984567 100644 --- a/lambdatest.py +++ b/lambdatest.py @@ -8,24 +8,25 @@ access_key = os.getenv("LT_ACCESS_KEY") # Replace the access key -class FirstSampleTest(unittest.TestCase): - # Generate capabilites from here: https://www.lambdatest.com/capabilities-generator/ - # setUp runs before each test case and - def setUp(self): - desired_caps = { - 'LT:Options': { - "build": "Python Demo", # Change your build name here - "name": "Python Demo Test", # Change your test name here - "platformName": "Windows 11", - "selenium_version": "4.0.0", - "console": 'true', # Enable or disable console logs - "network": 'true', # Enable or disable network logs - #Enable Smart UI Project - #"smartUI.project": "" - }, - "browserName": "firefox", - "browserVersion": "latest", - } +#paste your capibility options below + +options = ChromeOptions() +options.browser_version = "114.0" +options.platform_name = "macOS High Sierra" +lt_options = {} +lt_options["username"] = username +lt_options["accessKey"] = access_key +lt_options["video"] = True +lt_options["resolution"] = "1920x1080" +lt_options["network"] = True +lt_options["build"] = "test_build" +lt_options["project"] = "unit_testing" +lt_options["smartUI.project"] = "test" +lt_options["name"] = "basic_unit_selinium" +lt_options["w3c"] = True +lt_options["plugin"] = "python-python" +options.set_capability('LT:Options', lt_options) + # Steps to run Smart UI project (https://beta-smartui.lambdatest.com/) # Step - 1 : Change the hub URL to @beta-smartui-hub.lambdatest.com/wd/hub @@ -33,10 +34,9 @@ def setUp(self): # Step - 3 : Run "driver.execute_script("smartui.takeScreenshot")" command wherever you need to take a screenshot # Note: for additional capabilities navigate to https://www.lambdatest.com/support/docs/test-settings-options/ - self.driver = webdriver.Remote( - command_executor="http://{}:{}@hub.lambdatest.com/wd/hub".format( - username, access_key), - desired_capabilities=desired_caps) +driver = webdriver.Remote( + command_executor="http://{}:{}@beta-smartui-hub.lambdatest.com/wd/hub".format( + username, access_key),options=options) # tearDown runs after each test case @@ -90,4 +90,4 @@ def test_demo_site(self): if __name__ == "__main__": - unittest.main() \ No newline at end of file + unittest.main() From c81def1770a85a5cc944bd6c0d0d6777d448c657 Mon Sep 17 00:00:00 2001 From: Aniket Sen Date: Sun, 18 Jun 2023 15:59:35 +0530 Subject: [PATCH 2/5] Update lambdatest.py changes related to new selenium update in python --- lambdatest.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lambdatest.py b/lambdatest.py index b984567..0924160 100644 --- a/lambdatest.py +++ b/lambdatest.py @@ -3,6 +3,7 @@ import os from selenium import webdriver from selenium.webdriver.common.by import By +from selenium.webdriver.chrome.options import Options as ChromeOptions username = os.getenv("LT_USERNAME") # Replace the username access_key = os.getenv("LT_ACCESS_KEY") # Replace the access key @@ -35,7 +36,7 @@ # Note: for additional capabilities navigate to https://www.lambdatest.com/support/docs/test-settings-options/ driver = webdriver.Remote( - command_executor="http://{}:{}@beta-smartui-hub.lambdatest.com/wd/hub".format( + command_executor="http://{}:{}@hub.lambdatest.com/wd/hub".format( username, access_key),options=options) # tearDown runs after each test case From 8a9b1d85b7f7f1ed46680b4e809aa3241c1ead72 Mon Sep 17 00:00:00 2001 From: Aniket Sen Date: Sun, 18 Jun 2023 16:01:24 +0530 Subject: [PATCH 3/5] Update README.md --- README.md | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 378a9ba..835519b 100644 --- a/README.md +++ b/README.md @@ -81,15 +81,22 @@ Make sure you have your LambdaTest credentials with you to run test automation s **Step 4:** In the python script, you need to update your test capabilities. In this code, we are passing browser, browser version, and operating system information, along with LambdaTest Selenium grid capabilities via capabilities object. The capabilities object in the above code are defined as: - +You can change the desired capibilite's ```python -capabilities = { - "build": "your build name", - "name": "your test name", - "platformName": "Windows 10" - "browserName": "Chrome", - "browserVersion": "latest", -} +options = ChromeOptions() +options.browser_version = "114.0" +options.platform_name = "macOS High Sierra" +lt_options = {} +lt_options["video"] = True +lt_options["resolution"] = "1920x1080" +lt_options["network"] = True +lt_options["build"] = "test_build" +lt_options["project"] = "unit_testing" +lt_options["smartUI.project"] = "test" +lt_options["name"] = "basic_unit_selinium" +lt_options["w3c"] = True +lt_options["plugin"] = "python-python" +options.set_capability('LT:Options', lt_options) ``` You can generate capabilities for your test requirements with the help of our inbuilt [Desired Capability Generator](https://www.lambdatest.com/capabilities-generator/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample). From 1ef38cef0624ea9b967bc98ef55f0d61e39892d2 Mon Sep 17 00:00:00 2001 From: Aniket Sen Date: Sun, 18 Jun 2023 16:02:58 +0530 Subject: [PATCH 4/5] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 835519b..b4b8714 100644 --- a/README.md +++ b/README.md @@ -80,8 +80,8 @@ Make sure you have your LambdaTest credentials with you to run test automation s **Step 4:** In the python script, you need to update your test capabilities. In this code, we are passing browser, browser version, and operating system information, along with LambdaTest Selenium grid capabilities via capabilities object. -The capabilities object in the above code are defined as: -You can change the desired capibilite's +The capabilities in the below code are defined as: + ```python options = ChromeOptions() options.browser_version = "114.0" From dd8199699a26c5888752776c368f28b6e6c179c8 Mon Sep 17 00:00:00 2001 From: Aniket Sen Date: Fri, 1 Sep 2023 09:28:13 +0530 Subject: [PATCH 5/5] Update lambdatest.py --- lambdatest.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lambdatest.py b/lambdatest.py index 0924160..341f253 100644 --- a/lambdatest.py +++ b/lambdatest.py @@ -35,15 +35,9 @@ # Step - 3 : Run "driver.execute_script("smartui.takeScreenshot")" command wherever you need to take a screenshot # Note: for additional capabilities navigate to https://www.lambdatest.com/support/docs/test-settings-options/ -driver = webdriver.Remote( - command_executor="http://{}:{}@hub.lambdatest.com/wd/hub".format( - username, access_key),options=options) - -# tearDown runs after each test case - - - def tearDown(self): - self.driver.quit() +class FirstSampleTest(unittest.TestCase): + def setUp(self): + driver = webdriver.Remote(command_executor="http://{}:{}@hub.lambdatest.com/wd/hub".format(username, access_key),options=options) # """ You can write the test cases here """ def test_demo_site(self): @@ -88,7 +82,9 @@ def test_demo_site(self): print("Tests are run successfully!") else: driver.execute_script("lambda-status=failed") - +# tearDown runs after each test case + def tearDown(self): + self.driver.quit() if __name__ == "__main__": unittest.main()