@@ -8,6 +8,7 @@ import urls from '../urls';
88 */
99import { PcpMerchant } from '../../resources' ;
1010import { generateRandomString } from '../helpers' ;
11+ import { expect } from 'playwright/test' ;
1112
1213export class Connection extends PcpSettingsPage {
1314 url = urls . pcp . connection ;
@@ -36,13 +37,11 @@ export class Connection extends PcpSettingsPage {
3637 name : 'Test payments with PayPal sandbox' ,
3738 } ) ;
3839 toggleToManualCredentialInputButton = ( ) =>
39- this . page . getByRole ( 'button' , {
40- name : 'Toggle to manual credential input' ,
41- } ) ;
40+ this . page . locator ( 'button[id="ppcp[toggle_manual_input]"]' ) ;
4241 documentationLink = ( ) =>
4342 this . page . getByRole ( 'link' , { name : 'documentation' , exact : true } ) ;
4443
45- sandboxCheckbox = ( ) => this . page . getByLabel ( 'Sandbox' , { exact : true } ) ;
44+ sandboxCheckbox = ( ) => this . page . locator ( '#ppcp-sandbox_on' ) ;
4645
4746 liveEmailAddressInput = ( ) => this . page . getByLabel ( 'Live Email address' ) ;
4847 liveMerchantIdInput = ( ) => this . page . getByLabel ( 'Live Merchant Id' ) ;
@@ -51,12 +50,13 @@ export class Connection extends PcpSettingsPage {
5150 this . page . locator ( 'input[name="ppcp\\[client_secret_production\\]"]' ) ;
5251
5352 sandboxEmailAddressInput = ( ) =>
54- this . page . getByLabel ( 'Sandbox Email address ' ) ;
53+ this . page . locator ( '#ppcp-merchant_email_sandbox ' ) ;
5554 sandboxMerchantIdInput = ( ) =>
56- this . page . getByLabel ( 'Sandbox Merchant Id' ) ;
57- sandboxClientIdInput = ( ) => this . page . getByLabel ( 'Sandbox Client Id' ) ;
55+ this . page . locator ( '#ppcp-merchant_id_sandbox' ) ;
56+ sandboxClientIdInput = ( ) =>
57+ this . page . locator ( '#ppcp-client_id_sandbox' ) ;
5858 sandboxSecretKeyInput = ( ) =>
59- this . page . locator ( 'input[name="ppcp\\ [client_secret_sandbox\\ ]"]' ) ;
59+ this . page . locator ( 'input[name="ppcp[client_secret_sandbox]"]' ) ;
6060
6161 statusConnected = ( ) => this . page . getByText ( 'Status: Connected' ) ;
6262 disconnectAccountButton = ( ) =>
@@ -101,43 +101,6 @@ export class Connection extends PcpSettingsPage {
101101 await this . saveChanges ( ) ;
102102 } ;
103103
104- /**
105- * Checks if merchant is connected
106- *
107- * @param data
108- */
109- isMerchantConnected = async ( data ? ) => {
110- if ( ! ( await this . disconnectAccountButton ( ) . isVisible ( ) ) ) {
111- return false ;
112- }
113-
114- const emailInput = this . sandboxEmailAddressInput ( ) ;
115- const merchantIdInput = this . sandboxMerchantIdInput ( ) ;
116- const clientIdInput = this . sandboxClientIdInput ( ) ;
117- const secretKeyInput = this . sandboxSecretKeyInput ( ) ;
118-
119- const emailInputValue = ( await emailInput . inputValue ( ) ) . trim ( ) ;
120- const merchantIdValue = ( await merchantIdInput . inputValue ( ) ) . trim ( ) ;
121- const clientIdValue = ( await clientIdInput . inputValue ( ) ) . trim ( ) ;
122- const secretKeyValue = ( await secretKeyInput . inputValue ( ) ) . trim ( ) ;
123-
124- if ( ! data ) {
125- return (
126- emailInputValue !== '' &&
127- merchantIdValue !== '' &&
128- clientIdValue !== '' &&
129- secretKeyValue !== ''
130- ) ;
131- }
132-
133- return (
134- emailInputValue === data . email &&
135- merchantIdValue === data . account_id &&
136- clientIdValue === data . client_id &&
137- secretKeyValue === data . client_secret
138- ) ;
139- } ;
140-
141104 /**
142105 * Connects PayPal merchant with options
143106 *
@@ -150,23 +113,46 @@ export class Connection extends PcpSettingsPage {
150113 enablePayUponInvoice : false ,
151114 }
152115 ) => {
116+ await this . page . waitForLoadState ( ) ;
153117 if ( options . enablePayUponInvoice ) {
154118 await this . onboardPayUponInvoiceCheckbox ( ) . check ( ) ;
155119 } else if ( await this . onboardPayUponInvoiceCheckbox ( ) . isVisible ( ) ) {
156120 await this . onboardPayUponInvoiceCheckbox ( ) . uncheck ( ) ;
157121 }
158122
159- await this . toggleToManualCredentialInputButton ( ) . click ( ) ;
160- await this . page . waitForTimeout ( 500 ) ;
161- await this . sandboxCheckbox ( ) . check ( ) ;
162- await this . sandboxEmailAddressInput ( ) . fill ( merchant . email ) ;
163- await this . sandboxMerchantIdInput ( ) . fill ( merchant . account_id ) ;
164- await this . sandboxClientIdInput ( ) . fill ( merchant . client_id ) ;
165- await this . sandboxSecretKeyInput ( ) . fill ( merchant . client_secret ) ;
166- await this . saveChangesButton ( ) . click ( ) ;
123+ const toggleToManualCredentialInputButton =
124+ this . toggleToManualCredentialInputButton ( ) ;
125+ await expect ( toggleToManualCredentialInputButton ) . toBeVisible ( ) ;
126+ await toggleToManualCredentialInputButton . click ( { force : true } ) ;
127+
128+ const sandboxCheckbox = this . sandboxCheckbox ( ) ;
129+ await expect ( sandboxCheckbox ) . toBeVisible ( ) ;
130+ await sandboxCheckbox . check ( { force : true } ) ;
131+ await expect ( this . sandboxCheckbox ( ) ) . toBeChecked ( ) ;
132+
133+ const sandboxEmailAddressInput = this . sandboxEmailAddressInput ( ) ;
134+ await expect ( sandboxEmailAddressInput ) . toBeVisible ( ) ;
135+ await sandboxEmailAddressInput . fill ( merchant . email ) ;
136+
137+ const sandboxMerchantIdInput = this . sandboxMerchantIdInput ( ) ;
138+ await expect ( sandboxMerchantIdInput ) . toBeVisible ( ) ;
139+ await sandboxMerchantIdInput . fill ( merchant . account_id ) ;
140+
141+ const sandboxClientIdInput = this . sandboxClientIdInput ( ) ;
142+ await expect ( sandboxClientIdInput ) . toBeVisible ( ) ;
143+ await sandboxClientIdInput . fill ( merchant . client_id ) ;
144+
145+ const sandboxSecretKeyInput = this . sandboxSecretKeyInput ( ) ;
146+ await expect ( sandboxSecretKeyInput ) . toBeVisible ( ) ;
147+ await sandboxSecretKeyInput . fill ( merchant . client_secret ) ;
148+
149+ const saveChangesButton = this . saveChangesButton ( ) ;
150+ await expect ( saveChangesButton ) . toBeVisible ( ) ;
151+ await saveChangesButton . click ( ) ;
167152 await this . page . waitForLoadState ( ) ;
168153 // make sure Connection page has been loaded:
169- await this . disconnectAccountButton ( ) . waitFor ( { state : 'visible' } ) ;
154+
155+ await expect ( this . disconnectAccountButton ( ) ) . toBeVisible ( ) ;
170156 await this . updateInvoicePrefix ( ) ;
171157 } ;
172158
@@ -177,31 +163,5 @@ export class Connection extends PcpSettingsPage {
177163 await this . saveChanges ( ) ;
178164 } ;
179165
180- /**
181- * Disconnects PayPal merchant
182- */
183- disconnectMerchant = async ( ) => {
184- const disconnectButton = this . disconnectAccountButton ( ) ;
185-
186- if ( await disconnectButton . isVisible ( ) ) {
187- await disconnectButton . click ( ) ;
188- }
189- await this . page . waitForLoadState ( ) ;
190- // make sure Account Setup page has been loaded:
191- await this . toggleToManualCredentialInputButton ( ) . waitFor ( {
192- state : 'visible' ,
193- } ) ;
194- } ;
195-
196- clearDB = async ( ) => {
197- this . page . on ( 'dialog' , ( dialog ) => dialog . accept ( ) ) ;
198- await this . clearNowButton ( ) . click ( ) ;
199- await this . page . waitForLoadState ( ) ;
200- // make sure Account Setup page has been loaded:
201- await this . toggleToManualCredentialInputButton ( ) . waitFor ( {
202- state : 'visible' ,
203- } ) ;
204- } ;
205-
206166 // Assertions
207167}
0 commit comments