Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 55 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

<p align="center">
<b>For Linux/macOS:</b>

```
export LT_USERNAME="YOUR_USERNAME"
export LT_ACCESS_KEY="YOUR ACCESS KEY"
```

<p align="center">
<b>For Windows:</b>

```
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.
79 changes: 0 additions & 79 deletions google-search-lambdatest.py

This file was deleted.

60 changes: 60 additions & 0 deletions lambdatest.py
Original file line number Diff line number Diff line change
@@ -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()