From 4092ec449c5e16ec9ad94782f11e32bb8f9e1085 Mon Sep 17 00:00:00 2001 From: CiuciuiA Date: Sat, 24 Aug 2024 23:10:31 +0300 Subject: [PATCH 1/2] Created the constantsAndTestData folder and the constants file --- constantsAndTestData/constants.ts | 6 ++++++ pages/home.page.js | 7 +++++-- 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 constantsAndTestData/constants.ts diff --git a/constantsAndTestData/constants.ts b/constantsAndTestData/constants.ts new file mode 100644 index 0000000..85899d9 --- /dev/null +++ b/constantsAndTestData/constants.ts @@ -0,0 +1,6 @@ +// This class was created to constants, variables with values that don't change after being instantiated. +// It also helps in reducing duplicate code. + + +// Constants +export const APP_URL = "https://magento.softwaretestingboard.com/"; diff --git a/pages/home.page.js b/pages/home.page.js index b6f0938..35aa583 100644 --- a/pages/home.page.js +++ b/pages/home.page.js @@ -1,8 +1,11 @@ +import { APP_URL } from './constants'; + + export class HomePage { constructor(page) { this.page = page; - this.homePageUrl = 'https://magento.softwaretestingboard.com/'; + this.homePageUrl = APP_URL; } // locators @@ -11,5 +14,5 @@ export class HomePage { async navigateToHomePage() { await this.page.goto(this.homePageUrl); } -} +} From c36207ccccb97b98d0d1f033bb299189dbe32da0 Mon Sep 17 00:00:00 2001 From: CiuciuiA Date: Mon, 26 Aug 2024 04:09:42 +0300 Subject: [PATCH 2/2] Worked on running the first api test Updated the playwright version --- .../{constants.ts => constants.js} | 3 ++ package-lock.json | 34 +++++++++++-------- package.json | 2 +- tests/api/requests/apiClient.js | 15 ++++++++ tests/api/testCases/apiTests.spec.js | 17 ++++++++++ 5 files changed, 55 insertions(+), 16 deletions(-) rename constantsAndTestData/{constants.ts => constants.js} (70%) create mode 100644 tests/api/requests/apiClient.js create mode 100644 tests/api/testCases/apiTests.spec.js diff --git a/constantsAndTestData/constants.ts b/constantsAndTestData/constants.js similarity index 70% rename from constantsAndTestData/constants.ts rename to constantsAndTestData/constants.js index 85899d9..226f0a7 100644 --- a/constantsAndTestData/constants.ts +++ b/constantsAndTestData/constants.js @@ -4,3 +4,6 @@ // Constants export const APP_URL = "https://magento.softwaretestingboard.com/"; + +export const API_ENDPOINT = "https://z3.martioli.com/api/"; +export const API_GET_ENTRY = "/id/%s" diff --git a/package-lock.json b/package-lock.json index 0f34018..324ba0c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,23 +9,24 @@ "version": "1.0.0", "license": "ISC", "devDependencies": { - "@playwright/test": "^1.40.0", + "@playwright/test": "^1.46.1", "@types/node": "^20.9.3" } }, "node_modules/@playwright/test": { - "version": "1.40.0", - "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.40.0.tgz", - "integrity": "sha512-PdW+kn4eV99iP5gxWNSDQCbhMaDVej+RXL5xr6t04nbKLCBwYtA046t7ofoczHOm8u6c+45hpDKQVZqtqwkeQg==", + "version": "1.46.1", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.46.1.tgz", + "integrity": "sha512-Fq6SwLujA/DOIvNC2EL/SojJnkKf/rAwJ//APpJJHRyMi1PdKrY3Az+4XNQ51N4RTbItbIByQ0jgd1tayq1aeA==", "dev": true, + "license": "Apache-2.0", "dependencies": { - "playwright": "1.40.0" + "playwright": "1.46.1" }, "bin": { "playwright": "cli.js" }, "engines": { - "node": ">=16" + "node": ">=18" } }, "node_modules/@types/node": { @@ -43,6 +44,7 @@ "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", "dev": true, "hasInstallScript": true, + "license": "MIT", "optional": true, "os": [ "darwin" @@ -52,33 +54,35 @@ } }, "node_modules/playwright": { - "version": "1.40.0", - "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.40.0.tgz", - "integrity": "sha512-gyHAgQjiDf1m34Xpwzaqb76KgfzYrhK7iih+2IzcOCoZWr/8ZqmdBw+t0RU85ZmfJMgtgAiNtBQ/KS2325INXw==", + "version": "1.46.1", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.46.1.tgz", + "integrity": "sha512-oPcr1yqoXLCkgKtD5eNUPLiN40rYEM39odNpIb6VE6S7/15gJmA1NzVv6zJYusV0e7tzvkU/utBFNa/Kpxmwng==", "dev": true, + "license": "Apache-2.0", "dependencies": { - "playwright-core": "1.40.0" + "playwright-core": "1.46.1" }, "bin": { "playwright": "cli.js" }, "engines": { - "node": ">=16" + "node": ">=18" }, "optionalDependencies": { "fsevents": "2.3.2" } }, "node_modules/playwright-core": { - "version": "1.40.0", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.40.0.tgz", - "integrity": "sha512-fvKewVJpGeca8t0ipM56jkVSU6Eo0RmFvQ/MaCQNDYm+sdvKkMBBWTE1FdeMqIdumRaXXjZChWHvIzCGM/tA/Q==", + "version": "1.46.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.46.1.tgz", + "integrity": "sha512-h9LqIQaAv+CYvWzsZ+h3RsrqCStkBHlgo6/TJlFst3cOTlLghBQlJwPOZKQJTKNaD3QIB7aAVQ+gfWbN3NXB7A==", "dev": true, + "license": "Apache-2.0", "bin": { "playwright-core": "cli.js" }, "engines": { - "node": ">=16" + "node": ">=18" } }, "node_modules/undici-types": { diff --git a/package.json b/package.json index 988cde7..4638a45 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "author": "", "license": "ISC", "devDependencies": { - "@playwright/test": "^1.40.0", + "@playwright/test": "^1.46.1", "@types/node": "^20.9.3" } } diff --git a/tests/api/requests/apiClient.js b/tests/api/requests/apiClient.js new file mode 100644 index 0000000..69cf350 --- /dev/null +++ b/tests/api/requests/apiClient.js @@ -0,0 +1,15 @@ +import axios from 'axios'; +import { API_ENDPOINT} from './constants'; +import { APP_URL } from './constants'; + +const apiClient = { + get: async(config = {}) => { + try{ + const response = await axios.get(`${API_ENDPOINT}${APP_URL}`, config) + return response.data; + } catch(error) { + console.error('GET Request Failed', error); + throw error; + } + } +} diff --git a/tests/api/testCases/apiTests.spec.js b/tests/api/testCases/apiTests.spec.js new file mode 100644 index 0000000..a17355f --- /dev/null +++ b/tests/api/testCases/apiTests.spec.js @@ -0,0 +1,17 @@ +import apiClient from './tests/api/requests/apiClient.js'; +import {test, expect} from '@playwright/test'; + +async function fetchdata() { + try{ + const data = await apiClient.get('endpoint'); + console.log(data); + } catch (error) { + console.error('Error fetching data: ', error); + } +} + +test("API GetAll", async () => { + + await fetchdata(); + +}) \ No newline at end of file