Skip to content

Commit

Permalink
Merge pull request #74 from CS3219-AY2425S1/browser-compatibility-tests
Browse files Browse the repository at this point in the history
Set up browser testing for Chrome
  • Loading branch information
tituschewxj authored Nov 13, 2024
2 parents 31a6bd1 + 4b50754 commit 513fc88
Show file tree
Hide file tree
Showing 9 changed files with 293 additions and 37 deletions.
50 changes: 37 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up .env
env:
QUESTION_FIREBASE_CREDENTIAL_PATH: ${{ vars.QUESTION_SERVICE_FIREBASE_CREDENTIAL_PATH }}
Expand All @@ -30,7 +30,7 @@ jobs:
echo "FIREBASE_CREDENTIAL_PATH=$QUESTION_FIREBASE_CREDENTIAL_PATH" >> .env
echo "JWT_SECRET=$JWT_SECRET" >> .env
echo "EXECUTION_SERVICE_URL=$EXECUTION_SERVICE_URL" >> .env
- name: Set up credentials
env:
QUESTION_FIREBASE_JSON: ${{ secrets.QUESTION_SERVICE_FIREBASE_CREDENTIAL }}
Expand All @@ -41,8 +41,8 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "1.23.x"
with:
go-version: '1.23.x'

- name: Install Go dependencies
run: |
Expand All @@ -51,7 +51,7 @@ jobs:
- name: Install firebase tools
run: curl -sL firebase.tools | bash

- name: Run Go tests with Firebase emulator
run: firebase emulators:exec --only firestore 'cd ./apps/question-service; go test -v ./tests'

Expand All @@ -66,11 +66,11 @@ jobs:
run: |
cd ./apps/frontend
cp .env.example .env
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: "22"
node-version: '22'

- name: Install pnpm
run: npm i -g pnpm
Expand All @@ -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 @@ -117,7 +117,6 @@ jobs:
EXECUTION_SERVICE_PORT: ${{ vars.EXECUTION_SERVICE_PORT }}
MATCHING_SERVICE_TIMEOUT: ${{ vars.MATCHING_SERVICE_TIMEOUT }}
REDIS_URL: ${{ vars.REDIS_URL }}
RABBITMQ_URL: ${{ vars.RABBITMQ_URL }}
QUESTION_SERVICE_GRPC_URL: ${{ vars.QUESTION_SERVICE_GPRC_URL }}
run: |
cd ./apps/frontend
Expand Down Expand Up @@ -148,13 +147,11 @@ jobs:
cd ../history-service
echo "FIREBASE_CREDENTIAL_PATH=$HISTORY_FIREBASE_CREDENTIAL_PATH" >> .env
echo "PORT=$HISTORY_SERVICE_PORT" >> .env
echo "RABBITMQ_URL=$RABBITMQ_URL" >> .env
cd ../execution-service
echo "FIREBASE_CREDENTIAL_PATH=$EXECUTION_FIREBASE_CREDENTIAL_PATH" >> .env
echo "PORT=$EXECUTION_SERVICE_PORT" >> .env
echo "HISTORY_SERVICE_URL=$HISTORY_SERVICE_URL" >> .env
echo "RABBITMQ_URL=$RABBITMQ_URL" >> .env
cd ../signalling-service
echo "PORT=$SIGNALLING_SERVICE_PORT" >> .env
Expand All @@ -173,7 +170,7 @@ jobs:
cd ../history-service
echo "$HISTORY_FIREBASE_JSON" > "./$HISTORY_FIREBASE_CREDENTIAL_PATH"
cd ../execution-service
echo "$EXECUTION_FIREBASE_JSON" > "./$EXECUTION_FIREBASE_CREDENTIAL_PATH"
Expand Down Expand Up @@ -225,3 +222,30 @@ 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: Install Edge
uses: browser-actions/setup-edge@v1
with:
edge-version: stable

- name: Install Geckodriver
uses: browser-actions/setup-geckodriver@latest

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

import {Options as ChromeOptions} from "selenium-webdriver/chrome"
import {Options as EdgeOptions} from "selenium-webdriver/edge"
import {Options as FirefoxOptions} from "selenium-webdriver/firefox"

const URL = 'http://localhost:3000/';
const ETERNAL_JWT = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJleHAiOjk5OTk5OTk5OTk5fQ.Z4_FVGQ5lIcouP3m4YLMr6pGMF17IJFfo2yOTiN58DY"

const CHROME_OPTIONS = new ChromeOptions()
.addArguments("--headless=new") as ChromeOptions; // uncomment locally to see the steps in action
const EDGE_OPTIONS = new EdgeOptions()
.setBinaryPath("/opt/hostedtoolcache/msedge/stable/x64/msedge") // need to point to the correct path
.addArguments("--headless=new") as EdgeOptions;

const FIREFOX_OPTIONS = new FirefoxOptions()
.addArguments("--headless") as FirefoxOptions;

const builder = new Builder()
.setChromeOptions(CHROME_OPTIONS)
.setEdgeOptions(EDGE_OPTIONS)
.setFirefoxOptions(FIREFOX_OPTIONS)

describe.each([Browser.CHROME, Browser.EDGE, Browser.FIREFOX])("%s driver test", (browser) => {
let driver: WebDriver;
beforeAll(() => {
const cap = new Capabilities().setBrowserName(browser)
builder.withCapabilities(cap);
})

beforeEach(async () => {
console.log(browser + ": building...");
driver = await builder.build();
console.log(browser + ": built");
}, 20000)

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

describe("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);
}, 10000);

it.skip("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);
}, 10000);
});

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).toBe("A better way to prepare for coding interviews with");
expect(slogan2).toBe("peers");
}, 10000);
})
}, 60000)




File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ describe("GetQuestions", () => {

});

it("gets all questions on the 2nd page with (2) call", async () => {
it("formats (page=2) params correctly", async () => {

const res = await GetQuestions(2)

Expand All @@ -138,7 +138,7 @@ describe("GetQuestions", () => {
}]])
});

it("gets all questions on the 2nd page with (limit=3) call", async () => {
it("formats (limit=3) params correctly", async () => {

await GetQuestions(undefined, 3)

Expand All @@ -150,7 +150,7 @@ describe("GetQuestions", () => {
}]])
});

it("gets all questions on the 2nd page with (limit=3) call", async () => {
it("formats (difficulty asc) params correctly", async () => {

await GetQuestions(undefined, undefined, "difficulty asc")

Expand All @@ -162,7 +162,7 @@ describe("GetQuestions", () => {
}]])
});

it("gets all questions on the 2nd page with (limit=3) call", async () => {
it("formats ([\"easy\", \"hard\"]) params correctly", async () => {

await GetQuestions(undefined, undefined, undefined, ["easy", "hard"])

Expand All @@ -174,7 +174,7 @@ describe("GetQuestions", () => {
}]])
});

it("formats urls for categories", async () => {
it("formats cat params correctly", async () => {

await GetQuestions(undefined, undefined, undefined, undefined, ["CatA", "CatB"])

Expand All @@ -189,7 +189,7 @@ describe("GetQuestions", () => {
]])
});

it("formats url for title", async () => {
it("formats title params correctly", async () => {

await GetQuestions(undefined, undefined, undefined, undefined, undefined, "The Title Name")

Expand Down
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 --verbose __tests__/unit-tests",
"browser-test": "jest --verbose __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 513fc88

Please sign in to comment.