diff --git a/README.md b/README.md index 378a9ba..b4b8714 100644 --- a/README.md +++ b/README.md @@ -80,16 +80,23 @@ 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: +The capabilities in the below code are defined as: ```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). diff --git a/lambdatest.py b/lambdatest.py index 76a5081..0924160 100644 --- a/lambdatest.py +++ b/lambdatest.py @@ -3,29 +3,31 @@ 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 -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 +35,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( +driver = webdriver.Remote( command_executor="http://{}:{}@hub.lambdatest.com/wd/hub".format( - username, access_key), - desired_capabilities=desired_caps) + username, access_key),options=options) # tearDown runs after each test case @@ -90,4 +91,4 @@ def test_demo_site(self): if __name__ == "__main__": - unittest.main() \ No newline at end of file + unittest.main()