Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration of E2E tests to accomplish 80% test coverage 🚀 #373

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
39 changes: 39 additions & 0 deletions __tests__/E2E/email.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Porto, 2022
// This code was made with love by Ana Rita
// for the curriculum unit of Comprehension and Evolution of Software at the
// master's in Software Engineering at the Faculty of Engineering of the University of Porto.
// Feel free to contact the author if any questions arise.
//
const { Builder, By } = require('selenium-webdriver');
const assert = require('assert');

describe('email', function () {
jest.setTimeout(30000);
let driver;
// eslint-disable-next-line no-unused-vars
let vars;
beforeEach(async function () {
driver = await new Builder().forBrowser('chrome').build();
vars = {};
});
afterEach(async function () {
await driver.quit();
});
it('email', async function () {
// Test name: email
// Step # | name | target | value
// 1 | open | / |
await driver.get('http://localhost:3000/');
// 2 | setWindowSize | 1792x1016 |
await driver.manage().window().setRect({ width: 1792, height: 1016 });
// 3 | click | linkText=Give Your Time |
await driver.findElement(By.linkText('Give Your Time')).click();
// 4 | click | css=.btn:nth-child(1) |
await driver.findElement(By.css('.btn:nth-child(1)')).click();
// 5 | assertText | css=.btn:nth-child(1) | Donate
assert(
(await driver.findElement(By.css('.btn:nth-child(1)')).getText()) ==
'Donate'
);
});
});
102 changes: 102 additions & 0 deletions __tests__/E2E/hotmealdonate.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// Porto, 2022
// This code was made with love by Francisco Bastos (https://www.linkedin.com/in/francisco-bastos-031369160/)
// for the curriculum unit of Comprehension and Evolution of Software at the
// master's in Software Engineering at the Faculty of Engineering of the University of Porto.
// Feel free to contact the author if any questions arise.
//
import { Builder, By, until } from 'selenium-webdriver';
import assert from 'assert';

describe('Hot meal donate', function () {
var webdriver = require('selenium-webdriver');

var driver = new webdriver.Builder()
.withCapabilities(webdriver.Capabilities.chrome())
.build();

jest.setTimeout(60000);
// eslint-disable-next-line no-unused-vars
let vars;
beforeEach(async function () {
driver = await new Builder().forBrowser('chrome').build();
vars = {};
});
afterEach(async function () {
await driver.quit();
});
it('Hot meal donate', async function () {
// Test name: Hot meal donate
// Step # | name | target | value
// 1 | open | / |
await driver.get('http://localhost:3000/');
// 2 | setWindowSize | 1920x1080 |
await driver.manage().window().setRect({ width: 1920, height: 1080 });
// 3 | click | xpath=//div[@id='__next']/div/main/div[2]/div/div/div/div/div/div/button |
await driver
.findElement(
By.xpath(
"//div[@id='__next']/div/main/div[2]/div/div/div/div/div/div/button"
)
)
.click();
// Apply timeout for 10 seconds
await driver.manage().setTimeouts({ implicit: 10000 });
// 4 | click | xpath=//div[@id='email-fieldset']/div/div/div/div/span/input |
await driver
.findElement(
By.xpath("//div[@id='email-fieldset']/div/div/div/div/span/input")
)
.click();
// 5 | type | xpath=//div[@id='email-fieldset']/div/div/div/div/span/input | [email protected]
await driver
.findElement(
By.xpath("//div[@id='email-fieldset']/div/div/div/div/span/input")
)
.sendKeys('[email protected]');
// 6 | click | xpath=//div[@id='cardNumber-fieldset']/div/div/div/span/input |
await driver
.findElement(
By.xpath("//div[@id='cardNumber-fieldset']/div/div/div/span/input")
)
.click();
// 7 | type | xpath=//fieldset/div/div/div/div/span/input | 6011 1111 1111 1117
await driver
.findElement(By.xpath('//fieldset/div/div/div/div/span/input'))
.sendKeys('6011 1111 1111 1117');
// 8 | type | xpath=//div[2]/div/div/span/input | 11 / 26
await driver
.findElement(By.xpath('//div[2]/div/div/span/input'))
.sendKeys('11 / 26');
// 9 | type | xpath=//div[@id='billingName-fieldset']/div/div/div/span/input | Francisco
await driver
.findElement(
By.xpath("//div[@id='billingName-fieldset']/div/div/div/span/input")
)
.sendKeys('Francisco');
// 10 | click | xpath=//div[@id='cardNumber-fieldset']/div[3]/div/div/span/input |
await driver
.findElement(
By.xpath("//div[@id='cardNumber-fieldset']/div[3]/div/div/span/input")
)
.click();
// 11 | type | xpath=//div[3]/div/div/span/input | 123
await driver
.findElement(By.xpath('//div[3]/div/div/span/input'))
.sendKeys('123');
// 12 | click | xpath=//button/div[3] |
await driver.findElement(By.xpath('//button/div[3]')).click();
// 13 | waitForElementPresent | xpath=//h1[contains(.,'Thank You!')] | 60000
await driver.wait(
until.elementLocated(By.xpath("//h1[contains(.,'Thank You!')]")),
60000
);
// 14 | assertText | //*[@id="__next"]/html/body/div/div[1]/div/div/h1 | Thank You!
assert(
(await driver
.findElement(
By.xpath('//*[@id="__next"]/html/body/div/div[1]/div/div/h1')
)
.getText()) == 'Thank You!'
);
});
});
39 changes: 39 additions & 0 deletions __tests__/E2E/hotmeallearnmore.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Porto, 2022
// This code was made with love by Francisco Bastos (https://www.linkedin.com/in/francisco-bastos-031369160/)
// for the curriculum unit of Comprehension and Evolution of Software at the
// master's in Software Engineering at the Faculty of Engineering of the University of Porto.
// Feel free to contact the author if any questions arise.
//
import { Builder, By } from 'selenium-webdriver';
import assert from 'assert';

