Content-Length: 776753 | pFad | http://github.com/LambdaTest/python-selenium-sample/commit/44779703bf627c2b232d553f7e1f79f2488dbde6

5D autohealing python demo · LambdaTest/python-selenium-sample@4477970 · GitHub
Skip to content

Commit 4477970

Browse files
committed
autohealing python demo
1 parent 3b9a447 commit 4477970

6 files changed

+228
-110
lines changed

.gitpod.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# List the start up tasks. Learn more https://www.gitpod.io/docs/config-start-tasks/
22
tasks:
3-
- init: pip install selenium && export PYTHONWARNINGS="ignore:Unverified HTTPS request" # runs during prebuild
4-
command: python lambdatest.py
3+
- init: pip install requirements.txt && export PYTHONWARNINGS="ignore:Unverified HTTPS request" # runs during prebuild
4+
command: python autoHealingEnableDemo.py && python autoHealingDisableDemo.py
55

66

README.md

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ Make sure you have your LambdaTest credentials with you to run test automation s
7474

7575
## Run Your First Test
7676

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.
77+
>**Test Scenario**:
78+
79+
7880

7981
### Configuration Of Your Test Capabilities
8082

@@ -83,28 +85,34 @@ Make sure you have your LambdaTest credentials with you to run test automation s
8385
The capabilities object in the above code are defined as:
8486

8587
```python
86-
capabilities = {
87-
"build": "your build name",
88-
"name": "your test name",
89-
"platformName": "Windows 10"
90-
"browserName": "Chrome",
91-
"browserVersion": "latest",
88+
# Desired capabilities for the test
89+
desired_caps = {
90+
'LT:Options': {
91+
"build": "Auto Heal Demo",
92+
"name": "Auto Heal Enabled",
93+
"platformName": "Windows 10",
94+
"autoHeal": 'true',
95+
},
96+
"browserName": "Chrome",
97+
"browserVersion": "latest",
98+
}
9299
}
93100
```
94101
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).
95102

96103
### Executing The Test
97104

98-
**Step 5:** You would need to execute the below command in your terminal/cmd.
105+
**Execution Steps:**
106+
1. Install the required libraries:
107+
```
108+
pip install -r requirements.txt
109+
```
99110

100-
```bash
101-
python lambdatest.py
102-
```
103-
For python3 use
104-
```bash
105-
python3 lambdatest.py
106-
```
107111

112+
3. Run the test:
113+
```
114+
python autoHealingEnableDemo.py && python autoHealingDisableDemo.py
115+
```
108116
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.
109117

110118

autoHealingDisableDemo.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Import necessary libraries
2+
import time
3+
import unittest
4+
import os
5+
from selenium import webdriver
6+
from selenium.webdriver.common.by import By
7+
8+
# Fetching environment variables for LambdaTest authentication
9+
username = os.getenv("LT_USERNAME")
10+
access_key = os.getenv("LT_ACCESS_KEY")
11+
12+
# Define the test class which inherits from unittest.TestCase
13+
class AutoHealDemoTest(unittest.TestCase):
14+
15+
# This method will be executed before every test method
16+
def setUp(self):
17+
# Desired capabilities for the test
18+
desired_caps = {
19+
'LT:Options': {
20+
"build": "Auto Heal Demo",
21+
"name": "Auto Heal Enabled",
22+
"platformName": "Windows 10",
23+
"autoHeal": 'false',
24+
},
25+
"browserName": "Chrome",
26+
"browserVersion": "latest",
27+
}
28+
29+
# Initialize the remote webdriver for LambdaTest
30+
self.driver = webdriver.Remote(
31+
command_executor="http://{}:{}@hub.lambdatest.com/wd/hub".format(
32+
username, access_key),
33+
desired_capabilities=desired_caps)
34+
35+
# This method will be executed after every test method
36+
def tearDown(self):
37+
# Close the browser session
38+
self.driver.quit()
39+
40+
# Method to update locators on the page
41+
def updateLocators(self, driver):
42+
print("Updating Page Locators")
43+
# Change the ID of the search submit button
44+
driver.execute_script("document.getElementById('nav-search-submit-button').id = 'changed-search-submit-btn';")
45+
time.sleep(1)
46+
# Change the ID of the search textbox
47+
driver.execute_script("document.getElementById('twotabsearchtextbox').id = 'newsearchtextbtn';")
48+
time.sleep(1)
49+
50+
# Main test method
51+
def test_demo_site(self):
52+
driver = self.loadAmazonWebsite()
53+
# Uncomment below to update page locators.
54+
self.updateLocators(driver)
55+
self.searchBookAndGoToCart(driver)
56+
57+
# Method to search for a book and navigate to the cart
58+
def searchBookAndGoToCart(self, driver):
59+
print("Executing Test Script")
60+
try:
61+
# Select the dropdown for search categories
62+
drop_down_btn = driver.find_element(By.ID, "searchDropdownBox")
63+
drop_down_btn.click()
64+
time.sleep(1)
65+
# Select 'Books' from the dropdown
66+
books_btn = driver.find_element(By.XPATH, "//*[@id=\"searchDropdownBox\"]/option[11]")
67+
if books_btn.is_displayed():
68+
books_btn.click()
69+
# Enter 'Python Programming' in the search box
70+
search_box = driver.find_element(By.ID, "twotabsearchtextbox")
71+
if search_box.is_displayed():
72+
time.sleep(1)
73+
search_box.send_keys("Python Programming")
74+
time.sleep(1)
75+
# Click the search button
76+
search_button = driver.find_element(By.ID, "nav-search-submit-button")
77+
if search_button.is_displayed():
78+
time.sleep(1)
79+
search_button.click()
80+
# Mark the test as passed on LambdaTest
81+
driver.execute_script("lambda-status=passed")
82+
return
83+
# Mark the test as failed on LambdaTest if any of the above steps fail
84+
driver.execute_script("lambda-status=failed")
85+
except:
86+
# Mark the test as failed on LambdaTest if there's an exception
87+
driver.execute_script("lambda-status=failed")
88+
89+
# Method to load the Amazon website
90+
def loadAmazonWebsite(self):
91+
driver = self.driver
92+
print('Loading URL')
93+
driver.get("https://www.amazon.in")
94+
driver.set_page_load_timeout(30)
95+
time.sleep(10)
96+
print("Page Loaded Successfully.")
97+
return driver
98+
99+
# This block ensures the test runs if this script is executed
100+
if __name__ == "__main__":
101+
unittest.main()

