diff --git a/README.md b/README.md index 79487f8..11a64c6 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,66 @@ -## Python unittest automation Lambdatest +# Python-Selenium-Sample -Python selenium automation sample test for [LambdaTest](https://www.lambdatest.com/) cloud-based Selenium Grid. +![MSTest](https://opengraph.githubassets.com/8039186e9aebcc17be88d53ac4b85364a56f6aae503057e0ebf36dfcc5b5cc32/LambdaTest/python-selenium-sample) +## Prerequisites -## Install Python - - Download the latest python build from https://www.python.org/downloads/ - - Make sure pip should installed. you can check using `pip --version` +1. Install pip and python. +``` +sudo apt install python-pip +sudo apt install python +``` -### Configuring Test -- Replace {username} with your username -- Replace {accessToken} with your username -- List of supported platfrom, browser, version can be found at https://www.lambdatest.com/capabilities-generator/ +2. The recommended way to run your tests would be in virtualenv. It will isolate the build from other setups you may have running and ensure that the tests run with the specified versions of the modules specified in the requirements.txt file. +``` +pip install virtualenv +``` -### Installating Dependencies -```bash -pip install selenium -export PYTHONWARNINGS="ignore:Unverified HTTPS request" //Disable ssl warning +## Steps to Run your First Test + +Step 1. Clone the Python-Selenium-Sample Repository. + +``` +git clone https://github.com/LambdaTest/python-selenium-sample ``` -### Executing Test -```bash -python google-search-lambdatest.py +Step 2. Next we create and Activate the virtual environment in the Python-Selenium-Sample folder. + +``` +virtualenv venv +source venv/bin/activate +``` + +Step 3. Then install required packages. + +``` +pip install -r requirements.txt ``` + +Step 4. Inside Python-Selenium-Sample folder, export the Lambda-test Credentials. You can get these from your automation dashboard. + +

+ For Linux/macOS: + +``` +export LT_USERNAME="YOUR_USERNAME" +export LT_ACCESS_KEY="YOUR ACCESS KEY" +``` + +

+ For Windows: + +``` +set LT_USERNAME="YOUR_USERNAME" +set LT_ACCESS_KEY="YOUR ACCESS KEY" +``` + +Step 5. To run your first test. +``` +python lambdatest.py +``` + ## About LambdaTest -[LambdaTest](https://www.lambdatest.com/) is a cloud based selenium grid infrastructure that can help you run automated cross browser compatibility tests on 2000+ different browser and operating system environments. LambdaTest supports all programming languages and frameworks that are supported with Selenium, and have easy integrations with all popular CI/CD platforms. It's a perfect solution to bring your [selenium automation testing](https://www.lambdatest.com/selenium-automation) to cloud based infrastructure that not only helps you increase your test coverage over multiple desktop and mobile browsers, but also allows you to cut down your test execution time by running tests on parallel. + +[LambdaTest](https://www.lambdatest.com/) is a cloud based selenium grid infrastructure that can help you run automated cross browser compatibility tests on 2000+ different browser and operating system environments. LambdaTest supports all programming languages and frameworks that are supported with Selenium, and have easy integrations with all popular CI/CD platforms. It's a perfect solution to bring your [selenium automation testing](https://www.lambdatest.com/selenium-automation) to cloud based infrastructure that not only helps you increase your test coverage over multiple desktop and mobile browsers, but also allows you to cut down your test execution time by running tests on parallel. \ No newline at end of file diff --git a/google-search-lambdatest.py b/google-search-lambdatest.py deleted file mode 100644 index 9428407..0000000 --- a/google-search-lambdatest.py +++ /dev/null @@ -1,79 +0,0 @@ -import time -from selenium import webdriver -from selenium.webdriver.common.keys import Keys -from selenium.webdriver.chrome.options import Options -import os - - -""" - LambdaTest selenium automation sample example - Configuration - ---------- - username: Username can be found at automation dashboard - accessToken: AccessToken can be genarated from automation dashboard or profile section - - Result - ------- - Execute Test on lambdatest Distributed Grid perform selenium automation based -""" - -# username: Username can be found at automation dashboard -username = os.getenv("LT_USERNAME") -# accessToken: AccessToken can be genarated from automation dashboard or profile section -accessToken = os.getenv("LT_ACCESS_KEY") -# gridUrl: gridUrl can be found at automation dashboard -gridUrl = "hub.lambdatest.com/wd/hub" - - -capabilities = { - 'LT:Options': { - "build": "your build name", - "name": "your test name", - "platformName": "Windows 10" - }, - "browserName": "Chrome", - "browserVersion": "latest", -} - -url = "https://"+username+":"+accessToken+"@"+gridUrl - - -""" - ---------- - platformName : Supported platfrom - (Windows 10, Windows 8.1, Windows 8, Windows 7, macOS High Sierra, macOS Sierra, OS X El Capitan, OS X Yosemite, OS X Mavericks) - browserName : Supported platfrom - (chrome, firefox, Internet Explorer, MicrosoftEdge) - browserVersion : Supported list of version can be found at https://www.lambdatest.com/capabilities-generator/ - - Result - ------- -""" - -driver = webdriver.Remote( - command_executor=url, - desired_capabilities=capabilities -) - -""" - ---------- - Execute test: navigate google.com search LambdaTest - Result - ---------- - print title -""" - -driver.get("https://www.google.com/ncr") - -print("Searching lambdatest on google.com ") -time.sleep(8) -elem = driver.find_element_by_name("q") -elem.send_keys("lambdatest.com") -elem.submit() - -print("Printing title of current page :"+driver.title) -driver.execute_script("lambda-status=passed") -print("Requesting to mark test : pass") - -""" - Quit selenium driver -""" -driver.quit() diff --git a/lambdatest.py b/lambdatest.py new file mode 100644 index 0000000..24aa542 --- /dev/null +++ b/lambdatest.py @@ -0,0 +1,60 @@ +import unittest +import sys +from selenium import webdriver + +username = "Your Username" # Replace the username +access_key = "Your 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 = { + "build": 'PyunitTest sample build', # Change your build name here + "name": 'Py-unittest', # Change your test name here + "browserName": 'Chrome', + "version": '92.0', + "platform": 'Windows 10', + "resolution": '1024x768', + "console": 'true', # Enable or disable console logs + "network":'true' # Enable or disable network logs + } + self.driver = webdriver.Remote( + command_executor="https://{}:{}@hub.lambdatest.com/wd/hub".format(username, access_key), + desired_capabilities= desired_caps) + + +# tearDown runs after each test case + def tearDown(self): + self.driver.quit() + + # """ You can write the test cases here """ + def test_unit_user_should_able_to_add_item(self): + # try: + driver = self.driver + + # Url + driver.get("https://lambdatest.github.io/sample-todo-app/") + + # Click on check box + check_box_one = driver.find_element_by_name("li1") + check_box_one.click() + + # Click on check box + check_box_two = driver.find_element_by_name("li2") + check_box_two.click() + + # Enter item in textfield + textfield = driver.find_element_by_id("sampletodotext") + textfield.send_keys("Yey, Let's add it to list") + + # Click on add button + add_button = driver.find_element_by_id("addbutton") + add_button.click() + + # Verified added item + added_item = driver.find_element_by_xpath("//span[@class='done-false']").text + print (added_item) + +if __name__ == "__main__": + unittest.main()