Skip to content

Commit

Permalink
Merge pull request #4153 from dolbi-digital/WV-694-Automate-negative-…
Browse files Browse the repository at this point in the history
…scenarious-for-Donate-page

Added negative scenarious, used eslint to improve code
  • Loading branch information
fdiazq authored Oct 30, 2024
2 parents 605ca63 + 494ceab commit 7679f6c
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 43 deletions.
29 changes: 22 additions & 7 deletions tests/browserstack_automation/page_objects/donate.page.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { $, driver } from '@wdio/globals';
import { $, driver, expect, path } from '@wdio/globals';
import Page from './page';

class DonatePage extends Page {
Expand All @@ -11,13 +11,13 @@ class DonatePage extends Page {
}

async checkLinkAndTite () {
await expect(driver).toHaveUrl(path + '/donate');
await expect(driver).toHaveUrl(`${path}/donate`);
await expect(driver).toHaveTitle('Donate - WeVote');
}

getDonateHeader () {
return $('#want_to_vote');
}
}

getFirstParagraph () {
return $('(//*[@id="first_paragraph"])[2]');
Expand All @@ -36,7 +36,7 @@ class DonatePage extends Page {
}

getDonateAmountButton (amount) {
return $('//span[(text()=' + amount + ')]');
return $(`//span[text()="${amount}"]`);
}

getDonorBoxIFrame () {
Expand Down Expand Up @@ -115,6 +115,10 @@ class DonatePage extends Page {
return $('label[for="donation_donation_honor_attributes_honor_type_memory"]');
}

getPostalMailRadioButton () {
return $('label[for="donation_donation_honor_attributes_notify_type_postal"]');
}

getFirstName () {
return $('#donation_first_name');
}
Expand All @@ -141,15 +145,15 @@ class DonatePage extends Page {

getMonthlyAmount () {
return $('(//span[@class="donation-amt"])[3]');
}
}

getQuarterlyAmount () {
return $('(//span[@class="donation-amt"])[4]');
}
}

getAnnuallyAmount () {
return $('(//span[@class="donation-amt"])[5]');
}
}

getQuarterlyButton () {
return $('#plan_duration_quarterly');
Expand All @@ -175,6 +179,17 @@ class DonatePage extends Page {
return $('#donation_donation_honor_attributes_recipient_message');
}

getCustomAmountError () {
return $('.desc.invalid');
}

getFieldRequiredError (number) {
return $(`(//div[@class="dwm-error"])[${number}]`);
}

getFixErrors () {
return $('#info-error');
}
}

export default new DonatePage();
136 changes: 100 additions & 36 deletions tests/browserstack_automation/specs/DonatePage.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
import { driver, expect, $ } from '@wdio/globals';
import { driver, expect } from '@wdio/globals';
import ReadyPage from '../page_objects/ready.page';
import DonatePage from '../page_objects/donate.page';

/* eslint-disable no-undef
This eslint-disable turns off warnings for describe() and it()
We don't need those warnings, because describe() and it() are available at runtime
Refer to https://webdriver.io/docs/pageobjects for guidance */
/* eslint-disable no-undef */
// This eslint-disable turns off warnings for describe() and it()
// We don't need those warnings, because describe() and it() are available at runtime
// https://webdriver.io/docs/pageobjects

