Skip to content

Commit 711bdf7

Browse files
committed
Updating automation script
1 parent 8725008 commit 711bdf7

File tree

7 files changed

+246
-207
lines changed

7 files changed

+246
-207
lines changed

‎src/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { assert } from 'chai';
22
import { Builder, By, until, WebDriver, Capabilities } from 'selenium-webdriver';
33
import * as chrome from 'selenium-webdriver/chrome';
44
import { Main } from '../src/components/main';
5-
import { DataURL } from '../src/components/data/data';
5+
import { pageUrl } from '../src/components/data/data';
66

77
let compMain = new Main();
88
let driver: WebDriver;

‎src/components/data/data.ts

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,47 @@
1-
export enum DataURL {
1+
export enum pageUrl {
22
saucedemo = 'https://www.saucedemo.com/',
33
saucedemoInventory = 'https://www.saucedemo.com/inventory.html',
44
saucedemoCheckoutComplete = 'https://www.saucedemo.com/checkout-complete.html'
5-
}
5+
}
6+
7+
8+
export const ProductNames = {
9+
sauceLabsBackpack: 'Sauce Labs Backpack',
10+
sauceLabsBikeLight: 'Sauce Labs Bike Light',
11+
};
12+
13+
export const UserCredentials = {
14+
standardUser: {
15+
username: 'standard_user',
16+
password: 'secret_sauce',
17+
},
18+
invalidUser: {
19+
username: 'invalid_user',
20+
password: 'secret_sauce',
21+
},
22+
lockedoutUser: {
23+
username: 'locked_out_user',
24+
password: 'secret_sauce',
25+
},
26+
problemUser: {
27+
username: 'problem_user',
28+
password: 'secret_sauce',
29+
},
30+
performanceGlitchUser: {
31+
username: 'performance_glitch_user',
32+
password: 'secret_sauce',
33+
},
34+
errorUser: {
35+
username: 'error_user',
36+
password: 'secret_sauce',
37+
},
38+
visualUser: {
39+
username: 'visual_user',
40+
password: 'secret_sauce',
41+
}
42+
};
43+
44+
export const ErrorMsg = {
45+
restrictedAccess: `Epic sadface: You can only access '/inventory.html' when you are logged in.`,
46+
invalidLogin: `Epic sadface: Username and password do not match any user in this service`,
47+
};

‎test/invalidLoginTest.ts

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,44 @@ import * as chrome from 'selenium-webdriver/chrome';
44
import 'chromedriver';
55
import { Main } from '../src/components/main';
66
import { App } from '../src/app';
7-
import { DataURL } from '../src/components/data/data';
7+
import { pageUrl, UserCredentials, ErrorMsg } from '../src/components/data/data';
88

99
let compMain = new Main();
1010
let objApp: App;
1111

12-
describe('Test Case: Validate Unsuccessful Login', async function () {
13-
let driver: WebDriver;
14-
15-
before(async function () {
16-
driver = await App.buildDriver();
17-
driver = await new Builder().forBrowser('chrome').build();
18-
objApp = new App(driver); // Pass the driver instance here
19-
await driver.manage().window().maximize(); // Maximize the browser window
20-
});
21-
22-
after(async function () {
23-
await driver.quit(); // Close the driver after each test case
24-
});
25-
26-
it('Step 1: Open Browser', async function () {
27-
await driver.get('https://www.saucedemo.com'); // Navigate to the website
28-
29-
await objApp.verifyUrl(DataURL.saucedemo);
30-
});
31-
32-
it('Step 2: Enter invalid username', async function () {
33-
await objApp.insertText(By.css(compMain.userNameInput), 'invalid_user');
34-
});
35-
36-
it('Step 3: Enter invalid password', async function () {
37-
await objApp.insertText(By.css(compMain.userPassInput), 'wrong_password');
38-
});
39-
40-
it('Step 4: Click Login', async function () {
41-
await objApp.click(By.css(compMain.loginButton));
42-
43-
await objApp.verifyErrorMsg(`Epic sadface: Username and password do not match any user in this service`);
44-
});
45-
46-
});
47-
12+
export function invalidLoginTest() {
13+
describe('Test Case: Validate Unsuccessful Login', async function () {
14+
let driver: WebDriver;
15+
16+
before(async function () {
17+
driver = await App.buildDriver();
18+
// driver = await new Builder().forBrowser('chrome').build(); // Uncomment this line if you want to use the default chrome browser
19+
objApp = new App(driver); // Pass the driver instance here
20+
await driver.manage().window().maximize(); // Maximize the browser window
21+
});
22+
23+
after(async function () {
24+
await driver.quit(); // Close the driver after each test case
25+
});
26+
27+
it('Step 1: Open Browser', async function () {
28+
await driver.get(pageUrl.saucedemo); // Navigate to the website
29+
30+
await objApp.verifyUrl(pageUrl.saucedemo);
31+
});
32+
33+
it('Step 2: Enter invalid username', async function () {
34+
await objApp.insertText(By.css(compMain.userNameInput), UserCredentials.invalidUser.username);
35+
});
36+
37+
it('Step 3: Enter invalid password', async function () {
38+
await objApp.insertText(By.css(compMain.userPassInput), UserCredentials.invalidUser.password);
39+
});
40+
41+
it('Step 4: Click Login', async function () {
42+
await objApp.click(By.css(compMain.loginButton));
43+
44+
await objApp.verifyErrorMsg(ErrorMsg.invalidLogin);
45+
});
46+
});
47+
}

