Skip to content

Commit

Permalink
set up browser tests for Chrome
Browse files Browse the repository at this point in the history
  • Loading branch information
chiaryan committed Nov 10, 2024
1 parent 439b410 commit 311be82
Show file tree
Hide file tree
Showing 9 changed files with 247 additions and 19 deletions.
22 changes: 21 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
- name: Run tests
run: |
cd ./apps/frontend
pnpm test
pnpm unit-test
test-docker-compose:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -222,3 +222,23 @@ jobs:
echo "WebSocket for Signalling Service is live"
fi
# We can add more tests here
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9.1.4

- name: Install dependencies
run: |
cd ./apps/frontend
pnpm i
- name: Install Chrome WebDriver
uses: nanasess/setup-chromedriver@v2
with:
chromedriver-version: '130.0.6723.116'

- name: Run Browser Test
run: |
cd ./apps/frontend
pnpm browser-test
58 changes: 58 additions & 0 deletions apps/frontend/__tests__/browser-tests/browser.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { Actions, Browser, Builder, By, Key, until, WebDriver } from "selenium-webdriver"

import Chrome from "selenium-webdriver/chrome"
const URL = 'http://localhost:3000/';
const ETERNAL_JWT = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJleHAiOjk5OTk5OTk5OTk5fQ.Z4_FVGQ5lIcouP3m4YLMr6pGMF17IJFfo2yOTiN58DY"

describe("chrome browser", () => {
const options = new Chrome.Options()
.addArguments("--headless=new") as Chrome.Options; // uncomment locally to see the steps in action
const builder = new Builder().forBrowser(Browser.CHROME).setChromeOptions(options);
let driver: WebDriver;

beforeEach(async () => {
driver = await builder.build();
})

afterEach(async () => {
await driver.quit();
})

describe("chrome webdriver installed correctly", () => {
it("does google search", async () => {
await driver.get('http://www.google.com');
await driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN);
await driver.wait(until.titleIs('webdriver - Google Search'), 1000);
});
it("does another google search", async () => {
await driver.get('http://www.google.com');
await driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN);
await driver.wait(until.titleIs('webdriver - Google Search'), 1000);
});
});

describe("browser-test", () => {
it("accesses and login to peerprep", async () => {
await driver.get(URL);
await driver.wait(until.urlIs(`${URL}login`));

const [email, password] = await driver.findElements(By.css("input"))
const submit = await driver.findElement(By.css("button[type=\"submit\"]"))

await email.sendKeys("admin@gmail.com");
await password.sendKeys("admin");

await submit.click();
await driver.wait(until.urlIs(`${URL}`));

const slogan1 = await driver.findElement(By.xpath("/html/body/div[1]/main/div/div[1]/div[2]/span[1]")).then(ele => ele.getText())
const slogan2 = await driver.findElement(By.xpath("/html/body/div[1]/main/div/div[1]/div[2]/span[2]")).then(ele => ele.getText())

expect(slogan1 + slogan2).toBe("A better way to prepare for coding interviews withpeers");
});
})
})




File renamed without changes.
File renamed without changes.
9 changes: 7 additions & 2 deletions apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"build": "next build",
"start": "next start",
"lint": "next lint",
"test": "jest"
"test": "jest",
"unit-test": "jest __tests__/unit-tests",
"browser-test": "jest __tests__/browser-tests"
},
"dependencies": {
"@ant-design/icons": "^5.5.1",
Expand Down Expand Up @@ -37,19 +39,22 @@
"yjs": "^13.6.20"
},
"devDependencies": {
"@types/codemirror": "^5.60.15",
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.0.1",
"@types/chromedriver": "^81.0.5",
"@types/codemirror": "^5.60.15",
"@types/jest": "^29.5.14",
"@types/node": "^20",
"@types/peerjs": "^1.1.0",
"@types/react": "^18.3.8",
"@types/react-dom": "^18.3.0",
"@types/selenium-webdriver": "^4.1.27",
"eslint": "^8",
"eslint-config-next": "14.2.13",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"selenium-webdriver": "^4.26.0",
"ts-node": "^10.9.2",
"typescript": "^5"
},
Expand Down
Loading

0 comments on commit 311be82

Please sign in to comment.