var fillDonationForm = async (name, lastName, email) => {
const requiredError = 'This field is required';
const validEmailError = 'Please enter a valid email address';
const validEmail = '[email protected]';

const fillDonationForm = async (name, lastName, email) => {
await DonatePage.getFirstName().setValue(name);
await DonatePage.getLasttName().setValue(lastName);
await DonatePage.getEmail().setValue(email);
(await DonatePage.getNextButton()).click();
};

async function nextButtonScrollIntoView() {
async function nextButtonScrollIntoView () {
const nextButton = await DonatePage.getNextButton();
await nextButton.scrollIntoView();
await expect(nextButton).toBeDisplayed();
await nextButton.click();
}

var checkAmounts = async (interval, processingFee, fullAmount, withoutFeeAmount, amountLabel) => {
const elementText = await DonatePage.getIntervalLabel().getText();
const amount = await amountLabel;
expect(elementText.includes(interval));
await expect(DonatePage.getProcessingFeeLabel()).toHaveText(processingFee);
await expect(amount).toHaveText(fullAmount);
driver.pause(3000);
(await DonatePage.getOptionalFeesCheckbox()).click();
driver.pause(3000);
await expect(amount).toHaveText(withoutFeeAmount);

(await DonatePage.getDonateButton()).click();
await expect(driver).toHaveTitle('Log in to your PayPal account');
};
const checkAmounts = async (interval, processingFee, fullAmount, withoutFeeAmount, amountLabel) => {
const elementText = await DonatePage.getIntervalLabel().getText();
const amount = await amountLabel;
expect(elementText.includes(interval));
await expect(DonatePage.getProcessingFeeLabel()).toHaveText(processingFee);
await expect(amount).toHaveText(fullAmount);
(await DonatePage.getOptionalFeesCheckbox()).click();
await expect(amount).toHaveText(withoutFeeAmount);

(await DonatePage.getDonateButton()).click();
await expect(driver).toHaveTitle('Log in to your PayPal account');
};

describe('DonatePage', () => {

// Donate_001
it('verifyDonatePageAfterClickDonateLinks', async () => {
await ReadyPage.load();
Expand All @@ -55,20 +55,20 @@ describe('DonatePage', () => {
it('verifyTextAndDonationWidget', async () => {
await DonatePage.load();
await expect(DonatePage.getDonateHeader()).toHaveText('Want more Americans to vote?');
await expect(DonatePage.getFirstParagraph()).toHaveText('Thank you for being a voter! For every $10 donated, '
+ 'you help 50 Americans be voters too.');
await expect(DonatePage.getSecondParagraph()).toHaveText('Our budgets are small,so every tax-deductible '
+ 'donation helps us reach more voters.'
+ '\n\n'
+ 'Expenses include server costs ($600 - $2,500 per '
+ 'month), data fees (~$40,000 per year), collaboration tools and other hard costs.');
await expect(DonatePage.getFirstParagraph()).toHaveText('Thank you for being a voter! For every $10 donated, ' +
'you help 50 Americans be voters too.');
await expect(DonatePage.getSecondParagraph()).toHaveText('Our budgets are small,so every tax-deductible ' +
'donation helps us reach more voters.' +
'\n\n' +
'Expenses include server costs ($600 - $2,500 per ' +
'month), data fees (~$40,000 per year), collaboration tools and other hard costs.');
});

// Donate_003
it('verifyNonProfitExplorerLink', async () => {
await DonatePage.load();
const element = await DonatePage.getTextLink();
await driver.execute("arguments[0].click();", element);
await driver.execute('arguments[0].click();', element);
const allWindowHandles = await driver.getWindowHandles();
await driver.switchToWindow(allWindowHandles[allWindowHandles.length - 1]);
await expect(driver).toHaveTitle('We Vote - Nonprofit Explorer - ProPublica');
Expand All @@ -81,11 +81,11 @@ describe('DonatePage', () => {

(await DonatePage.getOneTimeButton()).click();
(await DonatePage.getDonateAmountButton(120)).click();

const checkbox = await DonatePage.getCommentCheckbox();
const isChecked = await checkbox.isSelected();
if (!isChecked) {
await checkbox.click();
await checkbox.click();
}

await DonatePage.getCommentField().setValue('Hello, WeVote!');
Expand All @@ -95,7 +95,7 @@ describe('DonatePage', () => {
await nextButtonScrollIntoView();

await DonatePage.getPayPalButton().click();
await expect(DonatePage.getOneTimeLabel()).toHaveText("One-time");
await expect(DonatePage.getOneTimeLabel()).toHaveText('One-time');
await expect(DonatePage.getOneTimeAmount()).toHaveText('$125.17');

await driver.switchToFrame(await DonatePage.getPayPalIFrame());
Expand Down Expand Up @@ -131,7 +131,7 @@ describe('DonatePage', () => {
const checkbox = await DonatePage.getDisplayDonationCheckbox();
const isChecked = await checkbox.isSelected();
if (!isChecked) {
await checkbox.click();
await checkbox.click();
}

await nextButtonScrollIntoView();
Expand Down Expand Up @@ -186,10 +186,74 @@ describe('DonatePage', () => {
(await DonatePage.getDisplayFirstNameCheckbox()).click();
await expect(DonatePage.getHideDonationAmountCheckbox()).not.toBeChecked();
(await DonatePage.getHideDonationAmountCheckbox()).click();

await nextButtonScrollIntoView();
await fillDonationForm('Dmytro', 'Dolbilov', '[email protected]');
await checkAmounts('Anually', '$12.16', '$312.16', '$300', DonatePage.getAnnuallyAmount());
});


// Donate_008
it('verifyEmptyFieldsErrorMessagesFirstPage', async () => {
await DonatePage.load();
await driver.switchToFrame(await DonatePage.getDonorBoxIFrame());

(await DonatePage.getOneTimeButton()).click();
(await DonatePage.getCustomAmountField()).click();
await nextButtonScrollIntoView();
await expect(DonatePage.getCustomAmountError()).toHaveText('Please select or enter an amount');
(await DonatePage.getCustomAmountField()).setValue(4.99);
await nextButtonScrollIntoView();
await expect(DonatePage.getCustomAmountError()).toHaveText('Please enter an amount of at least $5');
(await DonatePage.getDedicateMyDonationCheckbox()).click();
await nextButtonScrollIntoView();
await expect(DonatePage.getFieldRequiredError(1)).toHaveText(requiredError);
await expect(DonatePage.getFieldRequiredError(2)).toHaveText(requiredError);
(await DonatePage.getCommentCheckbox()).click();
await nextButtonScrollIntoView();
await expect(DonatePage.getFieldRequiredError(3)).toHaveText(requiredError);
});

// Donate_009
it('verifyFirstLastEmailEmptyFields', async () => {
await DonatePage.load();
await driver.switchToFrame(await DonatePage.getDonorBoxIFrame());

await nextButtonScrollIntoView();
await nextButtonScrollIntoView();
await expect(DonatePage.getFieldRequiredError(1)).toHaveText(requiredError);
await expect(DonatePage.getFieldRequiredError(2)).toHaveText(requiredError);
await expect(DonatePage.getFieldRequiredError(3)).toHaveText(requiredError);
await expect(DonatePage.getFixErrors()).toHaveText('Please fix the errors above.');
});

// Donate_010
it('verifyValidEmail', async () => {
await DonatePage.load();
await driver.switchToFrame(await DonatePage.getDonorBoxIFrame());

(await DonatePage.getDedicateMyDonationCheckbox()).click();
(await DonatePage.getRecipientEmailField()).setValue(`${validEmail}1`);
await nextButtonScrollIntoView();
await expect(DonatePage.getFieldRequiredError(2)).toHaveText(validEmailError);
(await DonatePage.getHonoreeNameField()).setValue('John Wick');
(await DonatePage.getRecipientEmailField()).setValue(validEmail);
await nextButtonScrollIntoView();
(await DonatePage.getEmail()).setValue(validEmail.replace('@', ''));
await nextButtonScrollIntoView();
await expect(DonatePage.getFieldRequiredError(1)).toHaveText(validEmailError);
await expect(DonatePage.getFixErrors()).toHaveText('Please fix the errors above.');
});

// Donate_011 https://wevoteusa.atlassian.net/browse/WV-699 Uncomment when fixed
it('verifyPostalAddress', async () => {
await DonatePage.load();
await driver.switchToFrame(await DonatePage.getDonorBoxIFrame());

(await DonatePage.getDedicateMyDonationCheckbox()).click();
const postalRadiobox = await DonatePage.getPostalMailRadioButton();
await postalRadiobox.scrollIntoView();
await postalRadiobox.click();
await nextButtonScrollIntoView();
// await expect(DonatePage.getFieldRequiredError(2)).toHaveText(requiredError);
});
});

0 comments on commit 7679f6c

Please sign in to comment.