From 312efa24a0e550f175f4321da668e75333f08816 Mon Sep 17 00:00:00 2001 From: PeaceGusenga Date: Mon, 15 May 2023 14:41:59 +0200 Subject: [PATCH] pokeapi test --- playwright.config.js | 1 + tests/API-Tests/Poke-API/PokeAPI-Test.spec.js | 26 +++++++++++++++++++ tests/ProjectBlaze/Test1.spec.js | 2 +- 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 tests/API-Tests/Poke-API/PokeAPI-Test.spec.js diff --git a/playwright.config.js b/playwright.config.js index 4a83bef..1c5f0f1 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -69,6 +69,7 @@ module.exports = defineConfig({ // use: { ..devices['Desktop Chrome'], channel: 'chrome' }, // }, ], +// playwright.config.ts /* Run your local dev server before starting the tests */ // webServer: { diff --git a/tests/API-Tests/Poke-API/PokeAPI-Test.spec.js b/tests/API-Tests/Poke-API/PokeAPI-Test.spec.js new file mode 100644 index 0000000..89a31ab --- /dev/null +++ b/tests/API-Tests/Poke-API/PokeAPI-Test.spec.js @@ -0,0 +1,26 @@ +const { test, expect } = require('@playwright/test'); +const fetch = require('node-fetch'); + +test.describe('PokeAPI Tests', () => { + test('Get Pokemon List', async () => { + const response = await fetch('https://pokeapi.co/api/v2/pokemon'); + const pokemonList = await response.json(); + expect(response.ok).toBe(true); + expect(pokemonList.results).toBeDefined(); + expect(pokemonList.results.length).toBeGreaterThan(0); + }); + + test('Get Pokemon by ID', async () => { + const response = await fetch('https://pokeapi.co/api/v2/pokemon/1'); + const pokemon = await response.json(); + expect(response.ok).toBe(true); + expect(pokemon.name).toBe('bulbasaur'); + }); + + test('Get Pokemon by Name', async () => { + const response = await fetch('https://pokeapi.co/api/v2/pokemon/bulbasaur'); + const pokemon = await response.json(); + expect(response.ok).toBe(true); + expect(pokemon.id).toBe(1); + }); +}); diff --git a/tests/ProjectBlaze/Test1.spec.js b/tests/ProjectBlaze/Test1.spec.js index 8a5bcf1..1c139c6 100644 --- a/tests/ProjectBlaze/Test1.spec.js +++ b/tests/ProjectBlaze/Test1.spec.js @@ -14,7 +14,7 @@ test('visit site', async ({ page }) => { await page.goto('https://www.demoblaze.com'); // Click the get started link. - await page.getByRole('link',{name:'Cart'}).click(); + await page.getByRole('link', { name: 'Cart'}).click(); // Expects the URL to contain intro. await expect(page).toHaveURL(/.*cart/);