autoHealingEnableDemo.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Import necessary libraries
2+
import time
3+
import unittest
4+
import os
5+
from selenium import webdriver
6+
from selenium.webdriver.common.by import By
7+
8+
# Fetching environment variables for LambdaTest authentication
9+
username = os.getenv("LT_USERNAME")
10+
access_key = os.getenv("LT_ACCESS_KEY")
11+
12+
# Define the test class which inherits from unittest.TestCase
13+
class AutoHealDemoTest(unittest.TestCase):
14+
15+
# This method will be executed before every test method
16+
def setUp(self):
17+
# Desired capabilities for the test
18+
desired_caps = {
19+
'LT:Options': {
20+
"build": "Auto Heal Demo",
21+
"name": "Auto Heal Enabled",
22+
"platformName": "Windows 10",
23+
"autoHeal": 'true',
24+
},
25+
"browserName": "Chrome",
26+
"browserVersion": "latest",
27+
}
28+
29+
# Initialize the remote webdriver for LambdaTest
30+
self.driver = webdriver.Remote(
31+
command_executor="http://{}:{}@hub.lambdatest.com/wd/hub".format(
32+
username, access_key),
33+
desired_capabilities=desired_caps)
34+
35+
# This method will be executed after every test method
36+
def tearDown(self):
37+
# Close the browser session
38+
self.driver.quit()
39+
40+
# Method to update locators on the page
41+
def updateLocators(self, driver):
42+
print("Updating Page Locators")
43+
# Change the ID of the search submit button
44+
driver.execute_script("document.getElementById('nav-search-submit-button').id = 'changed-search-submit-btn';")
45+
time.sleep(1)
46+
# Change the ID of the search textbox
47+
driver.execute_script("document.getElementById('twotabsearchtextbox').id = 'newsearchtextbtn';")
48+
time.sleep(1)
49+
50+
# Main test method
51+
def test_demo_site(self):
52+
driver = self.loadAmazonWebsite()
53+
# Uncomment below to update page locators.
54+
self.updateLocators(driver)
55+
self.searchBookAndGoToCart(driver)
56+
57+
# Method to search for a book and navigate to the cart
58+
def searchBookAndGoToCart(self, driver):
59+
print("Executing Test Script")
60+
try:
61+
# Select the dropdown for search categories
62+
drop_down_btn = driver.find_element(By.ID, "searchDropdownBox")
63+
drop_down_btn.click()
64+
time.sleep(1)
65+
# Select 'Books' from the dropdown
66+
books_btn = driver.find_element(By.XPATH, "//*[@id=\"searchDropdownBox\"]/option[11]")
67+
if books_btn.is_displayed():
68+
books_btn.click()
69+
# Enter 'Python Programming' in the search box
70+
search_box = driver.find_element(By.ID, "twotabsearchtextbox")
71+
if search_box.is_displayed():
72+
time.sleep(1)
73+
search_box.send_keys("Python Programming")
74+
time.sleep(1)
75+
# Click the search button
76+
search_button = driver.find_element(By.ID, "nav-search-submit-button")
77+
if search_button.is_displayed():
78+
time.sleep(1)
79+
search_button.click()
80+
# Mark the test as passed on LambdaTest
81+
driver.execute_script("lambda-status=passed")
82+
return
83+
# Mark the test as failed on LambdaTest if any of the above steps fail
84+
driver.execute_script("lambda-status=failed")
85+
except:
86+
# Mark the test as failed on LambdaTest if there's an exception
87+
driver.execute_script("lambda-status=failed")
88+
89+
# Method to load the Amazon website
90+
def loadAmazonWebsite(self):
91+
driver = self.driver
92+
print('Loading URL')
93+
driver.get("https://www.amazon.in")
94+
driver.set_page_load_timeout(30)
95+
time.sleep(10)
96+
print("Page Loaded Successfully.")
97+
return driver
98+
99+
# This block ensures the test runs if this script is executed
100+
if __name__ == "__main__":
101+
unittest.main()

lambdatest.py

Lines changed: 0 additions & 93 deletions
This file was deleted.

requirement.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
selenium==3.141.0

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/LambdaTest/python-selenium-sample/commit/44779703bf627c2b232d553f7e1f79f2488dbde6

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy