Skip to content

Commit

Permalink
feat: add support for brave browser in tests (#1997)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaisailovic authored Feb 29, 2024
1 parent 115ab27 commit 3867c37
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ui_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ jobs:
- name: Get installed Playwright version
id: playwright-version
run: echo "PLAYWRIGHT_VERSION=$(node -e "console.log(require('./package-lock.json').packages['apps/laboratory']['devDependencies']['@playwright/test'])")" >> $GITHUB_ENV
- name: Install Brave Browser
working-directory: ./apps/laboratory/
run: sudo ./scripts/install-brave-browser.sh
- name: Cache playwright binaries
uses: actions/cache@v4
id: playwright-cache
Expand Down
11 changes: 11 additions & 0 deletions apps/laboratory/scripts/install-brave-browser.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
echo "Installing Brave Browser"

touch /var/lib/man-db/auto-update

curl -fsSLo /usr/share/keyrings/brave-browser-archive-keyring.gpg https://brave-browser-apt-release.s3.brave.com/brave-browser-archive-keyring.gpg

echo "deb [signed-by=/usr/share/keyrings/brave-browser-archive-keyring.gpg] https://brave-browser-apt-release.s3.brave.com/ stable main" | tee /etc/apt/sources.list.d/brave-browser-release.list

apt update -y

apt install brave-browser -y
2 changes: 2 additions & 0 deletions apps/laboratory/tests/shared/constants/browsers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const BRAVE_MACOS_PATH = '/Applications/Brave Browser.app/Contents/MacOS/Brave Browser'
export const BRAVE_UBUNTU_PATH = '/usr/bin/brave-browser'
2 changes: 1 addition & 1 deletion apps/laboratory/tests/shared/constants/devices.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const DEVICES = ['Desktop Chrome', 'Desktop Firefox', 'Desktop Safari']
export const DEVICES = ['Desktop Chrome', 'Desktop Brave', 'Desktop Firefox']
10 changes: 5 additions & 5 deletions apps/laboratory/tests/shared/pages/ModalPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ export class ModalPage {

async disconnect() {
const accountBtn = this.page.getByTestId('account-button')
await expect(accountBtn).toBeVisible()
await expect(accountBtn).toBeEnabled()
await expect(accountBtn, 'Account button should be visible').toBeVisible()
await expect(accountBtn, 'Account button should be enabled').toBeEnabled()
await accountBtn.click({ force: true })
const disconnectBtn = this.page.getByTestId('disconnect-button')
await expect(disconnectBtn).toBeVisible()
await expect(disconnectBtn).toBeEnabled()
await expect(disconnectBtn, 'Disconnect button should be visible').toBeVisible()
await expect(disconnectBtn, 'Disconnect button should be visible').toBeEnabled()
await disconnectBtn.click({ force: true })
}

Expand All @@ -108,7 +108,7 @@ export class ModalPage {

async promptSiwe() {
const siweSign = this.page.getByTestId('w3m-connecting-siwe-sign')
await expect(siweSign, 'Siwe promp sign button should be enabled').toBeEnabled()
await expect(siweSign, 'Siwe prompt sign button should be enabled').toBeEnabled()
await siweSign.click()
}

Expand Down
6 changes: 1 addition & 5 deletions apps/laboratory/tests/shared/utils/device.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { DEVICES } from '../constants/devices'

export function getAvailableDevices(): string[] {
if (!process.env['CI']) {
return DEVICES
}

return DEVICES.filter(d => d !== 'Desktop Safari')
return DEVICES
}
27 changes: 26 additions & 1 deletion apps/laboratory/tests/shared/utils/project.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { devices } from '@playwright/test'
import { getAvailableDevices } from './device'
import { getValue } from './config'
import { BRAVE_MACOS_PATH, BRAVE_UBUNTU_PATH } from '../constants/browsers'

const availableDevices = getAvailableDevices()

Expand All @@ -9,16 +11,35 @@ const PERMUTATIONS = availableDevices.flatMap(device =>
LIBRARIES.map(library => ({ device, library }))
)

interface UseOptions {
launchOptions: {
executablePath: string
}
}

interface CustomProperties {
testIgnore?: string
testMatch?: string
useOptions?: UseOptions
}

export type CustomProjectProperties = {
[T in string]: CustomProperties
}

const braveOptions: UseOptions = {
launchOptions: {
executablePath: getValue(BRAVE_UBUNTU_PATH, BRAVE_MACOS_PATH)
}
}

const customProjectProperties: CustomProjectProperties = {
'Desktop Brave/wagmi': {
useOptions: braveOptions
},
'Desktop Brave/ethers': {
useOptions: braveOptions
},
'Desktop Chrome/wagmi': {
testIgnore: 'email.spec.ts'
},
Expand All @@ -37,13 +58,17 @@ export interface Permutation {

export function getProjects() {
return PERMUTATIONS.map(({ device, library }) => {
const deviceName = device === 'Desktop Brave' ? 'Desktop Chrome' : device
let project = {
name: `${device}/${library}`,
use: { ...devices[device], library }
use: { ...devices[deviceName], library }
}
const props = customProjectProperties[project.name]
if (props) {
project = { ...project, ...props }
if (props.useOptions) {
project.use = { ...project.use, ...props.useOptions }
}
}

return project
Expand Down
5 changes: 4 additions & 1 deletion apps/laboratory/tests/shared/validators/WalletValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export class WalletValidator {
}

async expectConnected() {
await expect(this.gotoSessions).toBeVisible()
await expect(
this.gotoSessions,
'Approve screen should be closed and sessions tab visible'
).toBeVisible()
await this.gotoSessions.click()
await this.expectSessionCard()
}
Expand Down

0 comments on commit 3867c37

Please sign in to comment.