|
| 1 | +""" |
| 2 | +LambdaTest selenium automation sample example |
| 3 | +Configuration |
| 4 | +---------- |
| 5 | +username: Username can be found at automation dashboard |
| 6 | +accessToken: AccessToken can be genarated from automation dashboard or profile section |
| 7 | +
|
| 8 | +Result |
| 9 | +------- |
| 10 | +Execute Test on lambdatest Distributed Grid perform selenium automation based |
| 11 | +""" |
| 12 | +import unittest |
| 13 | +import time |
| 14 | +from selenium import webdriver |
| 15 | +from selenium.webdriver.common.keys import Keys |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | +class LTAutomate(unittest.TestCase): |
| 20 | + |
| 21 | + """ |
| 22 | + Setup remote driver |
| 23 | + Params |
| 24 | + ---------- |
| 25 | + platfrom : 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) |
| 26 | + browserName : Supported platfrom - (chrome, firefox, Internet Explorer, MicrosoftEdge) |
| 27 | + version : Supported list of version can be found at https://www.lambdatest.com/capabilities-generator/ |
| 28 | +
|
| 29 | + Result |
| 30 | + ------- |
| 31 | + """ |
| 32 | + def setUp(self): |
| 33 | + # username: Username can be found at automation dashboard |
| 34 | + username="{username}" |
| 35 | + # accessToken: AccessToken can be genarated from automation dashboard or profile section |
| 36 | + accessToken="{accessToken}" |
| 37 | + # gridUrl: gridUrl can be found at automation dashboard |
| 38 | + gridUrl = "beta-hub.lambdatest.com/wd/hub" |
| 39 | + |
| 40 | + desired_cap = { |
| 41 | + 'platform' : "win10", |
| 42 | + 'browserName' : "chrome", |
| 43 | + 'version' : "67.0", |
| 44 | + # Resolution of machine |
| 45 | + "resolution": "1024x768", |
| 46 | + "name": "LambdaTest python google search test ", |
| 47 | + "build": "LambdaTest python google search build", |
| 48 | + "network": True, |
| 49 | + "video": True, |
| 50 | + "visual": True, |
| 51 | + "console": True, |
| 52 | + } |
| 53 | + |
| 54 | + # URL: https://{username}:{accessToken}@beta-hub.lambdatest.com/wd/hub |
| 55 | + url = "https://"+username+":"+accessToken+"@"+gridUrl |
| 56 | + |
| 57 | + print("Initiating remote driver on platfrom: "+desired_cap["platform"]+" browser: "+desired_cap["browserName"]+" version: "+desired_cap["version"]) |
| 58 | + self.driver = webdriver.Remote( |
| 59 | + desired_capabilities=desired_cap, |
| 60 | + command_executor= url |
| 61 | + ) |
| 62 | + |
| 63 | + """ |
| 64 | + Setup remote driver |
| 65 | + Params |
| 66 | + ---------- |
| 67 | + Execute test: navigate google.com search LambdaTest |
| 68 | + Result |
| 69 | + ------- |
| 70 | + print title |
| 71 | + """ |
| 72 | + def test_search_in_google(self): |
| 73 | + driver = self.driver |
| 74 | + print("Driver initiated sucessfully. Navigate url") |
| 75 | + driver.get("https://www.google.com/ncr") |
| 76 | + |
| 77 | + print("Searching lambdatest on google.com ") |
| 78 | + time.sleep(8) |
| 79 | + elem = driver.find_element_by_name("q") |
| 80 | + elem.send_keys("lambdatest.com") |
| 81 | + elem.submit() |
| 82 | + |
| 83 | + print("Printing title of current page :"+driver.title) |
| 84 | + driver.execute_script("lambda-status=passed") |
| 85 | + print("Requesting to mark test : pass") |
| 86 | + |
| 87 | + """ |
| 88 | + Quit selenium driver |
| 89 | + """ |
| 90 | + def tearDown(self): |
| 91 | + self.driver.quit() |
| 92 | + |
| 93 | +if __name__ == "__main__": |
| 94 | + unittest.main() |
0 commit comments