├── .gitpod.yml ├── README.md ├── lambdatest.py ├── requirements.txt └── selenium-3 ├── README.md ├── lambdatest.py └── requirements.txt /.gitpod.yml: -------------------------------------------------------------------------------- 1 | # List the start up tasks. Learn more https://www.gitpod.io/docs/config-start-tasks/ 2 | tasks: 3 | - init: pip install -r requirements.txt && export PYTHONWARNINGS="ignore:Unverified HTTPS request" # runs during prebuild 4 | command: python lambdatest.py 5 | 6 | 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Run Selenium Tests With Python On LambdaTest 2 | 3 | ![171934563-4806efd2-1154-494c-a01d-1def95657383 (1)](https://user-images.githubusercontent.com/70570645/172273386-fa9606ac-3e63-4b2e-8978-3142add3e038.png) 4 | 5 | 6 |

7 | Blog 8 |   ⋅   9 | Docs 10 |   ⋅   11 | Learning Hub 12 |   ⋅   13 | Newsletter 14 |   ⋅   15 | Certifications 16 |   ⋅   17 | YouTube 18 |

19 |   20 |   21 |   22 | 23 | *Learn how to run your Python automation testing scripts on the LambdaTest platform* 24 | 25 | [](https://accounts.lambdatest.com/register) 26 | 27 | 28 | ## Table Of Contents 29 | 30 | * [Pre-requisites](#pre-requisites) 31 | * [Run Your First Test](#run-your-first-test) 32 | * [Local Testing With Python](#testing-locally-hosted-or-privately-hosted-projects) 33 | 34 | ## Prerequisites 35 | 36 | Before you can start performing **Python** automation testing with **Selenium**, you would need to: 37 | 38 | * Install the latest Python build from the [official website](https://www.python.org/downloads/). We recommend using the latest version. 39 | * Make sure **pip** is installed in your system. You can install **pip** from [here](https://pip.pypa.io/en/stable/installation/). 40 | * Download the latest **Selenium Client** and its **WebDriver bindings** from the [official website](https://www.selenium.dev/downloads/). Latest versions of **Selenium Client** and **WebDriver** are ideal for running your automation script on LambdaTest Selenium cloud grid. 41 | 42 | ### Installing Selenium Dependencies And Tutorial Repo 43 | 44 | **Step 1:** Clone the LambdaTest’s python-selenium-sample repository and navigate to the code directory as shown below: 45 | 46 | ```bash 47 | git clone https://github.com/LambdaTest/python-selenium-sample 48 | cd python-selenium-sample 49 | ``` 50 | 51 | **Step 2:** Download the driver from the link, or you can use **pip** to install it. 52 | ```bash 53 | pip install -r requirements.txt 54 | export PYTHONWARNINGS="ignore:Unverified HTTPS request" //Disable ssl warning 55 | ``` 56 | 57 | ### Setting Up Your Authentication 58 | 59 | Make sure you have your LambdaTest credentials with you to run test automation scripts. You can get these credentials from the [LambdaTest Automation Dashboard](https://automation.lambdatest.com/build/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) or by your [LambdaTest Profile](https://accounts.lambdatest.com/login/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample). 60 | 61 | **Step 2:** Set LambdaTest **Username** and **Access Key** in environment variables. 62 | 63 | * For **Linux/macOS**: 64 | 65 | ```bash 66 | export LT_USERNAME="YOUR_USERNAME" 67 | export LT_ACCESS_KEY="YOUR ACCESS KEY" 68 | ``` 69 | * For **Windows**: 70 | ```bash 71 | set LT_USERNAME="YOUR_USERNAME" 72 | set LT_ACCESS_KEY="YOUR ACCESS KEY" 73 | ``` 74 | 75 | ## Run Your First Test 76 | 77 | >**Test Scenario**: The [lambdatest.py](https://github.com/LambdaTest/python-selenium-sample/blob/master/lambdatest.py) sample script tests a simple to-do application with basic functionalities like mark items as done, add items in a list, calculate total pending items etc. 78 | 79 | ### Configuration Of Your Test Capabilities 80 | 81 | **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. 82 | 83 | The capabilities in the below code are defined as: 84 | 85 | ```python 86 | options = ChromeOptions() 87 | options.browser_version = "latest" 88 | options.platform_name = "macOS High Sierra" 89 | lt_options = {} 90 | lt_options["video"] = True 91 | lt_options["resolution"] = "1920x1080" 92 | lt_options["network"] = True 93 | lt_options["build"] = "test_build" 94 | lt_options["project"] = "unit_testing" 95 | lt_options["smartUI.project"] = "test" 96 | lt_options["name"] = "basic_unit_selinium" 97 | lt_options["w3c"] = True 98 | lt_options["plugin"] = "python-python" 99 | options.set_capability('LT:Options', lt_options) 100 | ``` 101 | 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). 102 | 103 | ### Executing The Test 104 | 105 | **Step 5:** You would need to execute the below command in your terminal/cmd. 106 | 107 | ```bash 108 | python lambdatest.py 109 | ``` 110 | For python3 use 111 | ```bash 112 | python3 lambdatest.py 113 | ``` 114 | 115 | Your test results would be displayed on the test console (or command-line interface if you are using terminal/cmd) and on LambdaTest automation dashboard. 116 | 117 | 118 | ## Testing Locally Hosted Or Privately Hosted Projects 119 | 120 | You can test your locally hosted or privately hosted projects with LambdaTest Selenium grid using LambdaTest Tunnel. All you would have to do is set up an SSH tunnel using tunnel and pass toggle `tunnel = True` via desired capabilities. LambdaTest Tunnel establishes a secure SSH protocol based tunnel that allows you in testing your locally hosted or privately hosted pages, even before they are live. 121 | 122 | Refer our [LambdaTest Tunnel documentation](https://www.lambdatest.com/support/docs/testing-locally-hosted-pages/) for more information. 123 | 124 | Here’s how you can establish LambdaTest Tunnel. 125 | 126 | Download the binary file of: 127 | * [LambdaTest Tunnel for Windows](https://downloads.lambdatest.com/tunnel/v3/windows/64bit/LT_Windows.zip) 128 | * [LambdaTest Tunnel for macOS](https://downloads.lambdatest.com/tunnel/v3/mac/64bit/LT_Mac.zip) 129 | * [LambdaTest Tunnel for Linux](https://downloads.lambdatest.com/tunnel/v3/linux/64bit/LT_Linux.zip) 130 | 131 | Open command prompt and navigate to the binary folder. 132 | 133 | Run the following command: 134 | 135 | ```bash 136 | LT -user {user’s login email} -key {user’s access key} 137 | ``` 138 | So if your user name is lambdatest@example.com and key is 123456, the command would be: 139 | 140 | ```bash 141 | LT -user lambdatest@example.com -key 123456 142 | ``` 143 | Once you are able to connect **LambdaTest Tunnel** successfully, you would just have to pass on tunnel capabilities in the code shown below : 144 | 145 | **Tunnel Capability** 146 | 147 | ``` 148 | "tunnel" : true 149 | ``` 150 | 151 | ## Tutorials 📙 152 | 153 | Check out our latest tutorials on Python automation testing 👇 154 | 155 | * [Why Python Is A Preferred Language For Test Automation?](https://www.lambdatest.com/blog/python-automation-testing/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 156 | * [7 Best Python Testing Frameworks](https://www.lambdatest.com/blog/top-python-frameworks-in-2020-for-selenium-test-automation/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 157 | * [Selenium 4 With Python: All You Need To Know](https://www.lambdatest.com/blog/selenium-with-python/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 158 | * [How to Set Up Selenium With Python for Modern Web Automation](https://www.lambdatest.com/blog/selenium-webdriver-with-python/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 159 | * [Using Selenium and Python Hypothesis for Automation Testing](https://www.lambdatest.com/blog/using-selenium-and-python-hypothesis-for-automation-testing/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 160 | * [Selenium Python Tutorial: Getting Started With BDD In Behave](https://www.lambdatest.com/blog/selenium-python-behave-tutorial-bdd/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 161 | * [Selenium Python Tutorial: Getting Started With Pytest](https://www.lambdatest.com/blog/selenium-python-pytest-testing-tutorial/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 162 | * [Selenium Python Tutorial: Running First PyUnit Script](https://www.lambdatest.com/blog/using-pyunit-for-testing-a-selenium-python-test-suite/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 163 | * [Robot Framework with Selenium and Python](https://www.lambdatest.com/blog/robot-framework-tutorial/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 164 | * [Getting Started With Selenium Python [Tutorial]](https://www.lambdatest.com/blog/robot-framework-tutorial/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 165 | * [Running Python Selenium Test in Parallel With PyTest](https://www.lambdatest.com/blog/robot-framework-tutorial/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 166 | * [Parallel Testing In Selenium WebDriver With Python Using Unittest](https://www.lambdatest.com/blog/robot-framework-tutorial/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 167 | * [Automated Browser Testing with Opera and Selenium in Python](https://www.lambdatest.com/blog/automated-browser-testing-with-opera-and-selenium-in-python/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 168 | * [How To Take A Screenshot Using Python & Selenium?](https://www.lambdatest.com/blog/python-selenium-screenshots/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 169 | * [How To Drag And Drop In Selenium With Python?](https://www.lambdatest.com/blog/drag-and-drop-in-selenium-python/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 170 | * [How To Switch Tabs In A Browser Using Selenium Python?](https://www.lambdatest.com/blog/python-selenium-switch-tabs/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 171 | * [How To Get Page Source In Selenium Using Python?](https://www.lambdatest.com/blog/how-to-get-page-source-in-selenium-webdriver/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 172 | * [How To Handle Dropdowns In Selenium WebDriver Using [Python?]](https://www.lambdatest.com/blog/handling-dropdown-in-selenium-webdriver-python/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 173 | * [How To Do Parameterization In Pytest With Selenium?](https://www.lambdatest.com/blog/parameterization-in-pytest-with-selenium/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 174 | * [Page Object Model (POM) In Selenium Python](https://www.lambdatest.com/blog/page-object-model-in-selenium-python/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 175 | * [How To Read Configuration Files in Python Using Selenium](https://www.lambdatest.com/blog/how-to-read-configuration-files-in-python-using-selenium/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 176 | * [How To Create an Automated Web Bot With Selenium in Python?](https://www.lambdatest.com/blog/automated-web-bot-with-selenium-python/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 177 | * [How To Perform Web Scraping Using Selenium and Python?](https://www.lambdatest.com/blog/web-scraping-using-selenium-and-python/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 178 | * [Adding Firefox Extensions With Selenium in Python](https://www.lambdatest.com/blog/adding-firefox-extensions-with-selenium-in-python/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 179 | * [How to Handle JavaScript Alert in Selenium WebDriver Using Python?](https://www.lambdatest.com/blog/how-to-handle-javascript-alert-in-selenium-webdriver/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 180 | * [Use Selenium Wait for Page to Load With Python](https://www.lambdatest.com/blog/selenium-wait-for-page-to-load/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 181 | * [Selenium Python Cheat Sheet for Test Automation](https://www.lambdatest.com/blog/selenium-python-cheat-sheet/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 182 | 183 | 184 | ## Documentation & Resources :books: 185 | 186 | 187 | Visit the following links to learn more about LambdaTest's features, setup and tutorials around test automation, mobile app testing, responsive testing, and manual testing. 188 | 189 | * [LambdaTest Documentation](https://www.lambdatest.com/support/docs/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 190 | * [LambdaTest Blog](https://www.lambdatest.com/blog/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 191 | * [LambdaTest Learning Hub](https://www.lambdatest.com/learning-hub/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 192 | 193 | ## LambdaTest Community :busts_in_silhouette: 194 | 195 | The [LambdaTest Community](https://community.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) allows people to interact with tech enthusiasts. Connect, ask questions, and learn from tech-savvy people. Discuss best practises in web development, testing, and DevOps with professionals from across the globe 🌎 196 | 197 | ## What's New At LambdaTest ❓ 198 | 199 | To stay updated with the latest features and product add-ons, visit [Changelog](https://changelog.lambdatest.com/) 200 | 201 | ## About LambdaTest 202 | 203 | [LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) is a leading test execution and orchestration platform that is fast, reliable, scalable, and secure. It allows users to run both manual and automated testing of web and mobile apps across 3000+ different browsers, operating systems, and real device combinations. Using LambdaTest, businesses can ensure quicker developer feedback and hence achieve faster go to market. Over 500 enterprises and 1 Million + users across 130+ countries rely on LambdaTest for their testing needs. 204 | 205 | ### Features 206 | 207 | * Run Selenium, Cypress, Puppeteer, Playwright, and Appium automation tests across 3000+ real desktop and mobile environments. 208 | * Real-time cross browser testing on 3000+ environments. 209 | * Test on Real device cloud 210 | * Blazing fast test automation with HyperExecute 211 | * Accelerate testing, shorten job times and get faster feedback on code changes with Test At Scale. 212 | * Smart Visual Regression Testing on cloud 213 | * 120+ third-party integrations with your favorite tool for CI/CD, Project Management, Codeless Automation, and more. 214 | * Automated Screenshot testing across multiple browsers in a single click. 215 | * Local testing of web and mobile apps. 216 | * Online Accessibility Testing across 3000+ desktop and mobile browsers, browser versions, and operating systems. 217 | * Geolocation testing of web and mobile apps across 53+ countries. 218 | * LT Browser - for responsive testing across 50+ pre-installed mobile, tablets, desktop, and laptop viewports 219 | 220 | 221 | [](https://accounts.lambdatest.com/register) 222 | 223 | 224 | 225 | ## We are here to help you :headphones: 226 | 227 | * Got a query? we are available 24x7 to help. [Contact Us](support@lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 228 | * For more info, visit - [LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 229 | 230 | -------------------------------------------------------------------------------- /lambdatest.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import os 3 | from selenium import webdriver 4 | from selenium.webdriver.common.by import By 5 | from selenium.webdriver.chrome.options import Options as ChromeOptions 6 | 7 | username = os.getenv("LT_USERNAME") # Replace the username 8 | access_key = os.getenv("LT_ACCESS_KEY") # Replace the access key 9 | 10 | 11 | # paste your capibility options below 12 | 13 | options = ChromeOptions() 14 | options.browser_version = "latest" 15 | options.platform_name = "Windows 10" 16 | lt_options = {} 17 | lt_options["username"] = username 18 | lt_options["accessKey"] = access_key 19 | # lt_options["video"] = True 20 | # lt_options["resolution"] = "1920x1080" 21 | lt_options["network"] = True 22 | lt_options["build"] = "Selenium 4 Example" 23 | # lt_options["project"] = "unit_testing" 24 | lt_options["smartUI.project"] = "test" 25 | lt_options["name"] = "Selenium 4 Sample Test" 26 | lt_options["w3c"] = True 27 | lt_options["plugin"] = "python-python" 28 | options.set_capability("LT:Options", lt_options) 29 | 30 | 31 | # Steps to run Smart UI project (https://beta-smartui.lambdatest.com/) 32 | # Step - 1 : Change the hub URL to @beta-smartui-hub.lambdatest.com/wd/hub 33 | # Step - 2 : Add "smartUI.project": "" as a capability above 34 | # Step - 3 : Run "driver.execute_script("smartui.takeScreenshot")" command wherever you need to take a screenshot 35 | # Note: for additional capabilities navigate to https://www.lambdatest.com/support/docs/test-settings-options/ 36 | 37 | 38 | class FirstSampleTest(unittest.TestCase): 39 | driver = None 40 | 41 | def setUp(self): 42 | self.driver = webdriver.Remote( 43 | command_executor="http://{}:{}@hub.lambdatest.com/wd/hub".format( 44 | username, access_key 45 | ), 46 | options=options, 47 | ) 48 | 49 | # """ You can write the test cases here """ 50 | def test_demo_site(self): 51 | # try: 52 | driver = self.driver 53 | driver.implicitly_wait(10) 54 | driver.set_page_load_timeout(30) 55 | driver.set_window_size(1920, 1080) 56 | 57 | # Url 58 | print("Loading URL") 59 | driver.get( 60 | "https://stage-lambda-devops-use-only.lambdatestinternal.com/To-do-app/index.html" 61 | ) 62 | 63 | # Let's click on a element 64 | driver.find_element(By.NAME, "li1").click() 65 | location = driver.find_element(By.NAME, "li2") 66 | location.click() 67 | print("Clicked on the second element") 68 | 69 | # Take Smart UI screenshot 70 | # driver.execute_script("smartui.takeScreenshot") 71 | 72 | # Let's add a checkbox 73 | driver.find_element(By.ID, "sampletodotext").send_keys("LambdaTest") 74 | add_button = driver.find_element(By.ID, "addbutton") 75 | add_button.click() 76 | print("Added LambdaTest checkbox") 77 | 78 | # print the heading 79 | search = driver.find_element(By.CSS_SELECTOR, ".container h2") 80 | assert search.is_displayed(), "heading is not displayed" 81 | print(search.text) 82 | search.click() 83 | driver.implicitly_wait(3) 84 | 85 | # Let's download the invoice 86 | heading = driver.find_element(By.CSS_SELECTOR, ".container h2") 87 | if heading.is_displayed(): 88 | heading.click() 89 | driver.execute_script("lambda-status=passed") 90 | print("Tests are run successfully!") 91 | else: 92 | driver.execute_script("lambda-status=failed") 93 | 94 | # tearDown runs after each test case 95 | def tearDown(self): 96 | self.driver.quit() 97 | 98 | 99 | if __name__ == "__main__": 100 | unittest.main() 101 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | urllib3==1.26.5 2 | selenium==4.25.0 -------------------------------------------------------------------------------- /selenium-3/README.md: -------------------------------------------------------------------------------- 1 | # Run Selenium Tests With Python On LambdaTest 2 | 3 | ![171934563-4806efd2-1154-494c-a01d-1def95657383 (1)](https://user-images.githubusercontent.com/70570645/172273386-fa9606ac-3e63-4b2e-8978-3142add3e038.png) 4 | 5 | 6 |

7 | Blog 8 |   ⋅   9 | Docs 10 |   ⋅   11 | Learning Hub 12 |   ⋅   13 | Newsletter 14 |   ⋅   15 | Certifications 16 |   ⋅   17 | YouTube 18 |

19 |   20 |   21 |   22 | 23 | *Learn how to run your Python automation testing scripts on the LambdaTest platform* 24 | 25 | [](https://accounts.lambdatest.com/register) 26 | 27 | 28 | ## Table Of Contents 29 | 30 | * [Pre-requisites](#pre-requisites) 31 | * [Run Your First Test](#run-your-first-test) 32 | * [Local Testing With Python](#testing-locally-hosted-or-privately-hosted-projects) 33 | 34 | ## Prerequisites 35 | 36 | Before you can start performing **Python** automation testing with **Selenium**, you would need to: 37 | 38 | * Install the latest Python build from the [official website](https://www.python.org/downloads/). We recommend using the latest version. 39 | * Make sure **pip** is installed in your system. You can install **pip** from [here](https://pip.pypa.io/en/stable/installation/). 40 | * Download the latest **Selenium Client** and its **WebDriver bindings** from the [official website](https://www.selenium.dev/downloads/). Latest versions of **Selenium Client** and **WebDriver** are ideal for running your automation script on LambdaTest Selenium cloud grid. 41 | 42 | ### Installing Selenium Dependencies And Tutorial Repo 43 | 44 | **Step 1:** Clone the LambdaTest’s python-selenium-sample repository and navigate to the code directory as shown below: 45 | 46 | ```bash 47 | git clone https://github.com/LambdaTest/python-selenium-sample 48 | cd python-selenium-sample/selenium-3 49 | ``` 50 | 51 | **Step 2:** Download the driver from the link, or you can use **pip** to install it. 52 | ```bash 53 | pip install -r requirements.txt 54 | export PYTHONWARNINGS="ignore:Unverified HTTPS request" //Disable ssl warning 55 | ``` 56 | 57 | ### Setting Up Your Authentication 58 | 59 | Make sure you have your LambdaTest credentials with you to run test automation scripts. You can get these credentials from the [LambdaTest Automation Dashboard](https://automation.lambdatest.com/build/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) or by your [LambdaTest Profile](https://accounts.lambdatest.com/login/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample). 60 | 61 | **Step 2:** Set LambdaTest **Username** and **Access Key** in environment variables. 62 | 63 | * For **Linux/macOS**: 64 | 65 | ```bash 66 | export LT_USERNAME="YOUR_USERNAME" 67 | export LT_ACCESS_KEY="YOUR ACCESS KEY" 68 | ``` 69 | * For **Windows**: 70 | ```bash 71 | set LT_USERNAME="YOUR_USERNAME" 72 | set LT_ACCESS_KEY="YOUR ACCESS KEY" 73 | ``` 74 | 75 | ## Run Your First Test 76 | 77 | >**Test Scenario**: The [lambdatest.py](https://github.com/LambdaTest/python-selenium-sample/blob/master/lambdatest.py) sample script tests a simple to-do application with basic functionalities like mark items as done, add items in a list, calculate total pending items etc. 78 | 79 | ### Configuration Of Your Test Capabilities 80 | 81 | **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. 82 | 83 | The capabilities in the below code are defined as: 84 | 85 | ```python 86 | capability = { 87 | "browserName": "Chrome", 88 | "browserVersion": "latest", 89 | "LT:Options": { 90 | "username": username, 91 | "accessKey": access_key, 92 | "platformName": "Windows 10", 93 | "build": "Selenium 3 Example" 94 | } 95 | } 96 | ``` 97 | 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). 98 | 99 | ### Executing The Test 100 | 101 | **Step 5:** You would need to execute the below command in your terminal/cmd. 102 | 103 | ```bash 104 | python lambdatest.py 105 | ``` 106 | For python3 use 107 | ```bash 108 | python3 lambdatest.py 109 | ``` 110 | 111 | Your test results would be displayed on the test console (or command-line interface if you are using terminal/cmd) and on LambdaTest automation dashboard. 112 | 113 | 114 | ## Testing Locally Hosted Or Privately Hosted Projects 115 | 116 | You can test your locally hosted or privately hosted projects with LambdaTest Selenium grid using LambdaTest Tunnel. All you would have to do is set up an SSH tunnel using tunnel and pass toggle `tunnel = True` via desired capabilities. LambdaTest Tunnel establishes a secure SSH protocol based tunnel that allows you in testing your locally hosted or privately hosted pages, even before they are live. 117 | 118 | Refer our [LambdaTest Tunnel documentation](https://www.lambdatest.com/support/docs/testing-locally-hosted-pages/) for more information. 119 | 120 | Here’s how you can establish LambdaTest Tunnel. 121 | 122 | Download the binary file of: 123 | * [LambdaTest Tunnel for Windows](https://downloads.lambdatest.com/tunnel/v3/windows/64bit/LT_Windows.zip) 124 | * [LambdaTest Tunnel for macOS](https://downloads.lambdatest.com/tunnel/v3/mac/64bit/LT_Mac.zip) 125 | * [LambdaTest Tunnel for Linux](https://downloads.lambdatest.com/tunnel/v3/linux/64bit/LT_Linux.zip) 126 | 127 | Open command prompt and navigate to the binary folder. 128 | 129 | Run the following command: 130 | 131 | ```bash 132 | LT -user {user’s login email} -key {user’s access key} 133 | ``` 134 | So if your user name is lambdatest@example.com and key is 123456, the command would be: 135 | 136 | ```bash 137 | LT -user lambdatest@example.com -key 123456 138 | ``` 139 | Once you are able to connect **LambdaTest Tunnel** successfully, you would just have to pass on tunnel capabilities in the code shown below : 140 | 141 | **Tunnel Capability** 142 | 143 | ``` 144 | "tunnel" : true 145 | ``` 146 | 147 | ## Tutorials 📙 148 | 149 | Check out our latest tutorials on Python automation testing 👇 150 | 151 | * [Why Python Is A Preferred Language For Test Automation?](https://www.lambdatest.com/blog/python-automation-testing/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 152 | * [7 Best Python Testing Frameworks](https://www.lambdatest.com/blog/top-python-frameworks-in-2020-for-selenium-test-automation/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 153 | * [Selenium 4 With Python: All You Need To Know](https://www.lambdatest.com/blog/selenium-with-python/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 154 | * [How to Set Up Selenium With Python for Modern Web Automation](https://www.lambdatest.com/blog/selenium-webdriver-with-python/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 155 | * [Using Selenium and Python Hypothesis for Automation Testing](https://www.lambdatest.com/blog/using-selenium-and-python-hypothesis-for-automation-testing/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 156 | * [Selenium Python Tutorial: Getting Started With BDD In Behave](https://www.lambdatest.com/blog/selenium-python-behave-tutorial-bdd/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 157 | * [Selenium Python Tutorial: Getting Started With Pytest](https://www.lambdatest.com/blog/selenium-python-pytest-testing-tutorial/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 158 | * [Selenium Python Tutorial: Running First PyUnit Script](https://www.lambdatest.com/blog/using-pyunit-for-testing-a-selenium-python-test-suite/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 159 | * [Robot Framework with Selenium and Python](https://www.lambdatest.com/blog/robot-framework-tutorial/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 160 | * [Getting Started With Selenium Python [Tutorial]](https://www.lambdatest.com/blog/robot-framework-tutorial/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 161 | * [Running Python Selenium Test in Parallel With PyTest](https://www.lambdatest.com/blog/robot-framework-tutorial/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 162 | * [Parallel Testing In Selenium WebDriver With Python Using Unittest](https://www.lambdatest.com/blog/robot-framework-tutorial/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 163 | * [Automated Browser Testing with Opera and Selenium in Python](https://www.lambdatest.com/blog/automated-browser-testing-with-opera-and-selenium-in-python/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 164 | * [How To Take A Screenshot Using Python & Selenium?](https://www.lambdatest.com/blog/python-selenium-screenshots/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 165 | * [How To Drag And Drop In Selenium With Python?](https://www.lambdatest.com/blog/drag-and-drop-in-selenium-python/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 166 | * [How To Switch Tabs In A Browser Using Selenium Python?](https://www.lambdatest.com/blog/python-selenium-switch-tabs/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 167 | * [How To Get Page Source In Selenium Using Python?](https://www.lambdatest.com/blog/how-to-get-page-source-in-selenium-webdriver/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 168 | * [How To Handle Dropdowns In Selenium WebDriver Using [Python?]](https://www.lambdatest.com/blog/handling-dropdown-in-selenium-webdriver-python/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 169 | * [How To Do Parameterization In Pytest With Selenium?](https://www.lambdatest.com/blog/parameterization-in-pytest-with-selenium/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 170 | * [Page Object Model (POM) In Selenium Python](https://www.lambdatest.com/blog/page-object-model-in-selenium-python/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 171 | * [How To Read Configuration Files in Python Using Selenium](https://www.lambdatest.com/blog/how-to-read-configuration-files-in-python-using-selenium/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 172 | * [How To Create an Automated Web Bot With Selenium in Python?](https://www.lambdatest.com/blog/automated-web-bot-with-selenium-python/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 173 | * [How To Perform Web Scraping Using Selenium and Python?](https://www.lambdatest.com/blog/web-scraping-using-selenium-and-python/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 174 | * [Adding Firefox Extensions With Selenium in Python](https://www.lambdatest.com/blog/adding-firefox-extensions-with-selenium-in-python/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 175 | * [How to Handle JavaScript Alert in Selenium WebDriver Using Python?](https://www.lambdatest.com/blog/how-to-handle-javascript-alert-in-selenium-webdriver/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 176 | * [Use Selenium Wait for Page to Load With Python](https://www.lambdatest.com/blog/selenium-wait-for-page-to-load/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 177 | * [Selenium Python Cheat Sheet for Test Automation](https://www.lambdatest.com/blog/selenium-python-cheat-sheet/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 178 | 179 | 180 | ## Documentation & Resources :books: 181 | 182 | 183 | Visit the following links to learn more about LambdaTest's features, setup and tutorials around test automation, mobile app testing, responsive testing, and manual testing. 184 | 185 | * [LambdaTest Documentation](https://www.lambdatest.com/support/docs/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 186 | * [LambdaTest Blog](https://www.lambdatest.com/blog/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 187 | * [LambdaTest Learning Hub](https://www.lambdatest.com/learning-hub/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 188 | 189 | ## LambdaTest Community :busts_in_silhouette: 190 | 191 | The [LambdaTest Community](https://community.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) allows people to interact with tech enthusiasts. Connect, ask questions, and learn from tech-savvy people. Discuss best practises in web development, testing, and DevOps with professionals from across the globe 🌎 192 | 193 | ## What's New At LambdaTest ❓ 194 | 195 | To stay updated with the latest features and product add-ons, visit [Changelog](https://changelog.lambdatest.com/) 196 | 197 | ## About LambdaTest 198 | 199 | [LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) is a leading test execution and orchestration platform that is fast, reliable, scalable, and secure. It allows users to run both manual and automated testing of web and mobile apps across 3000+ different browsers, operating systems, and real device combinations. Using LambdaTest, businesses can ensure quicker developer feedback and hence achieve faster go to market. Over 500 enterprises and 1 Million + users across 130+ countries rely on LambdaTest for their testing needs. 200 | 201 | ### Features 202 | 203 | * Run Selenium, Cypress, Puppeteer, Playwright, and Appium automation tests across 3000+ real desktop and mobile environments. 204 | * Real-time cross browser testing on 3000+ environments. 205 | * Test on Real device cloud 206 | * Blazing fast test automation with HyperExecute 207 | * Accelerate testing, shorten job times and get faster feedback on code changes with Test At Scale. 208 | * Smart Visual Regression Testing on cloud 209 | * 120+ third-party integrations with your favorite tool for CI/CD, Project Management, Codeless Automation, and more. 210 | * Automated Screenshot testing across multiple browsers in a single click. 211 | * Local testing of web and mobile apps. 212 | * Online Accessibility Testing across 3000+ desktop and mobile browsers, browser versions, and operating systems. 213 | * Geolocation testing of web and mobile apps across 53+ countries. 214 | * LT Browser - for responsive testing across 50+ pre-installed mobile, tablets, desktop, and laptop viewports 215 | 216 | 217 | [](https://accounts.lambdatest.com/register) 218 | 219 | 220 | 221 | ## We are here to help you :headphones: 222 | 223 | * Got a query? we are available 24x7 to help. [Contact Us](support@lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 224 | * For more info, visit - [LambdaTest](https://www.lambdatest.com/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample) 225 | 226 | -------------------------------------------------------------------------------- /selenium-3/lambdatest.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import os 3 | from selenium import webdriver 4 | from selenium.webdriver.common.by import By 5 | from selenium.webdriver.chrome.options import Options as ChromeOptions 6 | from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 7 | import warnings 8 | 9 | username = os.getenv("LT_USERNAME") # Replace the username 10 | access_key = os.getenv("LT_ACCESS_KEY") # Replace the access key 11 | 12 | 13 | capability = { 14 | "browserName": "Chrome", 15 | "browserVersion": "latest", 16 | "LT:Options": { 17 | "username": username, 18 | "accessKey": access_key, 19 | "platformName": "Windows 10", 20 | "build": "Selenium 3 Example", 21 | "name" : "Selenium 3 Sample Test" 22 | } 23 | } 24 | 25 | def suppress_resource_warnings(): 26 | warnings.filterwarnings("ignore", category=ResourceWarning) 27 | 28 | class FirstSampleTest(unittest.TestCase): 29 | driver = None 30 | 31 | def setUp(self): 32 | suppress_resource_warnings() 33 | self.driver = webdriver.Remote( 34 | command_executor = "http://{}:{}@hub.lambdatest.com/wd/hub".format( 35 | username, access_key 36 | ), 37 | # options=options, 38 | desired_capabilities = capability 39 | ) 40 | 41 | # """ You can write the test cases here """ 42 | def test_demo_site(self): 43 | suppress_resource_warnings() 44 | driver = self.driver 45 | driver.implicitly_wait(10) 46 | driver.set_page_load_timeout(30) 47 | # driver.set_window_size(1920, 1080) 48 | 49 | # Url 50 | print("Loading URL") 51 | driver.get( 52 | "https://lambdatest.github.io/sample-todo-app/" 53 | ) 54 | 55 | # Let's click on a element 56 | driver.find_element(By.NAME, "li1").click() 57 | location = driver.find_element(By.NAME, "li2") 58 | location.click() 59 | print("Clicked on the second element") 60 | 61 | # Let's add a checkbox 62 | driver.find_element(By.ID, "sampletodotext").send_keys("LambdaTest") 63 | add_button = driver.find_element(By.ID, "addbutton") 64 | add_button.click() 65 | print("Added LambdaTest checkbox") 66 | 67 | # print the heading 68 | search = driver.find_element(By.CSS_SELECTOR, ".container h2") 69 | assert search.is_displayed(), "heading is not displayed" 70 | print(search.text) 71 | search.click() 72 | driver.implicitly_wait(3) 73 | 74 | # Let's download the invoice 75 | heading = driver.find_element(By.CSS_SELECTOR, ".container h2") 76 | if heading.is_displayed(): 77 | heading.click() 78 | driver.execute_script("lambda-status=passed") 79 | print("Tests are run successfully!") 80 | else: 81 | driver.execute_script("lambda-status=failed") 82 | 83 | # tearDown runs after each test case 84 | def tearDown(self): 85 | self.driver.quit() 86 | 87 | 88 | if __name__ == "__main__": 89 | unittest.main() -------------------------------------------------------------------------------- /selenium-3/requirements.txt: -------------------------------------------------------------------------------- 1 | urllib3==1.26.5 2 | selenium==3.141.0 --------------------------------------------------------------------------------