|
| 1 | +import time |
| 2 | +from selenium import webdriver |
| 3 | +from selenium.webdriver.common.keys import Keys |
| 4 | +from selenium.webdriver.chrome.options import Options |
| 5 | +import os |
| 6 | + |
| 7 | + |
| 8 | +""" |
| 9 | + LambdaTest selenium automation sample example |
| 10 | + Configuration |
| 11 | + ---------- |
| 12 | + username: Username can be found at automation dashboard |
| 13 | + accessToken: AccessToken can be genarated from automation dashboard or profile section |
| 14 | +
|
| 15 | + Result |
| 16 | + ------- |
| 17 | + Execute Test on lambdatest Distributed Grid perform selenium automation based |
| 18 | +""" |
| 19 | + |
| 20 | +# username: Username can be found at automation dashboard |
| 21 | +username = os.getenv("LT_USERNAME") |
| 22 | +# accessToken: AccessToken can be genarated from automation dashboard or profile section |
| 23 | +accessToken = os.getenv("LT_ACCESS_KEY") |
| 24 | +# gridUrl: gridUrl can be found at automation dashboard |
| 25 | +gridUrl = "hub.lambdatest.com/wd/hub" |
| 26 | + |
| 27 | + |
| 28 | +capabilities = { |
| 29 | + 'LT:Options': { |
| 30 | + "build": "your build name", |
| 31 | + "name": "your test name", |
| 32 | + "platformName": "Windows 10" |
| 33 | + }, |
| 34 | + "browserName": "Chrome", |
| 35 | + "browserVersion": "latest", |
| 36 | +} |
| 37 | + |
| 38 | +url = "https://"+username+":"+accessToken+"@"+gridUrl |
| 39 | + |
| 40 | + |
| 41 | +""" |
| 42 | + ---------- |
| 43 | + 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) |
| 44 | + browserName : Supported platfrom - (chrome, firefox, Internet Explorer, MicrosoftEdge) |
| 45 | + browserVersion : Supported list of version can be found at https://www.lambdatest.com/capabilities-generator/ |
| 46 | +
|
| 47 | + Result |
| 48 | + ------- |
| 49 | +""" |
| 50 | + |
| 51 | +driver = webdriver.Remote( |
| 52 | + command_executor=url, |
| 53 | + desired_capabilities=capabilities |
| 54 | +) |
| 55 | + |
| 56 | +""" |
| 57 | + ---------- |
| 58 | + Execute test: navigate google.com search LambdaTest |
| 59 | + Result |
| 60 | + ---------- |
| 61 | + print title |
| 62 | +""" |
| 63 | + |
| 64 | +driver.get("https://www.google.com/ncr") |
| 65 | + |
| 66 | +print("Searching lambdatest on google.com ") |
| 67 | +time.sleep(8) |
| 68 | +elem = driver.find_element_by_name("q") |
| 69 | +elem.send_keys("lambdatest.com") |
| 70 | +elem.submit() |
| 71 | + |
| 72 | +print("Printing title of current page :"+driver.title) |
| 73 | +driver.execute_script("lambda-status=passed") |
| 74 | +print("Requesting to mark test : pass") |
| 75 | + |
| 76 | +""" |
| 77 | + Quit selenium driver |
| 78 | +""" |
| 79 | +driver.quit() |
0 commit comments