Skip to content

Commit e408f97

Browse files
committed
Fixing setupDriver
1 parent 34f01e1 commit e408f97

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

‎.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ jobs:
2222
with:
2323
node-version: ${{ matrix.node-version }}
2424

25+
- name: Install Dependencies
26+
run: npm install
27+
2528
- run: npm ci
26-
- run: npm run build --if-present
29+
- run: npm run build
2730

2831
- name: Setup Chrome
2932
uses: browser-actions/setup-chrome@latest
3033

31-
- name: Run Build
32-
run: npm run build
33-
3434
- name: Run Selenium Tests
3535
run: npm run test

‎src/app.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,37 @@
1-
import { assert, expect } from 'chai';
1+
import { assert } from 'chai';
2+
import { Builder, By, until, WebDriver, Capabilities } from 'selenium-webdriver';
3+
import * as chrome from 'selenium-webdriver/chrome';
24
import { Main } from '../src/components/main';
3-
import { Builder, By, until, WebDriver } from 'selenium-webdriver';
4-
import { WebElement } from 'selenium-webdriver';
55
import { DataURL } from '../src/components/data/data';
66

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

10-
1110
export class App {
1211
private driver: WebDriver;
1312
private compMain: Main; // Property to hold the Main instance
13+
1414

1515
constructor(driver: WebDriver) {
1616
this.driver = driver;
1717
this.compMain = new Main(); // Initialize the Main instance
1818
}
1919

20+
// Static method to initialize the WebDriver with headless configuration
21+
static async buildDriver(): Promise<WebDriver> {
22+
let options = new chrome.Options();
23+
options.addArguments('--headless');
24+
options.addArguments('--no-sandbox');
25+
options.addArguments('--disable-dev-shm-usage');
26+
27+
const driver = await new Builder()
28+
.forBrowser('chrome')
29+
.setChromeOptions(options)
30+
.build();
31+
32+
return driver;
33+
}
34+
2035
// ---URL---
2136
async verifyUrl(expectedUrl: string) {
2237
try {

‎test/autoDemo.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ describe('Web Automation', async function () {
1515
let driver: WebDriver;
1616

1717
before(async function () {
18-
driver = await new Builder().forBrowser('chrome').build();
19-
ObjApp = new App(driver); // Pass the driver instance here
20-
await driver.get('https://www.saucedemo.com'); // Navigate to the website
21-
await driver.manage().window().maximize(); // Maximize the browser window
18+
driver = await new Builder().forBrowser('chrome').build();
19+
ObjApp = new App(driver); // Pass the driver instance here
20+
await driver.get('https://www.saucedemo.com'); // Navigate to the website
21+
await driver.manage().window().maximize(); // Maximize the browser window
2222
});
2323

2424
after(async function () {
@@ -58,3 +58,5 @@ describe('Web Automation', async function () {
5858
});
5959
});
6060

61+
62+

‎test/loginTest.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ describe('Validate Successful Login', async function () {
1313
let driver: WebDriver;
1414

1515
before(async function () {
16+
driver = await App.buildDriver();
1617
driver = await new Builder().forBrowser('chrome').build();
1718
ObjApp = new App(driver); // Pass the driver instance here
1819
await driver.get('https://www.saucedemo.com'); // Navigate to the website

0 commit comments

Comments
 (0)