Skip to content

Commit 5894d82

Browse files
committed
added test cases for ui, api and grapqhl
1 parent 6bf6d36 commit 5894d82

30 files changed

+333
-40
lines changed

.gitignore

+3-3
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,6 @@ fabric.properties
219219

220220
#other
221221
./outputs
222-
./allure-report
223-
./allure-results
224-
./custom_helpers/new.js
222+
./allure-report/
223+
./allure-results/
224+
./outputs/allure-results/**/*.*

config/env.conf.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ const envConf = {
22
'env': process.env.E2E_ENV || 'int',
33
'int': {
44
'web': {
5-
host_url: 'https://automationexercise.com/'
5+
host_url: 'https://automationexercise.com'
66
},
7-
'services': {
8-
end_point: 'https://graphqlzero.almansi.me/api'
7+
'restApi': {
8+
end_point: 'https://petstore.swagger.io/v2'
99
},
10-
'servers': {
11-
end_point: 'https://dummyapi.online/api/'
10+
'gql': {
11+
end_point: 'https://graphqlzero.almansi.me/api'
1212
}
1313
}
1414
};

config/graphql.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const envURL = require('./env.conf');
22

3-
const gql_endpoint = envURL[envURL.env].services.end_point;
3+
const gql_endpoint = envURL[envURL.env].gql.end_point;
44

55
module.exports = {
66
endpoint: gql_endpoint,

config/include.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = {
22
I: './steps_file.js',
3-
page: './src/pages/*.js',
3+
page: './src/pages/*_page.js',
44
};

config/playwright.conf.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ const downloadDir = path.join(__dirname, '../outputs/Download');
66

77
module.exports = {
88
url: host_url,
9-
show: false, // Headless mode
9+
show: false, // to run in headless make false
1010
browser: 'chromium',
1111
waitForTimeout: 30000, // Consistent timeout for all operations
1212
smartWait: 10000, // Smart wait for elements to appear
1313
restart: true,
1414
windowSize: '1280x1024',
1515
keepCookies: false,
1616
keepBrowserState: false,
17-
waitForNavigation: "networkidle", // Wait until network is idle (all resources loaded)
17+
waitForNavigation: "domcontentloaded", // Wait for the network to be idle (0 connections)
1818
viewport: {
1919
width: 1280,
2020
height: 1024

config/plugins.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ module.exports = {
9393
// ],
9494
},
9595
stepByStepReport: {
96-
enabled: true, // Enable or disable step-by-step reporting
96+
enabled: false, // Enable or disable step-by-step reporting
9797
fullPageScreenshots: true, // Capture full-page screenshots instead of only the visible area
9898
screenshotsForAllFailures: true, // Take screenshots for all failures
9999
onFail: true, // Take a screenshot on failure

config/rest.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const envURL = require('./env.conf');
22

3-
const api_endpoint = envURL[envURL.env].services.end_point;
3+
const api_endpoint = envURL[envURL.env].restApi.end_point;
44

55
module.exports = {
66
endpoint: api_endpoint,

custom_helpers/api_helper.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const I = actor();
44
const envURL = require('../config/env.conf'); // Import environment configuration
55

66
// Extract the base API endpoint from the environment configuration
7-
const api_endpoint = envURL[envURL.env].servers.end_point;
7+
const api_endpoint = envURL[envURL.env].restApi.end_point;
88

99
if (!api_endpoint) {
1010
throw new Error("API endpoint is not defined in the environment configuration.");
@@ -13,7 +13,7 @@ if (!api_endpoint) {
1313
/**
1414
* API Helper class for managing API requests and configurations.
1515
*/
16-
class ApiHelper extends Helper{
16+
class ApiHelper extends Helper {
1717
constructor(config) {
1818
super(config);
1919
// Initialize common variables or settings
@@ -84,17 +84,17 @@ class ApiHelper extends Helper{
8484
* Sends an HTTP POST request to the specified endpoint.
8585
*
8686
* @param {string} endpoint - The specific endpoint to send the POST request to.
87-
* @param {Object} [data={}] - Optional data to include in the request body.
87+
* @param {Object} data - Optional data to include in the request body.
8888
* @param {Object} [headers={}] - Optional headers to include in the request.
8989
* @returns {Promise} - A promise that resolves with the response.
9090
*/
91-
sendPostRequest(endpoint = "/", data = {}, headers = {}) {
92-
return I.sendPostRequest(endpoint, data, headers)
93-
.then(response => response)
94-
.catch(error => {
95-
console.error("Error sending POST request:", error);
96-
throw error;
97-
});
91+
async sendPostRequest(endpoint = "/", data = {}, headers = {}) {
92+
try {
93+
return await I.sendPostRequest(endpoint, data, headers);
94+
} catch (error) {
95+
console.error("Error sending POST request:", error);
96+
throw error;
97+
}
9898
}
9999

100100
/**

custom_helpers/common_codeceptjs_utils.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const {actor, Helper} = require("codeceptjs"); // Import environment configuration
22
const I = actor();
33
const {assert} = require('chai'); // Import Chai assertion library for validating test conditions
4-
class common_codeceptjs_utils extends Helper{
4+
class common_codeceptjs_utils extends Helper {
55
constructor(config) {
66
super(config);
77
}
@@ -16,6 +16,18 @@ class common_codeceptjs_utils extends Helper{
1616
I.click(locator);
1717
}
1818

19+
/**
20+
* Navigates to a specified URL, waits for an element to be visible, and then clicks it.
21+
* @param {string} [url=""] - The URL to visit. Defaults to environment URL if empty.
22+
* @param {string} locator - The locator of the element to click.
23+
* @param {number} [sec=10] - The number of seconds to wait for the element to be visible.
24+
*/
25+
async waitToNavigate(url = "", locator, sec = 10) {
26+
await I.amOnPage(url);
27+
await I.waitForVisible(locator, sec);
28+
}
29+
30+
1931
/**
2032
* Waits for an element to be visible and then checks it if it is not already checked.
2133
* @param {string} locator - The locator of the element to check.

custom_helpers/common_utils.js

+30
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,36 @@ class common_utils extends Helper {
162162
}
163163
}
164164
}
165+
166+
/**
167+
* Transforms a Gherkin table into an array of objects.
168+
* Each object represents a row in the table, with keys corresponding to headers.
169+
*
170+
* @param {Object} table - The Gherkin table object containing rows and cells.
171+
* @returns {Array<Object>} - An array of objects where each object represents a row from the table.
172+
*/
173+
transformTable(table) {
174+
// Extract rows from the table
175+
const rows = table.rows;
176+
177+
// Extract and remove the header row from the rows array
178+
const headerRow = rows.shift();
179+
180+
// Map the header row cells to their values to create an array of headers
181+
const headers = headerRow.cells.map(item => item.value);
182+
183+
// Transform each row into an object using headers as keys
184+
return rows.map(row => {
185+
// Create an object for each row
186+
let obj = {};
187+
// Assign values from each cell to the corresponding header key
188+
row.cells.forEach((item, index) => {
189+
obj[headers[index]] = item.value;
190+
});
191+
return obj;
192+
});
193+
}
194+
165195
}
166196

167197
module.exports = new common_utils();

custom_helpers/graphql_helper.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const I = actor();
33
const envURL = require('../config/env.conf');
44

55
// Extract the base API endpoint for GraphQL from the environment configuration
6-
const graphql_endpoint = envURL[envURL.env].services.end_point;
6+
const graphql_endpoint = envURL[envURL.env].gql.end_point;
77

88
if (!graphql_endpoint) {
99
throw new Error("GraphQL endpoint is not defined in the environment configuration.");

custom_helpers/test_data.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,24 @@
1-
module.exports = {};
1+
module.exports = {
2+
signup_test_data: {
3+
title: "Mr",
4+
Name: "",
5+
Email: "",
6+
Password: "Test@1234",
7+
dateOfBirth: {
8+
day: "1",
9+
month: "February",
10+
year: "1996"
11+
},
12+
AddressInformation: {
13+
firstName: "test",
14+
lastName: "user",
15+
company: "test company",
16+
addressLine1: "test address line one",
17+
addressLine2: "test address line two",
18+
state: "Maharashtra",
19+
city: "Pune",
20+
zipcode: "411006",
21+
mobileNumber: "9999999999"
22+
}
23+
}
24+
};

custom_helpers/variables.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
module.exports = {
2-
test: 'hello'
2+
api_response: {},
3+
gql_response: {}
34
};

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"main": "index.js",
2020
"directories": {
2121
"config": "./config",
22-
"custom_helper": "custom_helpers",
22+
"custom_helpers": "./custom_helpers",
2323
"inputs": "./inputs",
2424
"outputs": "./outputs",
2525
"src": "./src",
@@ -33,7 +33,7 @@
3333
"scripts": {
3434
"test:run": "codeceptjs run --debug --plugins allure --config=./codecept.conf.js",
3535
"test:report-serve": "allure serve ./outputs/allure-results --clean",
36-
"test:debug": "codeceptjs run --debug --grep '@debug' --config=./codecept.conf.js",
36+
"test:debug": "codeceptjs run --debug --grep \"@debug\" --plugins allure --config=./codecept.conf.js",
3737
"test:report-generate": "allure generate ./outputs/allure-results --clean -o ./allure-report",
3838
"test:e2e": "codeceptjs run --plugins allure --config=./codecept.conf.js",
3939
"test:parallel": "codeceptjs run-multiple --all --plugins allure --config=./codecept.conf.js",

src/features/01-test_feature.feature

-4
This file was deleted.
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@suit1
2+
Feature: User Registration
3+
4+
Background:
5+
Given the user is on the homepage
6+
7+
Scenario Outline: Register a new user
8+
When the user clicks on the " Signup / Login" button
9+
Then the user should be on the login and signup page
10+
When the user signs up with the name "<name>" and email "<email>"
11+
And the user clicks on the "Signup" button
12+
And the user fills in the required information
13+
When the user clicks on the "Create Account" button
14+
Then the user should see the "Account Created!" confirmation message
15+
When the user clicks on the "Continue" button
16+
Then the user should be logged in as "<name>"
17+
When the user clicks on the " Delete Account" button
18+
Then the user should see the "Account Deleted!" confirmation message
19+
Examples:
20+
| name | email |
21+
| test user 1 | test_user_one@test.com |
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@suit2
2+
Feature: REST API GET, POST, and DELETE Operations
3+
4+
Scenario: POST - Create user account
5+
When the user hits the create account API with the following details:
6+
| username | firstName | lastName | email | password | phone |
7+
| testusers | tests | users | testusers@test.com | testpassword | 9999999999 |
8+
Then the user should validate a 200 response code
9+
10+
Scenario: GET - User Account Details
11+
When the user hits the GET user account details API for "testusers"
12+
Then the user should validate a response and the following details:
13+
| username | firstName | lastName | email | password | phone |
14+
| testusers | tests | users | testusers@test.com | testpassword | 9999999999 |
15+
16+
Scenario: DELETE - User Account Details
17+
When the user hits the DELETE user account details API for "testusers"
18+
Then the user should validate a 200 response code
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@suit3
2+
Feature: GET and POST methods of GraphQL
3+
4+
Scenario: GET - Get a Post query
5+
Given the user hits the get a post query
6+
Then the user validates the response of the get a post query
7+
8+
Scenario: DELETE - Delete a Post mutation
9+
Given the user hits the delete a post mutation for id 101
10+
Then the user validates the response of the delete a post mutation

src/model/02-api-test_model.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Define and export your payload
2+
module.exports = {
3+
username: "",
4+
firstName: "",
5+
lastName: "",
6+
email: "",
7+
password: "",
8+
phone: "",
9+
userStatus: 1
10+
};

src/model/03-gql-test_model.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
let deleteData = {
2+
"id": 101
3+
}
4+
5+
module.exports = {
6+
deleteData
7+
}

src/pages/01-ui-test-scenario_page.js

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
const {actor, Helper, locator} = require('codeceptjs');
2+
const I = actor();
3+
4+
let dynamicLocators = {
5+
validateText: (text) => `//*[text()="${text}"] | //*[@value="${text}"]`,
6+
selectRadioButton: (text) => `//input[@value="${text}"]`,
7+
fillTextBox: (text) => `//input[@name="${text}"]`,
8+
checkBoxSelect: (text) => `//label[text()="${text}"]/..//input`
9+
}
10+
11+
class ui_test_scenario_page extends Helper {
12+
constructor(config) {
13+
super(config);
14+
this.validateIOnLoginAndSignupPageLocator = `//h2[text()="New User Signup!"]`;
15+
this.fillNameLocator = `//input[@name="name"]`;
16+
this.fillEmailLocator = `(//input[@name="email"])[2]`;
17+
}
18+
19+
async validateIOnLoginAndSignupPage() {
20+
await common_codeceptjs_utils.waitAndSee(this.validateIOnLoginAndSignupPageLocator);
21+
}
22+
23+
async fillNameAndEmail(name, email) {
24+
await common_codeceptjs_utils.waitAndFillField(this.fillNameLocator, name);
25+
await common_codeceptjs_utils.waitAndFillField(this.fillEmailLocator, email);
26+
}
27+
28+
async fillAndValidateUserDetails() {
29+
const data = test_data.signup_test_data;
30+
const AddressInformation = data.AddressInformation;
31+
await common_codeceptjs_utils.waitAndSee(dynamicLocators.validateText("Enter Account Information"));
32+
await common_codeceptjs_utils.waitAndClick(dynamicLocators.selectRadioButton(data.title));
33+
await common_codeceptjs_utils.waitAndSee(dynamicLocators.validateText(data.Name));
34+
await common_codeceptjs_utils.waitAndSee(dynamicLocators.validateText(data.Email));
35+
await common_codeceptjs_utils.waitAndFillField(dynamicLocators.fillTextBox("password"), data.Password);
36+
await I.selectOption('days', data.dateOfBirth.day);
37+
await I.selectOption('months', data.dateOfBirth.month);
38+
await I.selectOption('years', data.dateOfBirth.year);
39+
await common_codeceptjs_utils.waitAndChecked(dynamicLocators.checkBoxSelect("Sign up for our newsletter!"));
40+
await common_codeceptjs_utils.waitAndChecked(dynamicLocators.checkBoxSelect("Receive special offers from our partners!"));
41+
await common_codeceptjs_utils.waitAndFillField(dynamicLocators.fillTextBox('first_name'), AddressInformation.firstName);
42+
await common_codeceptjs_utils.waitAndFillField(dynamicLocators.fillTextBox('last_name'), AddressInformation.lastName);
43+
await common_codeceptjs_utils.waitAndFillField(dynamicLocators.fillTextBox('company'), AddressInformation.company);
44+
await common_codeceptjs_utils.waitAndFillField(dynamicLocators.fillTextBox('address1'), AddressInformation.addressLine1);
45+
await common_codeceptjs_utils.waitAndFillField(dynamicLocators.fillTextBox('address2'), AddressInformation.addressLine2);
46+
await common_codeceptjs_utils.waitAndFillField(dynamicLocators.fillTextBox('state'), AddressInformation.state);
47+
await common_codeceptjs_utils.waitAndFillField(dynamicLocators.fillTextBox('city'), AddressInformation.city);
48+
await common_codeceptjs_utils.waitAndFillField(dynamicLocators.fillTextBox('zipcode'), AddressInformation.zipcode);
49+
await common_codeceptjs_utils.waitAndFillField(dynamicLocators.fillTextBox('mobile_number'), AddressInformation.mobileNumber);
50+
}
51+
}
52+
53+
module.exports = new ui_test_scenario_page();

0 commit comments

Comments
 (0)