Skip to content

Instantly share code, notes, and snippets.

@muditlambda
Created September 21, 2020 15:11
# Python example demonstrates Selenium testing on the Cloud using LambdaTest platform
import time
import unittest
import selenium
import urllib3
import time
import warnings
from time import sleep
from selenium import webdriver
test_url = "https://www.duckduckgo.com"
# Desired browser capabilities generated using LambdaTest Capabilities Generator
# https://www.lambdatest.com/capabilities-generator/
desired_capabilities = {
"build" : "Parallel Testing - Selenium testing on the Cloud [IE]",
"name" : "Parallel Testing - Selenium testing on the Cloud [ChromeIE]",
"platform" : "Windows 7",
"browserName" : "Internet Explorer",
"version" : "11.0",
"ie.compatibility" : 11001
}
class SeachTest(unittest.TestCase):
def setUp(self):
print("Start - SetUp")
# Ignore ResourceWarning related warnings
warnings.filterwarnings(action="ignore", message="unclosed", category=ResourceWarning)
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
# user_name = "user-name"
# app_key = "app_key"
user_name = "himanshu.sheth@gmail.com"
app_key = "fbI6kxucn5iRzwt5GWYiNvaPb4Olu9R8lwBsXWTSaIOebXn4x9"
# Username and Access Token to use the LambdaTest platform
remote_url = "https://" + user_name + ":" + app_key + "@hub.lambdatest.com/wd/hub"
self.driver = webdriver.Remote(command_executor=remote_url, desired_capabilities=desired_capabilities)
print("End - SetUp")
def test_selenium_on_cloud(self):
print("Start - test_selenium_on_cloud")
self.driver.maximize_window()
self.driver.get(test_url)
# time.sleep(5)
sleep(5)
# Locate the element using the Inspect tool of the browser
elem = self.driver.find_element_by_xpath("//*[@id='search_form_input_homepage']")
elem.send_keys("Lambdatest")
# Execute the search
elem.submit()
# Sleep for 10 seconds in order to see the results
sleep(5)
print("End - test_selenium_on_cloud")
def tearDown(self):
print("Start - tearDown")
# Close the browser.
self.driver.quit()
print("End - tearDown")
if __name__ == '__main__':
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment