|
1 | 1 | <?php |
2 | | -require_once('vendor/autoload.php'); |
3 | | -use Facebook\WebDriver\Remote\RemoteWebDriver; |
4 | | -use Facebook\WebDriver\WebDriverBy; |
5 | | -use Facebook\WebDriver\WebDriverExpectedCondition; |
6 | | -$caps = array( |
7 | | - 'bstack:options' => array( |
8 | | - "os" => "OS X", |
9 | | - "osVersion" => "Sierra", |
10 | | - "buildName" => "BStack Build Number 1", |
11 | | - "sessionName" => "BStack-[Php] Sample Test", |
12 | | - "local" => "false", |
13 | | - "seleniumVersion" => "4.0.0", |
14 | | - ), |
15 | | - "browserName" => "Chrome", |
16 | | - "browserVersion" => "latest", |
17 | | -); |
| 2 | + require_once('vendor/autoload.php'); |
| 3 | + use Facebook\WebDriver\Remote\RemoteWebDriver; |
| 4 | + use Facebook\WebDriver\WebDriverBy; |
| 5 | + use Facebook\WebDriver\WebDriverExpectedCondition; |
| 6 | + |
| 7 | + $caps = array( |
| 8 | + 'bstack:options' => array( |
| 9 | + "os" => "OS X", |
| 10 | + "osVersion" => "Sierra", |
| 11 | + "buildName" => "BStack Build Number 1", |
| 12 | + "sessionName" => "BStack-[Php] Sample Test", |
| 13 | + "local" => "false", |
| 14 | + "seleniumVersion" => "4.0.0", |
| 15 | + ), |
| 16 | + "browserName" => "Chrome", |
| 17 | + "browserVersion" => "latest", |
| 18 | + ); |
18 | 19 |
|
19 | | -$BROWSERSTACK_USERNAME = "BROWSERSTACK_USERNAME"; |
20 | | -$BROWSERSTACK_ACCESS_KEY = "BROWSERSTACK_ACCESS_KEY"; |
| 20 | + $BROWSERSTACK_USERNAME = "BROWSERSTACK_USERNAME"; |
| 21 | + $BROWSERSTACK_ACCESS_KEY = "BROWSERSTACK_ACCESS_KEY"; |
21 | 22 |
|
22 | | -$web_driver = RemoteWebDriver::create("https://$BROWSERSTACK_USERNAME:$BROWSERSTACK_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub",$caps); |
23 | | -try{ |
24 | | - $web_driver->get("https://bstackdemo.com/"); |
25 | | - $web_driver->wait(10000)->until(WebDriverExpectedCondition::titleIs("StackDemo")); |
26 | | - # getting text of the product |
27 | | - $product_on_page = $web_driver->wait(10000)->until(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::XPath("//*[@id='1']/p")))->getText(); |
28 | | - # clicking the 'Add to cart' button |
29 | | - $web_driver->wait(10000)->until(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::XPath("//*[@id='1']/div[4]")))->click(); |
30 | | - # checking whether the cart pane is present on webpage |
31 | | - $web_driver->wait(10000)->until(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::className("float-cart__content"))); |
32 | | - # getting text of the product |
33 | | - $product_in_cart = $web_driver->wait(10000)->until(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::XPath("//*[@id='__next']/div/div/div[2]/div[2]/div[2]/div/div[3]/p[1]")))->getText(); |
34 | | - # Setting the status of test as 'passed' or 'failed' based on the condition; if title of the web page starts with 'BrowserStack' |
35 | | - if ($product_on_page == $product_in_cart){ |
36 | | - $web_driver->executeScript('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"passed", "reason": "Product has been successfully added to the cart!"}}' ); |
37 | | - } else { |
38 | | - $web_driver->executeScript('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"failed", "reason": "Failed to add product to the cart or some elements might have failed to load."}}'); |
| 23 | + $web_driver = RemoteWebDriver::create("https://$BROWSERSTACK_USERNAME:$BROWSERSTACK_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub",$caps); |
| 24 | + try{ |
| 25 | + $web_driver->get("https://bstackdemo.com/"); |
| 26 | + $web_driver->wait(10000)->until(WebDriverExpectedCondition::titleIs("StackDemo")); |
| 27 | + # getting text of the product |
| 28 | + $product_on_page = $web_driver->wait(10000)->until(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::XPath("//*[@id='1']/p")))->getText(); |
| 29 | + # clicking the 'Add to cart' button |
| 30 | + $web_driver->wait(10000)->until(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::XPath("//*[@id='1']/div[4]")))->click(); |
| 31 | + # checking whether the cart pane is present on webpage |
| 32 | + $web_driver->wait(10000)->until(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::className("float-cart__content"))); |
| 33 | + # getting text of the product |
| 34 | + $product_in_cart = $web_driver->wait(10000)->until(WebDriverExpectedCondition::presenceOfElementLocated(WebDriverBy::XPath("//*[@id='__next']/div/div/div[2]/div[2]/div[2]/div/div[3]/p[1]")))->getText(); |
| 35 | + # Setting the status of test as 'passed' or 'failed' based on the condition; if title of the web page starts with 'BrowserStack' |
| 36 | + if ($product_on_page == $product_in_cart){ |
| 37 | + $web_driver->executeScript('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"passed", "reason": "Product has been successfully added to the cart!"}}' ); |
| 38 | + } else { |
| 39 | + $web_driver->executeScript('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"failed", "reason": "Failed to add product to the cart or some elements might have failed to load."}}'); |
| 40 | + } |
39 | 41 | } |
40 | | -} |
41 | | -catch(Exception $e){ |
42 | | - echo 'Message: ' .$e->getMessage(); |
43 | | -} |
44 | | -$web_driver->quit(); |
| 42 | + catch(Exception $e){ |
| 43 | + echo 'Message: ' .$e->getMessage(); |
| 44 | + } |
| 45 | + $web_driver->quit(); |
45 | 46 | ?> |
0 commit comments