From 5ad9be4f6bd07282d6be929472c8586f9c798bc4 Mon Sep 17 00:00:00 2001 From: depa panjie purnama Date: Mon, 31 Oct 2022 18:20:57 +0700 Subject: [PATCH] feat: Create New Request e2e test (#52) * add selector ID * add createNewRequest flow * selector update --- .../QueryUrl/HttpMethodSelector/index.js | 2 +- .../src/components/RequestTabs/index.js | 2 +- tests/home.spec.js | 22 +++++++++++++------ tests/pages/home.page.js | 21 +++++++++++++++--- tests/utils/data-faker.js | 6 +++++ 5 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 tests/utils/data-faker.js diff --git a/packages/bruno-app/src/components/RequestPane/QueryUrl/HttpMethodSelector/index.js b/packages/bruno-app/src/components/RequestPane/QueryUrl/HttpMethodSelector/index.js index 0a7d32048..eb72c85b7 100644 --- a/packages/bruno-app/src/components/RequestPane/QueryUrl/HttpMethodSelector/index.js +++ b/packages/bruno-app/src/components/RequestPane/QueryUrl/HttpMethodSelector/index.js @@ -10,7 +10,7 @@ const HttpMethodSelector = ({ method, onMethodSelect }) => { const Icon = forwardRef((props, ref) => { return (
-
{method}
+
{method}
diff --git a/packages/bruno-app/src/components/RequestTabs/index.js b/packages/bruno-app/src/components/RequestTabs/index.js index df30f51fd..989c701d3 100644 --- a/packages/bruno-app/src/components/RequestTabs/index.js +++ b/packages/bruno-app/src/components/RequestTabs/index.js @@ -119,7 +119,7 @@ const RequestTabs = () => {
) : null} -
  • +
  • diff --git a/tests/home.spec.js b/tests/home.spec.js index b26f33587..4611db829 100644 --- a/tests/home.spec.js +++ b/tests/home.spec.js @@ -1,6 +1,6 @@ const { test, expect } = require('@playwright/test'); -const { faker } = require('@faker-js/faker'); const { HomePage } = require('../tests/pages/home.page'); +import * as faker from './utils/data-faker'; test.describe('bruno e2e test', () => { let homePage; @@ -13,9 +13,22 @@ test.describe('bruno e2e test', () => { await expect(page).toHaveTitle(/bruno/); }); + test('user should be able to create new collection & new request', async () => { + await homePage.createNewCollection(faker.randomWords); + await expect(homePage.createNewCollectionSuccessToast).toBeVisible(); + + // using fake data to simulate negative case + await homePage.createNewRequest(faker.randomVerb, faker.randomHttpMethod, faker.randomUrl); + await expect(homePage.networkErrorToast).toBeVisible(); + + // using real data to simulate positive case + await homePage.createNewRequest('Single User', 'GET', 'https://reqres.in/api/users/2'); + await expect(homePage.statusRequestSuccess).toBeVisible(); + }); + test('user should be able to load & use sample collection', async () => { await homePage.loadSampleCollection(); - await expect(homePage.loadSampleCollectionToastSuccess).toBeVisible(); + await expect(homePage.loadSampleCollectionSuccessToast).toBeVisible(); await homePage.getUsers(); await expect(homePage.statusRequestSuccess).toBeVisible(); @@ -33,9 +46,4 @@ test.describe('bruno e2e test', () => { await expect(homePage.statusRequestSuccess).toBeVisible(); }); - test('user should be able to create new collection', async () => { - await homePage.createCollection(faker.random.words()); - await expect(homePage.createCollectionToastSuccess).toBeVisible(); - }) - }); diff --git a/tests/pages/home.page.js b/tests/pages/home.page.js index c0357cb16..5f475fe6b 100644 --- a/tests/pages/home.page.js +++ b/tests/pages/home.page.js @@ -9,7 +9,7 @@ exports.HomePage = class HomePage { this.loadSampleCollectionSelector = page.locator('#load-sample-collection'); // sample collection - this.loadSampleCollectionToastSuccess = page.getByText('Sample Collection loaded successfully'); + this.loadSampleCollectionSuccessToast = page.getByText('Sample Collection loaded successfully'); this.sampeCollectionSelector = page.locator('#sidebar-collection-name'); this.getUsersSelector = page.getByText('Users'); this.getSingleUserSelector = page.getByText('Single User'); @@ -26,7 +26,12 @@ exports.HomePage = class HomePage { // create collection this.collectionNameField = page.locator('#collection-name'); this.submitButton = page.locator(`button[type='submit']`); - this.createCollectionToastSuccess = page.getByText('Collection created'); + this.createNewCollectionSuccessToast = page.getByText('Collection created'); + this.createNewTab = page.locator('#create-new-tab'); + this.requestNameField = page.locator('input[name="requestName"]'); + this.methodName = page.locator('#create-new-request-method').first(); + this.requestUrlField = page.locator('#request-url'); + this.networkErrorToast = page.getByText('Network Error'); } async open() { @@ -63,9 +68,19 @@ exports.HomePage = class HomePage { await this.sendRequestButton.click(); } - async createCollection(collectionName) { + async createNewCollection(collectionName) { await this.createCollectionSelector.click(); await this.collectionNameField.fill(collectionName); await this.submitButton.click(); } + + async createNewRequest(name, method, endpoint) { + await this.createNewTab.click(); + await this.requestNameField.fill(name); + await this.methodName.click(); + await this.page.click(`text=${method}`); + await this.requestUrlField.fill(endpoint); + await this.submitButton.click(); + await this.sendRequestButton.click(); + } } diff --git a/tests/utils/data-faker.js b/tests/utils/data-faker.js new file mode 100644 index 000000000..47183065e --- /dev/null +++ b/tests/utils/data-faker.js @@ -0,0 +1,6 @@ +const { faker } = require('@faker-js/faker'); + +export let randomWords = faker.random.words(); +export let randomVerb = faker.hacker.verb(); +export let randomHttpMethod = faker.internet.httpMethod(); +export let randomUrl = faker.internet.url(); \ No newline at end of file