-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
René Gust
committed
Dec 16, 2024
1 parent
95f46cb
commit a1903a9
Showing
23 changed files
with
707 additions
and
15 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace OxidSolutionCatalysts\PayPal\Twig; | ||
|
||
use Twig\Extension\AbstractExtension; | ||
use Twig\TwigFunction; | ||
|
||
class TestIdExtension extends AbstractExtension | ||
{ | ||
public function getFunctions() | ||
{ | ||
return [ | ||
new TwigFunction('render_test_id', [$this, 'renderTestId']), | ||
]; | ||
} | ||
|
||
public function renderTestId(string $testId): string | ||
{ | ||
return sprintf(' data-test-id="%s"', htmlspecialchars($testId, ENT_QUOTES)); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © OXID eSales AG. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OxidSolutionCatalysts\PayPal\Tests\Codeception\Acceptance; | ||
|
||
use OxidSolutionCatalysts\PayPal\Tests\Codeception\AcceptanceTester; | ||
use OxidSolutionCatalysts\PayPal\Tests\Codeception\Page\VirtualPage; | ||
|
||
/** | ||
* @group osc_paypal | ||
* @group osc_paypal_checkout | ||
* @group osc_paypal_checkout_acdc | ||
* @group osc_paypal_remote_login | ||
*/ | ||
final class GooglePayCheckoutCest extends BaseCest | ||
{ | ||
public function checkoutWithGooglePay(AcceptanceTester $I): void | ||
{ | ||
$I->wantToTest('checkout with google pay'); | ||
|
||
$I->resizeWindow(1024, 576); | ||
$virtualPage = new VirtualPage($I); | ||
$virtualPage->openShopAndLogin(); | ||
|
||
$basketPage = $virtualPage->addProductToBasket(); | ||
|
||
$basketPage->checkout(); | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace OxidSolutionCatalysts\PayPal\Tests\Codeception\Page; | ||
|
||
use OxidEsales\Codeception\Page\Page; | ||
|
||
class BasketPage extends Page | ||
{ | ||
private const SUBMIT_BUTTON_SELECTOR = '[data-test-id="checkout-button"]'; | ||
public function checkout() | ||
{ | ||
$this->user->scrollTo(self::SUBMIT_BUTTON_SELECTOR); | ||
$this->user->click(self::SUBMIT_BUTTON_SELECTOR); | ||
$this->user->see('#user_form'); | ||
} | ||
|
||
public function isSubmitButtonVisible(): void | ||
{ | ||
$this->user->scrollTo(self::SUBMIT_BUTTON_SELECTOR); | ||
$this->user->waitForElement(self::SUBMIT_BUTTON_SELECTOR); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © OXID eSales AG. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OxidSolutionCatalysts\PayPal\Tests\Codeception\Page; | ||
|
||
use Codeception\Util\Fixtures; | ||
use OxidEsales\Codeception\Module\Translation\Translator; | ||
use OxidEsales\Codeception\Page\Home; | ||
use OxidEsales\Codeception\Page\Page; | ||
use OxidEsales\Codeception\Step\Basket; | ||
|
||
class VirtualPage extends Page | ||
{ | ||
public function addProductToBasket(): BasketPage | ||
{ | ||
$product = Fixtures::get('product'); | ||
$basketStep = new Basket($this->user); | ||
|
||
$basketStep->addProductToBasketAndOpenBasket($product['oxid'], $product['amount'], 'basket'); | ||
|
||
$basketPage = new BasketPage($this->user); | ||
$basketPage->isSubmitButtonVisible(); | ||
|
||
return $basketPage; | ||
} | ||
|
||
public function openShopAndLogin(): Home | ||
{ | ||
$homePage = $this->user->openShop()->loginUser(Fixtures::get('userName'), Fixtures::get('userPassword')); | ||
|
||
$this->user->waitForText(Translator::translate('INFORMATION')); | ||
|
||
return $homePage; | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {PopUpCommand} from "./PopUpCommand"; | ||
import {PopUpCaptureCommand} from "./PopUpCaptureCommand"; | ||
|
||
export class CommandManager { | ||
popupReference: any = {} | ||
init() { | ||
PopUpCaptureCommand.init(this.popupReference); | ||
PopUpCommand.init(this.popupReference); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
export class PopUpCaptureCommand { | ||
static init(popupReference: any) { | ||
Cypress.Commands.add('capturePopup', () => { | ||
const originalWindowOpen = window.open; | ||
|
||
// Override the window.open method | ||
window.open = function(url, target, features) { | ||
console.log('window.open called with URL:', url); | ||
console.log('Target:', target); | ||
console.log('Features:', features); | ||
|
||
return originalWindowOpen.apply(this, arguments); // Call the original window.open | ||
}; | ||
cy.window().then((win) => { | ||
//cy.stub(win, 'open').as('popupStub'); | ||
|
||
|
||
// Stub `window.open` to simulate the PayPal popup | ||
/*cy.window().then((win) => { | ||
cy.stub(win, 'open').callsFake((url) => { | ||
expect(url).to.include('paypal.com'); // Assert the correct URL is used | ||
console.log(url) | ||
return { | ||
document: { | ||
write: Cypress.sinon.stub(), // Stub methods you expect to be called on the popup | ||
}, | ||
close: Cypress.sinon.stub(), | ||
}; | ||
}).as('popupStub'); | ||
});*/ | ||
|
||
|
||
|
||
const open = win.open | ||
cy | ||
.stub(win, 'open') | ||
.callsFake((...params) => { | ||
// Capture the reference to the popup | ||
popupReference.popup = open(...params) | ||
return popupReference.popup | ||
}) | ||
}) | ||
}) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export class PopUpCommand { | ||
static init(popupReference: any) { | ||
Cypress.Commands.add("popup", () => { | ||
const popup = Cypress.$(popupReference.popup.document) | ||
return cy.wrap(popup.contents().find('body')) | ||
}) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
declare namespace Cypress { | ||
interface Chainable { | ||
/** | ||
* Custom command to interact with popups | ||
* @example cy.popup() | ||
*/ | ||
popup(): Chainable<JQuery<HTMLElement>>; | ||
|
||
/** | ||
* Custom command to capture popup | ||
* @example cy.capturePopup() | ||
*/ | ||
capturePopup(): Chainable<JQuery<HTMLElement>>; | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
tests/CypressTests/cypress/e2e/checkout-with-register-and-paypal-express.cy.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { PageFactoryService } from "../service/PageFactoryService"; | ||
import { ShopDomainService } from "../service/ShopDomainService"; | ||
import {CommandManager} from "../command/CommandManager"; | ||
|
||
describe('template spec', () => { | ||
it('passes', () => { | ||
cy.log(JSON.stringify(Cypress.config(), null, 2)); | ||
const commandManager = new CommandManager(); | ||
commandManager.init(); | ||
cy.capturePopup() | ||
|
||
cy.visit(ShopDomainService.getShopUrl()) | ||
|
||
PageFactoryService.getStartPage(cy).putFirstNewItemInBasket() | ||
|
||
PageFactoryService.getBasketPage(cy).clickExpressButton() | ||
}) | ||
}) |
Oops, something went wrong.