‎test/regression.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
import { expect, assert} from 'chai';
21
import { WebDriver, Builder, By } from 'selenium-webdriver';
3-
import * as chrome from 'selenium-webdriver/chrome';
42
import 'chromedriver';
5-
import { Main } from '../src/components/main';
6-
import { App } from '../src/app';
7-
import { DataURL } from '../src/components/data/data';
8-
9-
10-
let compMain = new Main();
11-
let objApp: App;
3+
import { runShoppingExp } from './shoppingExp';
4+
import { invalidLoginTest } from './invalidLoginTest';
5+
import { validLoginTest } from './validLoginTest';
6+
import { restrictedAccessTest } from './restrictedAccessTest'
127

138

149
describe('Test Case: Regression Test', async function () {
@@ -21,8 +16,12 @@ describe('Test Case: Regression Test', async function () {
2116
after(async function () {
2217

2318
});
24-
// ---- Test Case 1 ----
2519

26-
// ---- Test Case 2 ----
20+
runShoppingExp();
21+
22+
invalidLoginTest();
23+
24+
validLoginTest();
2725

26+
restrictedAccessTest();
2827
});

‎test/restrictedAccessTest.ts

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,33 @@ import * as chrome from 'selenium-webdriver/chrome';
44
import 'chromedriver';
55
import { Main } from '../src/components/main';
66
import { App } from '../src/app';
7-
import { DataURL } from '../src/components/data/data';
7+
import { pageUrl, ErrorMsg } from '../src/components/data/data';
88

99
let compMain = new Main();
1010
let objApp: App;
1111

12-
describe('Test Case: Retrict Direct Access', async function () {
13-
let driver: WebDriver;
14-
15-
before(async function () {
16-
driver = await App.buildDriver();
17-
driver = await new Builder().forBrowser('chrome').build();
18-
objApp = new App(driver); // Pass the driver instance here
19-
await driver.manage().window().maximize(); // Maximize the browser window
20-
});
21-
22-
after(async function () {
23-
await driver.quit(); // Close the driver after each test case
24-
});
25-
26-
it('Step 1: Directly Access to Inventory', async function () {
27-
await driver.get('https://www.saucedemo.com/inventory.html');
28-
});
29-
30-
it('Step 2: Verify Access Restriction', async function () {
31-
await objApp.restrictedErrorMsg(`Epic sadface: You can only access '/inventory.html' when you are logged in.`);
32-
});
33-
});
3412

13+
export function restrictedAccessTest() {
14+
describe('Test Case: Restrict Direct Access', async function () {
15+
let driver: WebDriver;
16+
17+
before(async function () {
18+
driver = await App.buildDriver();
19+
// driver = await new Builder().forBrowser('chrome').build(); // Uncomment this line if you want to use the default chrome browser
20+
objApp = new App(driver); // Pass the driver instance here
21+
await driver.manage().window().maximize(); // Maximize the browser window
22+
});
23+
24+
after(async function () {
25+
await driver.quit(); // Close the driver after each test case
26+
});
27+
28+
it('Step 1: Directly Access to Inventory', async function () {
29+
await driver.get(pageUrl.saucedemoInventory);
30+
});
31+
32+
it('Step 2: Verify Access Restriction', async function () {
33+
await objApp.restrictedErrorMsg(ErrorMsg.restrictedAccess);
34+
});
35+
});
36+
}

0 commit comments

Comments
 (0)