Created
May 18, 2016 10:06
-
-
Save adamelso/b44e43baac53cf5a512a5bc392bd2c5e to your computer and use it in GitHub Desktop.
PayPal Express Checkout - Behat Mink UI test with Selenium 2 Driver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class CheckoutWithPaypalContext extends MinkContext | |
{ | |
/** | |
* @When /^I choose to pay with PayPal$/ | |
*/ | |
public function iChooseToPayWithPayPal() | |
{ | |
$this->findAndWaitForElementToBeVisibleThenClick("//a[@id = 'paypal']"); | |
sleep(5); | |
// Okay, now we're in PayPal | |
$page = $this->getSession()->getPage(); | |
$iframes = $page->findAll('xpath', '//iframe'); | |
/** | |
* Get the first frame, there might be more than one. | |
* | |
* @var NodeElement $payPalIframe | |
*/ | |
$payPalIframe = $iframes[0]; | |
// Then we switch to it. Mink works on a document-by-document basis. | |
$this->getSession()->getDriver()->switchToIFrame($payPalIframe->getAttribute('name')); | |
$payPalEmail = $page->findById('email'); | |
$payPalPassword = $page->findById('password'); | |
$doLogin = $page->findById('btnLogin'); | |
$payPalEmail->setValue('[email protected]'); | |
$payPalPassword->setValue('420420'); | |
$doLogin->click(); | |
// Ridiculous, but PayPal takes a few seconds to process. | |
sleep(10); | |
$doConfirm = null; | |
$iteration = 0; | |
while (null === $doConfirm && $iteration <= 5) { | |
++$iteration; | |
sleep(5); | |
$doConfirm = $this->getSession()->getPage()->findById('confirmButtonTop'); | |
} | |
$doConfirm->click(); | |
// Return back to the shop. | |
$this->getSession()->wait(10000, '"undefined" !== typeof someVariableIKnowExistsOnlyOnMySite'); | |
} | |
} |
Hoo many thanks for this.
I must mention that I had to switch back from the iframe to the regular window after the login
$this->getSession()->getDriver()->switchToIFrame();
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome, thanks for this! 👍