describe('Hot meal learn more', function () {
jest.setTimeout(60000);
let driver;
// eslint-disable-next-line no-unused-vars
let vars;
beforeEach(async function () {
driver = await new Builder().forBrowser('chrome').build();
vars = {};
});
afterEach(async function () {
await driver.quit();
});
it('Hot meal learn more', async function () {
// Test name: Hot meal learn more
// Step # | name | target | value
// 1 | open | / |
await driver.get('http://localhost:3000/');
// 2 | setWindowSize | 1920x1080 |
await driver.manage().window().setRect({ width: 1920, height: 1080 });
// 3 | click | xpath=//button[contains(.,'Learn More')] |
await driver
.findElement(By.xpath("//button[contains(.,'Learn More')]"))
.click();
// 4 | assertText | xpath=//h1/div | Free Food Boxes for Hungry Families. Every Saturday!
assert(
(await driver.findElement(By.xpath('//h1/div')).getText()) ==
'Free Food Boxes for Hungry Families. Every Saturday!'
);
});
});
112 changes: 112 additions & 0 deletions __tests__/E2E/makeadonation.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// Porto, 2022
// This code was made with love by Francisco Bastos (https://www.linkedin.com/in/francisco-bastos-031369160/)
// for the curriculum unit of Comprehension and Evolution of Software at the
// master's in Software Engineering at the Faculty of Engineering of the University of Porto.
// Feel free to contact the author if any questions arise.
//
import { Builder, By, until } from 'selenium-webdriver';
import assert from 'assert';

describe('Make a donation', function () {
jest.setTimeout(60000);
let driver;
// eslint-disable-next-line no-unused-vars
let vars;
beforeEach(async function () {
driver = await new Builder().forBrowser('chrome').build();
vars = {};
});
afterEach(async function () {
await driver.quit();
});
it('Make a donation', async function () {
// Test name: Make a donation
// Step # | name | target | value
// 1 | open | / |
await driver.get('http://localhost:3000/');
// 2 | setWindowSize | 1920x1080 |
await driver.manage().window().setRect({ width: 1920, height: 1080 });
// 3 | click | xpath=//input |
await driver.findElement(By.xpath('//input')).click();
// 4 | click | xpath=//label[contains(.,'People of Color in Need')] |
await driver
.findElement(By.xpath("//label[contains(.,'People of Color in Need')]"))
.click();
// 5 | click | xpath=//label[contains(.,'Immigrants in Need')] |
await driver
.findElement(By.xpath("//label[contains(.,'Immigrants in Need')]"))
.click();
// 6 | click | xpath=//label[contains(.,'Seniors in Need')] |
await driver
.findElement(By.xpath("//label[contains(.,'Seniors in Need')]"))
.click();
// Apply timeout for 10 seconds
await driver.manage().setTimeouts({ implicit: 10000 });
// 7 | click | xpath=//select |
await driver.findElement(By.xpath('//select')).click();
// 8 | select | css=#amount and xpath=//option[. = '$5'] | label=$5
{
const dropdown = await driver.findElement(By.css('#amount'));
await dropdown.findElement(By.xpath("//option[. = '$5']")).click();
}
// 9 | click | xpath=//form/div/button[2] |
await driver.findElement(By.xpath('//form/div/button[2]')).click();
// 10 | click | xpath=//input[@id='email'] |
await driver.findElement(By.xpath("//input[@id='email']")).click();
// 11 | type | xpath=//input[@id='email'] | [email protected]
await driver
.findElement(By.xpath("//input[@id='email']"))
.sendKeys('[email protected]');
// 12 | click | xpath=//div[@id='cardNumber-fieldset']/div/div/div/span/input |
await driver
.findElement(
By.xpath("//div[@id='cardNumber-fieldset']/div/div/div/span/input")
)
.click();
// 13 | type | xpath=//fieldset/div/div/div/div/span/input | 6011 1111 1111 1117
await driver
.findElement(By.xpath('//fieldset/div/div/div/div/span/input'))
.sendKeys('6011 1111 1111 1117');
// 14 | type | xpath=//div[@id='cardNumber-fieldset']/div[2]/div/div/span/input | 11 / 26
await driver
.findElement(
By.xpath("//div[@id='cardNumber-fieldset']/div[2]/div/div/span/input")
)
.sendKeys('11 / 26');
// 15 | type | xpath=//div[@id='cardNumber-fieldset']/div[3]/div/div/span/input | 123
await driver
.findElement(
By.xpath("//div[@id='cardNumber-fieldset']/div[3]/div/div/span/input")
)
.sendKeys('123');
// 16 | type | xpath=//div[3]/div/div/div/div/div[2]/div/div/div/div/span/input | Francisco
await driver
.findElement(
By.xpath('//div[3]/div/div/div/div/div[2]/div/div/div/div/span/input')
)
.sendKeys('Francisco');
// 17 | click | xpath=//div[3]/div/div/span/input |
await driver.findElement(By.xpath('//div[3]/div/div/span/input')).click();
// 18 | click | xpath=//div[@id='root']/div/div/div[2]/div/div[2]/form/div[2]/div[2]/button/div[3] |
await driver
.findElement(
By.xpath(
"//div[@id='root']/div/div/div[2]/div/div[2]/form/div[2]/div[2]/button/div[3]"
)
)
.click();
// 19 | waitForElementPresent | xpath=//h1[contains(.,'Thank You!')] | 60000
await driver.wait(
until.elementLocated(By.xpath("//h1[contains(.,'Thank You!')]")),
60000
);
// 20 | assertText | //*[@id="__next"]/html/body/div/div[1]/div/div/h1 | Thank You!
assert(
(await driver
.findElement(
By.xpath('//*[@id="__next"]/html/body/div/div[1]/div/div/h1')
)
.getText()) == 'Thank You!'
);
});
});
31 changes: 31 additions & 0 deletions __tests__/E2E/makesanemptydonation.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Porto, 2022
// This code was made with love by Francisco Bastos (https://www.linkedin.com/in/francisco-bastos-031369160/)
// for the curriculum unit of Comprehension and Evolution of Software at the
// master's in Software Engineering at the Faculty of Engineering of the University of Porto.
// Feel free to contact the author if any questions arise.
//
import { Builder, By } from 'selenium-webdriver';

