|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + LambdaTest selenium automation sample example |
| 5 | + Configuration |
| 6 | + ---------- |
| 7 | + username: Username can be found at automation dashboard |
| 8 | + accessToken: AccessToken can be generated from automation dashboard or profile section |
| 9 | +
|
| 10 | + Result |
| 11 | + ------- |
| 12 | + Execute PHP Automation Tests on LambdaTest Distributed Selenium Grid |
| 13 | +*/ |
| 14 | + |
| 15 | +require 'vendor/autoload.php'; |
| 16 | + |
| 17 | +class LambdaTest{ |
| 18 | + |
| 19 | + /* |
| 20 | + Setup remote driver |
| 21 | + Params |
| 22 | + ---------- |
| 23 | + platform : Supported platform - (Windows 10, Windows 8.1, Windows 8, Windows 7, macOS High Sierra, macOS Sierra, OS X El Capitan, OS X Yosemite, OS X Mavericks) |
| 24 | + browserName : Supported platform - (chrome, firefox, Internet Explorer, MicrosoftEdge, Safari) |
| 25 | + version : Supported list of version can be found at https://www.lambdatest.com/capabilities-generator/ |
| 26 | + */ |
| 27 | + protected static $driver; |
| 28 | + |
| 29 | + public function searchTextOnGoogle() { |
| 30 | + # username: Username can be found at automation dashboard |
| 31 | + $LT_USERNAME = "{username}"; |
| 32 | + |
| 33 | + # accessKey: AccessKey can be generated from automation dashboard or profile section |
| 34 | + $LT_APPKEY = "{accessKey}"; |
| 35 | + |
| 36 | + $LT_BROWSER = "chrome"; |
| 37 | + $LT_BROWSER_VERSION ="63.0"; |
| 38 | + $LT_PLATFORM = "windows 10"; |
| 39 | + |
| 40 | + # URL: https://{username}:{accessToken}@beta-hub.lambdatest.com/wd/hub |
| 41 | + $url = "https://". $LT_USERNAME .":" . $LT_APPKEY ."@beta-hub.lambdatest.com/wd/hub"; |
| 42 | + |
| 43 | + # setting desired capabilities for the test |
| 44 | + $desired_capabilities = new DesiredCapabilities(); |
| 45 | + $desired_capabilities->setCapability('browserName',$LT_BROWSER); |
| 46 | + $desired_capabilities->setCapability('version', $LT_BROWSER_VERSION); |
| 47 | + $desired_capabilities->setCapability('platform', $LT_PLATFORM); |
| 48 | + $desired_capabilities->setCapability('name', "Php"); |
| 49 | + $desired_capabilities->setCapability('build', "Php Build"); |
| 50 | + $desired_capabilities->setCapability('network', true); |
| 51 | + $desired_capabilities->setCapability('visual', true); |
| 52 | + $desired_capabilities->setCapability('video ', true); |
| 53 | + $desired_capabilities->setCapability('console', true); |
| 54 | + |
| 55 | + /* |
| 56 | + Setup remote driver |
| 57 | + Params |
| 58 | + ---------- |
| 59 | + Execute test: navigate google.com search LambdaTest |
| 60 | + Result |
| 61 | + ------- |
| 62 | + print title |
| 63 | + */ |
| 64 | + self::$driver = RemoteWebDriver::create($url, $desired_capabilities); |
| 65 | + |
| 66 | + self::$driver->get("https://www.google.com/ncr"); |
| 67 | + |
| 68 | + $element = self::$driver->findElement(WebDriverBy::name("q")); |
| 69 | + if($element) { |
| 70 | + $element->sendKeys("LambdaTest"); |
| 71 | + $element->submit(); |
| 72 | + } |
| 73 | + |
| 74 | + print self::$driver->getTitle(); |
| 75 | + self::$driver->quit(); |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +$lambdaTest = new LambdaTest(); |
| 80 | +$lambdaTest->searchTextOnGoogle(); |
| 81 | + |
| 82 | +?> |
| 83 | + |
0 commit comments