Skip to content

Commit

Permalink
added beforeAll for API
Browse files Browse the repository at this point in the history
  • Loading branch information
dilpreetj committed Aug 3, 2023
1 parent 758a072 commit 82a8a1b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const config: PlaywrightTestConfig = {
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
actionTimeout: 0,
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: 'https://practice.automationbro.com',
baseURL: 'https://practice.sdetunicorns.com',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'retain-on-failure',
Expand Down
31 changes: 31 additions & 0 deletions tests/contact.api.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { test, expect, APIRequestContext } from '@playwright/test';
import ContactPage from '../pages/contact.page';
import { faker } from '@faker-js/faker';

test.describe('Contact', () => {
let contactPage: ContactPage;
let fakerApi: APIRequestContext;

test.beforeAll(async ({ playwright }) => {
fakerApi = await playwright.request.newContext({
baseURL: 'https://jsonplaceholder.typicode.com/'
});

const response = await fakerApi.get('users');
console.log(await response.json());
})


test('Fill contact form and verify success message', async ({ page }) => {
contactPage = new ContactPage(page);

// open contact page
await contactPage.navigate()

// fill out the input fields and submit
await contactPage.submitForm(faker.name.findName(), faker.internet.email(), faker.phone.number(), faker.lorem.paragraphs(2));

// verify success message
await expect(contactPage.successTxt).toHaveText('Thanks for contacting us! We will be in touch with you shortly')
})
})

0 comments on commit 82a8a1b

Please sign in to comment.