describe('Makes an empty donation', function () {
jest.setTimeout(60000);
let driver;
// eslint-disable-next-line no-unused-vars
let vars;
beforeEach(async function () {
driver = await new Builder().forBrowser('chrome').build();
vars = {};
});
afterEach(async function () {
await driver.quit();
});
it('Makes an empty donation', async function () {
// Test name: Makes an empty donation
// Step # | name | target | value
// 1 | open | / |
await driver.get('http://localhost:3000/');
// 2 | setWindowSize | 1920x1080 |
await driver.manage().window().setRect({ width: 1920, height: 1080 });
// 3 | click | xpath=//form/div/button |
await driver.findElement(By.xpath('//form/div/button')).click();
});
});
56 changes: 56 additions & 0 deletions __tests__/E2E/makesanemptydonation2.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Porto, 2022
// This code was made with love by Francisco Bastos (https://www.linkedin.com/in/francisco-bastos-031369160/)
// for the curriculum unit of Comprehension and Evolution of Software at the
// master's in Software Engineering at the Faculty of Engineering of the University of Porto.
// Feel free to contact the author if any questions arise.
//
const { By } = require('selenium-webdriver'),
webdriver = require('selenium-webdriver');

describe('Makes an empty donation 2', function () {
let driver;
// eslint-disable-next-line no-unused-vars
let vars;

beforeEach(async function () {
driver = new webdriver.Builder()
.withCapabilities(webdriver.Capabilities.chrome())
.build();
vars = {};
});
afterEach(async function () {
await driver.quit();
});
jest.setTimeout(60000);
it('Makes an empty donation 2', async function () {
// Test name: Makes an empty donation 2
// Step # | name | target | value
// 1 | open | / |
await driver.get('http://localhost:3000/');
// 2 | setWindowSize | 1920x1080 |
await driver.manage().window().setRect({ width: 1920, height: 1080 });
// 3 | click | xpath=//div[@id='__next']/div/main/div/div[2]/div/div/div[3]/form/div/div[5]/select |
await driver
.findElement(
By.xpath(
"//div[@id='__next']/div/main/div/div[2]/div/div/div[3]/form/div/div[5]/select"
)
)
.click();
// 4 | click | xpath=//select |
await driver.findElement(By.xpath('//select')).click();
// 5 | select | xpath=//html/body/div[2]/div/main/div[1]/div[2]/div/div/div[3]/form/div/div[5]/select/option[2] | label=$5
{
const dropdown = await driver.findElement(
By.xpath(
'/html/body/div[1]/div/main/div[1]/div[2]/div/div/div[3]/form/div/div[5]/select/option[2]'
)
);
await dropdown.findElement(By.xpath("//option[. = '$5']")).click();
}
// 6 | click | xpath=//form/div/button |
await driver.findElement(By.css('.btn-accent:nth-child(7)')).click();
// 7 | webdriverChooseOkOnVisibleConfirmation | xpath=//body/div[4]/div/div |
// await driver.switchTo().alert().accept();
});
});
Loading