├── .github
└── workflows
│ └── main.yml
├── .gitignore
├── README.md
├── allure-results
├── 0f1e83c1-52db-411a-b33b-83d22031b8eb-container.json
├── 2a1ada48-2b7d-4a08-b21d-0dbcfdd5e1c3-container.json
├── 42b06249-3f9b-482a-8498-cd7877e6e5d8-container.json
├── 67bd76b9-c91a-46cf-8a87-97eee76a159a-result.json
├── 6a7b5784-be9f-4955-832d-a1e74d104641-container.json
├── 966c8d76-ddd5-4b1c-b304-a22d2346e64d-container.json
├── 9aff6610-8ac8-48dd-9609-12e687060fd4-result.json
├── b3f629c8-265d-4d48-9d6a-4335ea9fd38a-attachment.png
├── c7c14a28-3c20-453a-a1c5-342959e336bc-container.json
├── categories.json
└── dcda5987-38e4-4d8f-98ab-03c82ada26b7-container.json
├── docs
├── README-pt_BR.md
└── imgs
│ └── report.png
├── jest.config.js
├── package-lock.json
├── package.json
└── tests
├── global
├── Setup.global.js
└── Teardown.global.js
├── pages
├── Base.page.js
├── CreateAccount.page.js
├── Home.page.js
├── MyAccount.page.js
└── SignIn.page.js
├── specs
├── createUser.spec.js
└── login.spec.js
└── utils
├── PlaywrightEnv.utils.js
└── Utils.js
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | name: CI for run UI tests and save report to gh-pages.
2 |
3 | on:
4 | push:
5 | pull_request:
6 |
7 | jobs:
8 | build-and-deploy:
9 | runs-on: ubuntu-latest
10 |
11 | steps:
12 | - name: Use Node.js 14
13 | uses: actions/setup-node@v2
14 | with:
15 | node-version: 14
16 |
17 | - name: Checkout
18 | uses: actions/checkout@v2.3.1
19 |
20 | - name: Install and exec tests
21 | run: npm ci && npm run test
22 | continue-on-error: true
23 |
24 | - name: Get allure history
25 | uses: actions/checkout@v2
26 | continue-on-error: true
27 | with:
28 | ref: gh-pages
29 | path: gh-pages
30 |
31 | - name: Allure Report action
32 | uses: simple-elf/allure-report-action@master
33 | with:
34 | allure_results: allure-results
35 | allure_history: allure-history/allure-history
36 | keep_reports: 5
37 |
38 | - name: Deploy report to Github Pages
39 | if: github.ref == 'refs/heads/main'
40 | uses: JamesIves/github-pages-deploy-action@4.1.4
41 | with:
42 | access_token: ${{ github.token }}
43 | branch: gh-pages
44 | folder: allure-history/allure-history
45 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
Architecture example using Playwright for UI tests.
2 |
3 | Para acessar a versão em Português do Brasil, basta clicar [aqui](/docs/README-pt_BR.md)! :brazil:
4 |
5 | This project was created for a architecture example of UI tests using Playwright + jest
6 |
7 | ## Technologies and tools used::
8 | - [JS](https://developer.mozilla.org/pt-BR/docs/Web/JavaScript)
9 | - [npm](https://www.npmjs.com/)
10 | - [playwright](https://playwright.dev/)
11 | - [jest](https://jestjs.io/)
12 |
13 | ## Files Structure
14 |
15 | 📦playwright-arch-example
16 | ┣ 📂allure-results
17 | ┃ ┣ 📜2094b072-0e34-4f06-856b-8ef4bd346faa-testsuite.xml
18 | ┃ ┗ 📜783b98b6-c65f-473d-9bd6-c785ed393d69-testsuite.xml
19 | ┣ 📂tests
20 | ┃ ┣ 📂pages
21 | ┃ ┃ ┣ 📜Base.page.js
22 | ┃ ┃ ┣ 📜CreateAccount.page.js
23 | ┃ ┃ ┣ 📜Home.page.js
24 | ┃ ┃ ┣ 📜MyAccount.page.js
25 | ┃ ┃ ┗ 📜SignIn.page.js
26 | ┃ ┣ 📂specs
27 | ┃ ┃ ┣ 📜createUser.spec.js
28 | ┃ ┃ ┗ 📜login.spec.js
29 | ┃ ┗ 📂utils
30 | ┃ ┃ ┗ 📜Utils.js
31 | ┣ 📜.gitignore
32 | ┣ 📜README.md
33 | ┣ 📜jest-playwright.config.js
34 | ┣ 📜jest.config.js
35 | ┣ 📜jest.setup.js
36 | ┣ 📜package-lock.json
37 | ┗ 📜package.json
38 |
39 | ## Run examples:
40 |
41 | - Install dependencies: ```npm i```
42 | - Run all tests: ```npm run test```
43 |
44 |
45 | ## Report:
46 | - Open report: ```npm run report:open```
47 | - _if the task not correctly run install allure-commandline e o allure by the global way: ```npm i -g allure-commandline allure```_
48 |
49 | 
50 |
--------------------------------------------------------------------------------
/allure-results/0f1e83c1-52db-411a-b33b-83d22031b8eb-container.json:
--------------------------------------------------------------------------------
1 | {"uuid":"0f1e83c1-52db-411a-b33b-83d22031b8eb","children":["4d71f10c-118e-49d0-868e-6ea77ab9e847"],"befores":[],"afters":[],"name":"createUser.spec.js"}
--------------------------------------------------------------------------------
/allure-results/2a1ada48-2b7d-4a08-b21d-0dbcfdd5e1c3-container.json:
--------------------------------------------------------------------------------
1 | {"uuid":"2a1ada48-2b7d-4a08-b21d-0dbcfdd5e1c3","children":["6a7b5784-be9f-4955-832d-a1e74d104641"],"befores":[],"afters":[],"name":"ROOT_DESCRIBE_BLOCK"}
--------------------------------------------------------------------------------
/allure-results/42b06249-3f9b-482a-8498-cd7877e6e5d8-container.json:
--------------------------------------------------------------------------------
1 | {"uuid":"42b06249-3f9b-482a-8498-cd7877e6e5d8","children":["67bd76b9-c91a-46cf-8a87-97eee76a159a"],"befores":[{"status":"passed","statusDetails":{},"stage":"finished","steps":[],"attachments":[],"parameters":[]},{"status":"passed","statusDetails":{},"stage":"finished","steps":[],"attachments":[],"parameters":[]}],"afters":[{"status":"passed","statusDetails":{},"stage":"finished","steps":[],"attachments":[],"parameters":[]}],"name":"Create an Account"}
--------------------------------------------------------------------------------
/allure-results/67bd76b9-c91a-46cf-8a87-97eee76a159a-result.json:
--------------------------------------------------------------------------------
1 | {"uuid":"67bd76b9-c91a-46cf-8a87-97eee76a159a","historyId":"da26169a53fa97d1cb5ccb41b4174d11","status":"passed","statusDetails":{},"stage":"finished","steps":[],"attachments":[],"parameters":[],"labels":[{"name":"thread","value":"1"},{"name":"parentSuite","value":"tests"},{"name":"package","value":"tests"},{"name":"suite","value":"specs"},{"name":"subSuite","value":"createUser.spec.js"}],"links":[],"start":1641166316715,"name":"Create an Account with success","fullName":"Create an Account with success","description":"\n### Test\n```typescript\nasync () => {\n const utils = new Utils();\n const homePage = new HomePage(page);\n const signInPage = new SignInPage(page);\n const createAccount = new CreateAccount(page);\n const myAccountPage = new MyAccountPage(page);\n const firstname = utils.getFirstname();\n const lastname = utils.getLastName();\n await homePage.navigate();\n await homePage.clickSignIn();\n await signInPage.insertEmailCreateAccount(utils.getRandomEmail());\n await signInPage.clickBtnCreateAccount();\n await createAccount.selectionMr();\n await createAccount.fillFirstname(firstname);\n await createAccount.fillLastname(lastname);\n await createAccount.fillPassword(\"teste123\");\n await createAccount.fillDateOfBirth(\"14\", \"5\", \"2000\");\n await createAccount.fillAddressFirstname(firstname);\n await createAccount.fillAddressLastname(lastname);\n await createAccount.fillAddressName(\"rua teste, 123\");\n await createAccount.fillCity(\"New York\");\n await createAccount.fillState(\"32\");\n await createAccount.fillPostCode(\"93210\");\n await createAccount.fillMobilePhone(\"51995484857\");\n await createAccount.clickBtnRegister();\n let username = await myAccountPage.getUsername();\n\n expect(username).toEqual(`${firstname} ${lastname}`);\n};\n\n```\n","stop":1641166331570}
--------------------------------------------------------------------------------
/allure-results/6a7b5784-be9f-4955-832d-a1e74d104641-container.json:
--------------------------------------------------------------------------------
1 | {"uuid":"6a7b5784-be9f-4955-832d-a1e74d104641","children":["9aff6610-8ac8-48dd-9609-12e687060fd4"],"befores":[{"status":"passed","statusDetails":{},"stage":"finished","steps":[],"attachments":[],"parameters":[]},{"status":"passed","statusDetails":{},"stage":"finished","steps":[],"attachments":[],"parameters":[]}],"afters":[{"status":"passed","statusDetails":{},"stage":"finished","steps":[],"attachments":[],"parameters":[]}],"name":"Login"}
--------------------------------------------------------------------------------
/allure-results/966c8d76-ddd5-4b1c-b304-a22d2346e64d-container.json:
--------------------------------------------------------------------------------
1 | {"uuid":"966c8d76-ddd5-4b1c-b304-a22d2346e64d","children":["42b06249-3f9b-482a-8498-cd7877e6e5d8"],"befores":[],"afters":[],"name":"ROOT_DESCRIBE_BLOCK"}
--------------------------------------------------------------------------------
/allure-results/9aff6610-8ac8-48dd-9609-12e687060fd4-result.json:
--------------------------------------------------------------------------------
1 | {"uuid":"9aff6610-8ac8-48dd-9609-12e687060fd4","historyId":"1d56e508348fecce58b681371baa781c","status":"failed","statusDetails":{"message":"expect(received).toEqual(expected) // deep equality\n","trace":"Expected: \"MY ACCOUNTT\"\nReceived: \"MY ACCOUNT\""},"stage":"finished","steps":[],"attachments":[{"name":"Screenshot","type":"image/png","source":"b3f629c8-265d-4d48-9d6a-4335ea9fd38a-attachment.png"}],"parameters":[],"labels":[{"name":"thread","value":"1"},{"name":"parentSuite","value":"tests"},{"name":"package","value":"tests"},{"name":"suite","value":"specs"},{"name":"subSuite","value":"login.spec.js"}],"links":[],"start":1641166300837,"name":"Do login with success","fullName":"Do login with success","description":"\n### Test\n```typescript\nasync () => {\n const homePage = new HomePage(page);\n const signInPage = new SignInPage(page);\n const myAccountPage = new MyAccountPage(page);\n await homePage.navigate();\n await homePage.clickSignIn();\n await signInPage.login(\"novoemailteste@gmail.com\", \"teste123\");\n let myAccountHeading = await myAccountPage.getHeading();\n\n expect(myAccountHeading).toEqual(\"MY ACCOUNTT\");\n};\n\n```\n","stop":1641166308555}
--------------------------------------------------------------------------------
/allure-results/b3f629c8-265d-4d48-9d6a-4335ea9fd38a-attachment.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maximilianoalves/playwright-js-arch-ui-test/ff7d0103c44bf3dee0c60934b83b43fe0fbc6122/allure-results/b3f629c8-265d-4d48-9d6a-4335ea9fd38a-attachment.png
--------------------------------------------------------------------------------
/allure-results/c7c14a28-3c20-453a-a1c5-342959e336bc-container.json:
--------------------------------------------------------------------------------
1 | {"uuid":"c7c14a28-3c20-453a-a1c5-342959e336bc","children":["966c8d76-ddd5-4b1c-b304-a22d2346e64d"],"befores":[],"afters":[],"name":"createUser.spec.js"}
--------------------------------------------------------------------------------
/allure-results/categories.json:
--------------------------------------------------------------------------------
1 | [{"name":"Response status failures","description":"Unexpected API response status code.","messageRegex":".*toHaveStatusCode.*","matchedStatuses":["failed"]},{"name":"Response time failures","description":"API responses that took longer than expected.","messageRegex":".*toHaveResponseTimeBelow.*","matchedStatuses":["failed"]},{"name":"JSON schema failures","description":"An object did not validate against an expected JSON schema.","messageRegex":".*toMatchSchema.*","matchedStatuses":["failed"]},{"name":"Property name failures","description":"An object had keys that were not camelCase.","messageRegex":".*toHaveCamelCase.*","matchedStatuses":["failed"]},{"name":"Snapshot failures","description":"Snapshot does not match the expected snapshot.","messageRegex":".*toMatchSnapshot.*","matchedStatuses":["failed"]},{"name":"Timed out","description":"The test exceeded the test threshold.","traceRegex":".*Exceeded timeout.*","matchedStatuses":["broken"]},{"name":"Updated JSON schemas","description":"Tests that have updated a JSON schema.","messageRegex":".*updated.*schema.*updated.*","matchedStatuses":["passed"]},{"name":"Updated snapshots","description":"Tests that have updated a snapshot.","messageRegex":".*updated.*snapshots.*updated.*","matchedStatuses":["passed"]},{"name":"Skipped tests","description":"Tests that were skipped in this run.","matchedStatuses":["skipped"]}]
--------------------------------------------------------------------------------
/allure-results/dcda5987-38e4-4d8f-98ab-03c82ada26b7-container.json:
--------------------------------------------------------------------------------
1 | {"uuid":"dcda5987-38e4-4d8f-98ab-03c82ada26b7","children":["2a1ada48-2b7d-4a08-b21d-0dbcfdd5e1c3"],"befores":[],"afters":[],"name":"login.spec.js"}
--------------------------------------------------------------------------------
/docs/README-pt_BR.md:
--------------------------------------------------------------------------------
1 | Exemplo de estrutura para projetos utilizando playwright
2 |
3 | ## Tecnologias utilizadas:
4 | - [JS](https://developer.mozilla.org/pt-BR/docs/Web/JavaScript)
5 | - [npm](https://www.npmjs.com/)
6 | - [playwright](https://playwright.dev/)
7 | - [jest](https://jestjs.io/)
8 |
9 | ## Estrutura de arquivos
10 |
11 | 📦playwright-arch-example
12 | ┣ 📂allure-results
13 | ┃ ┣ 📜2094b072-0e34-4f06-856b-8ef4bd346faa-testsuite.xml
14 | ┃ ┗ 📜783b98b6-c65f-473d-9bd6-c785ed393d69-testsuite.xml
15 | ┣ 📂tests
16 | ┃ ┣ 📂pages
17 | ┃ ┃ ┣ 📜Base.page.js
18 | ┃ ┃ ┣ 📜CreateAccount.page.js
19 | ┃ ┃ ┣ 📜Home.page.js
20 | ┃ ┃ ┣ 📜MyAccount.page.js
21 | ┃ ┃ ┗ 📜SignIn.page.js
22 | ┃ ┣ 📂specs
23 | ┃ ┃ ┣ 📜createUser.spec.js
24 | ┃ ┃ ┗ 📜login.spec.js
25 | ┃ ┗ 📂utils
26 | ┃ ┃ ┗ 📜Utils.js
27 | ┣ 📜.gitignore
28 | ┣ 📜README.md
29 | ┣ 📜jest-playwright.config.js
30 | ┣ 📜jest.config.js
31 | ┣ 📜jest.setup.js
32 | ┣ 📜package-lock.json
33 | ┗ 📜package.json
34 |
35 | ## Exemplos de execução:
36 |
37 | - Instalar as dependencias: ```npm i```
38 | - Executar os testes: ```npm run test```
39 | - Abrir o relatório: ```npm run report:open```
40 | - _se a task não for executada corretamente instala a dependencia do allure-commandline e o allure de forma global: ```npm i -g allure-commandline allure```_
41 |
42 | 
43 |
--------------------------------------------------------------------------------
/docs/imgs/report.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maximilianoalves/playwright-js-arch-ui-test/ff7d0103c44bf3dee0c60934b83b43fe0fbc6122/docs/imgs/report.png
--------------------------------------------------------------------------------
/jest.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | globalSetup: './tests/global/Setup.global.js',
3 | globalTeardown: './tests/global/Teardown.global.js',
4 | testRunner: "jest-circus/runner",
5 | testEnvironment: "./tests/utils/PlaywrightEnv.utils",
6 | testTimeout: 30000,
7 | verbose: true
8 | }
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "playwright-js-arch-example",
3 | "version": "1.0.0",
4 | "description": "Exemplo de estrutura para projetos utilizando playwright",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "jest --runInBand --config=jest.config.js",
8 | "report:open": "allure serve",
9 | "report:clean": "rm -rf allure-results/* && rm -rf screenshots/*"
10 | },
11 | "keywords": [],
12 | "author": "Maximiliano alves da cruz (https://www.linkedin.com/in/maximilianodacruz/)",
13 | "license": "ISC",
14 | "devDependencies": {
15 | "allure-commandline": "^2.17.2",
16 | "faker": "^5.5.3",
17 | "jest": "26.6.3 ",
18 | "jest-circus": "26.6.3",
19 | "jest-circus-allure-environment": "1.1.0",
20 | "playwright": "^1.17.1"
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/tests/global/Setup.global.js:
--------------------------------------------------------------------------------
1 | module.exports = async () => {
2 | console.log("SETUP BEFORE ALL TESTS")
3 | }
--------------------------------------------------------------------------------
/tests/global/Teardown.global.js:
--------------------------------------------------------------------------------
1 | module.exports = async () => {
2 | console.log("TEARDOWN AFTER ALL TESTS")
3 | }
--------------------------------------------------------------------------------
/tests/pages/Base.page.js:
--------------------------------------------------------------------------------
1 | class BasePage {
2 |
3 | baseUrl = "http://automationpractice.com";
4 |
5 | constructor(page) {
6 | this.page = page;
7 | }
8 |
9 | async navigate(path) {
10 | await this.page.goto(`${this.baseUrl}/${path}`);
11 | }
12 | }
13 |
14 | module.exports = BasePage;
--------------------------------------------------------------------------------
/tests/pages/CreateAccount.page.js:
--------------------------------------------------------------------------------
1 | const BasePage = require('./Base.page');
2 |
3 | class CreateAccountPage extends BasePage {
4 | constructor(page) {
5 | super(page);
6 |
7 | //elements
8 | this.radioGenderMr = page.locator('#uniform-id_gender1');
9 | this.tfFirstname = page.locator('#customer_firstname');
10 | this.tfLastname = page.locator('#customer_lastname');
11 | this.tfPassword = page.locator('#passwd');
12 | this.selectDays = page.locator('#days');
13 | this.selectMonths = page.locator('#months');
14 | this.selectYears = page.locator('#years');
15 | //address
16 | this.tfAddressFirstname = page.locator('#firstname');
17 | this.tfAddressLastname = page.locator('#lastname');
18 | this.tfAddressName = page.locator('#address1');
19 | this.tfCity = page.locator('#city');
20 | this.selectState = page.locator('#id_state');
21 | this.tfPostCode = page.locator('#postcode');
22 | this.selectCountry = page.locator('#id_country')
23 | this.tfMobilePhone = page.locator('#phone_mobile')
24 | this.btnSubmitAccount = page.locator('#submitAccount');
25 | }
26 |
27 | async navigate() {
28 | await super.navigate('index.php?controller=authentication&back=my-account#account-creation');
29 | }
30 |
31 | async selectionMr() {
32 | await this.radioGenderMr.first().click();
33 | }
34 |
35 | async fillFirstname(firstname) {
36 | await this.tfFirstname.fill(firstname);
37 | }
38 |
39 | async fillLastname(lastname) {
40 | await this.tfLastname.fill(lastname);
41 | }
42 |
43 | async fillPassword(password) {
44 | await this.tfPassword.fill(password);
45 | }
46 |
47 | async fillDateOfBirth(day, month, year) {
48 | this.selectDays.selectOption({value: day});
49 | this.selectMonths.selectOption({value: month});
50 | this.selectYears.selectOption({value: year});
51 | }
52 |
53 | async fillAddressFirstname(firstname) {
54 | await this.tfAddressFirstname.fill(firstname);
55 | }
56 |
57 | async fillAddressLastname(lastname) {
58 | await this.tfAddressLastname.fill(lastname);
59 | }
60 |
61 | async fillAddressName(addressName) {
62 | await this.tfAddressName.fill(addressName);
63 | }
64 |
65 | async fillCity(city) {
66 | await this.tfCity.fill(city);
67 | }
68 |
69 | async fillState(state) {
70 | await this.selectState.selectOption({value: state});
71 | }
72 |
73 | async fillMobilePhone(mobilePhone) {
74 | await this.tfMobilePhone.fill(mobilePhone);
75 | }
76 |
77 | async fillPostCode(postCode) {
78 | await this.tfPostCode.fill(postCode);
79 | }
80 |
81 | async clickBtnRegister() {
82 | await this.btnSubmitAccount.first().click();
83 | }
84 |
85 | }
86 |
87 | module.exports = CreateAccountPage;
--------------------------------------------------------------------------------
/tests/pages/Home.page.js:
--------------------------------------------------------------------------------
1 | const BasePage = require('./Base.page');
2 |
3 | class HomePage extends BasePage {
4 | constructor(page) {
5 | super(page);
6 |
7 | //elements
8 | this.btnSignIn = page.locator('.login');
9 | }
10 |
11 | async navigate() {
12 | await super.navigate('index.php');
13 | }
14 |
15 | async clickSignIn() {
16 | await this.btnSignIn.first().click();
17 | }
18 |
19 | }
20 |
21 | module.exports = HomePage;
--------------------------------------------------------------------------------
/tests/pages/MyAccount.page.js:
--------------------------------------------------------------------------------
1 | const BasePage = require('./Base.page');
2 |
3 | class MyAccountPage extends BasePage {
4 | constructor(page) {
5 | super(page);
6 |
7 | //elements
8 | this.heading = page.locator('h1.page-heading');
9 | this.txtName = page.locator('div.header_user_info > a > span');
10 | }
11 |
12 | async getHeading() {
13 | let pageHeading = await this.heading.innerText()
14 | return pageHeading;
15 | }
16 |
17 | async getUsername() {
18 | let username = await this.txtName.innerText();
19 | return username;
20 | }
21 |
22 | }
23 |
24 | module.exports = MyAccountPage;
--------------------------------------------------------------------------------
/tests/pages/SignIn.page.js:
--------------------------------------------------------------------------------
1 | const BasePage = require('./Base.page');
2 |
3 | class SignInPage extends BasePage {
4 | constructor(page) {
5 | super(page);
6 |
7 | //elements
8 | this.tfEmail = page.locator('#email');
9 | this.tfPassword = page.locator('#passwd');
10 | this.btnSubmit = page.locator('#SubmitLogin');
11 | this.tfEmailCreate = page.locator('#email_create');
12 | this.btnCreateAccount = page.locator('#SubmitCreate')
13 |
14 | }
15 |
16 | async navigate() {
17 | await super.navigate('index.php?controller=authentication&back=my-account');
18 | }
19 |
20 | async login(email, password) {
21 | await this.tfEmail.fill(email);
22 | await this.tfPassword.fill(password);
23 | await this.btnSubmit.first().click();
24 | }
25 |
26 | async insertEmailCreateAccount(email) {
27 | await this.tfEmailCreate.fill(email);
28 | }
29 |
30 | async clickBtnCreateAccount() {
31 | await this.btnCreateAccount.first().click();
32 | }
33 |
34 | }
35 |
36 | module.exports = SignInPage;
--------------------------------------------------------------------------------
/tests/specs/createUser.spec.js:
--------------------------------------------------------------------------------
1 | const Utils = require('../utils/Utils')
2 | const HomePage = require('../pages/Home.page');
3 | const SignInPage = require('../pages/SignIn.page');
4 | const CreateAccount = require('../pages/CreateAccount.page');
5 | const MyAccountPage = require('../pages/MyAccount.page');
6 |
7 | describe('Create an Account', () => {
8 |
9 | beforeEach(async () => {
10 | context = await global.browser.newContext()
11 | page = await context.newPage()
12 | global.page = page
13 | })
14 |
15 | afterEach(async () => {
16 | page.close()
17 | })
18 |
19 | it('Create an Account with success', async () => {
20 | const utils = new Utils();
21 | const homePage = new HomePage(page);
22 | const signInPage = new SignInPage(page);
23 | const createAccount = new CreateAccount(page);
24 | const myAccountPage = new MyAccountPage(page);
25 |
26 | const firstname = utils.getFirstname();
27 | const lastname = utils.getLastName()
28 |
29 | await homePage.navigate();
30 | await homePage.clickSignIn();
31 | await signInPage.insertEmailCreateAccount(utils.getRandomEmail());
32 | await signInPage.clickBtnCreateAccount();
33 | await createAccount.selectionMr();
34 | await createAccount.fillFirstname(firstname);
35 | await createAccount.fillLastname(lastname);
36 | await createAccount.fillPassword("teste123");
37 | await createAccount.fillDateOfBirth("14", "5", "2000");
38 | await createAccount.fillAddressFirstname(firstname);
39 | await createAccount.fillAddressLastname(lastname);
40 | await createAccount.fillAddressName("rua teste, 123");
41 | await createAccount.fillCity("New York")
42 | await createAccount.fillState("32");
43 | await createAccount.fillPostCode("93210");
44 | await createAccount.fillMobilePhone("51995484857");
45 | await createAccount.clickBtnRegister();
46 |
47 | let username = await myAccountPage.getUsername();
48 | expect(username).toEqual(`${firstname} ${lastname}`);
49 | });
50 | });
--------------------------------------------------------------------------------
/tests/specs/login.spec.js:
--------------------------------------------------------------------------------
1 | const HomePage = require('../pages/Home.page');
2 | const MyAccountPage = require('../pages/MyAccount.page');
3 | const SignInPage = require('../pages/SignIn.page');
4 |
5 | describe('Login', () => {
6 |
7 | beforeEach(async () => {
8 | context = await global.browser.newContext()
9 | page = await context.newPage()
10 | global.page = page
11 | })
12 |
13 | afterEach(async () => {
14 | page.close()
15 | })
16 |
17 | test('Do login with success', async () => {
18 | const homePage = new HomePage(page);
19 | const signInPage = new SignInPage(page);
20 | const myAccountPage = new MyAccountPage(page);
21 |
22 | await homePage.navigate();
23 | await homePage.clickSignIn();
24 | await signInPage.login("novoemailteste@gmail.com", "teste123");
25 | let myAccountHeading = await myAccountPage.getHeading();
26 | expect(myAccountHeading).toEqual("MY ACCOUNT");
27 | });
28 | });
--------------------------------------------------------------------------------
/tests/utils/PlaywrightEnv.utils.js:
--------------------------------------------------------------------------------
1 | const playwright = require("playwright");
2 | const AllureNodeEnvironment = require("jest-circus-allure-environment").default;
3 |
4 | class PlaywrightEnvUtils extends AllureNodeEnvironment {
5 |
6 | async setup() {
7 | await super.setup()
8 | this.global.browser = await playwright.chromium.launch({headless: true, slowMo: 100});
9 | }
10 |
11 | async teardown() {
12 | await super.teardown();
13 | await this.global.browser.close();
14 | }
15 |
16 | async handleTestEvent(event, state) {
17 | await super.handleTestEvent(event, state)
18 | switch (event.name) {
19 | case 'setup':
20 | break
21 | case 'add_hook':
22 | break
23 | case 'add_test':
24 | break
25 | case 'run_start':
26 | break
27 | case 'test_skip':
28 | break
29 | case 'test_todo':
30 | break
31 | case 'start_describe_definition':
32 | break
33 | case 'finish_describe_definition':
34 | break
35 | case 'run_describe_start':
36 | break
37 | case 'test_start':
38 | break
39 | case 'hook_start':
40 | break
41 | case 'hook_success':
42 | break
43 | case 'hook_failure':
44 | break
45 | case 'test_fn_start':
46 | break
47 | case 'test_fn_success':
48 | break
49 | case 'test_fn_failure':
50 | await this.global.allure.attachment("Screenshot", await this.global.page.screenshot(), "image/png")
51 | break
52 | case 'test_done':
53 | break
54 | case 'run_describe_finish':
55 | break
56 | case 'run_finish':
57 | break
58 | case 'teardown':
59 | break
60 | case 'error':
61 | break
62 | default:
63 | break
64 | }
65 | }
66 | }
67 |
68 | module.exports = PlaywrightEnvUtils
--------------------------------------------------------------------------------
/tests/utils/Utils.js:
--------------------------------------------------------------------------------
1 | const faker = require('faker');
2 |
3 | class Utils {
4 |
5 | constructor() {
6 | faker.locale = 'pt_BR';
7 | }
8 |
9 | getFullName() {
10 | return faker.name.findName();
11 | }
12 |
13 | getRandomEmail() {
14 | return faker.internet.email();
15 | }
16 |
17 | getFirstname() {
18 | return faker.name.firstName();
19 | }
20 |
21 | getLastName() {
22 | return faker.name.lastName();
23 | }
24 | }
25 |
26 | module.exports = Utils;
--------------------------------------------------------------------------------