Skip to content

Commit

Permalink
QA New: Playground testing with playwright web and detox mobile i…
Browse files Browse the repository at this point in the history
…ntegration (#2166)
  • Loading branch information
eunjisong authored Dec 18, 2024
1 parent 70f9b30 commit 63f1866
Show file tree
Hide file tree
Showing 32 changed files with 490 additions and 171 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ const SelectAccounts = ({
borderRadius: 8,
justifyContent: 'space-between'
}}>
<AvaText.Heading3>{title}</AvaText.Heading3>
<AvaText.Heading3 testID="select_accounts">
{title}
</AvaText.Heading3>
<CarrotSVG direction={showAccounts ? 'up' : 'down'} />
</Row>
</View>
Expand Down
23 changes: 21 additions & 2 deletions packages/core-mobile/e2e/helpers/playwrightActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const tap = async (item: Locator, timeout = 5000) => {

const open = async (url: string, page: Page) => {
await page.goto(url)
await page.setViewportSize({ width: 2080, height: 1080 })
}

const waitFor = async (item: Locator, timeout = 5000) => {
Expand All @@ -26,9 +25,29 @@ async function writeQrCodeToFile(clipboardValue: string) {
)
}

// eslint-disable-next-line max-params
function addTestResultToFile(
testName: string,
result: string,
framework: string,
path: string
) {
const resultData = {
testName,
result,
framework
}
const currentResults = fs.existsSync(path)
? JSON.parse(fs.readFileSync(path))
: []
currentResults.push(resultData)
fs.writeFileSync(path, JSON.stringify(currentResults, null, 2))
}

export default {
tap,
open,
waitFor,
writeQrCodeToFile
writeQrCodeToFile,
addTestResultToFile
}
62 changes: 30 additions & 32 deletions packages/core-mobile/e2e/helpers/playwrightSetup.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,40 @@
import { test, Page, Browser } from '@playwright/test'
import { Page, Browser, BrowserContext } from '@playwright/test'
import PlaygroundPlaywrightPage from '../pages/playgroundPlaywright.page'
import CommonPlaywrightPage from '../pages/commonPlaywrightEls.page'
import DappsPlaywrightPage from '../pages/dappsPlaywright.page'
const { chromium } = require('playwright-extra')
const stealth = require('puppeteer-extra-plugin-stealth')()
chromium.use(stealth)

export const warmupWeb = async () => {
const browser = await chromium.launch({ headless: false })
const context = await browser.newContext({
let sharedContext: BrowserContext | null = null

export const playwrightSetup = async (saveContext = false) => {
const browser: Browser = await chromium.launch({ headless: false })
const context: BrowserContext = await browser.newContext({
permissions: ['clipboard-read']
})
const page = await context.newPage()
return { browser, page }
const page: Page = await context.newPage()
if (saveContext) {
sharedContext = context
}
const playground = new PlaygroundPlaywrightPage(page)
const common = new CommonPlaywrightPage(page)
const dapps = new DappsPlaywrightPage(page)
return { browser, page, sharedContext, playground, common, dapps }
}

export const playwrightSetup = () => {
let browser: Browser | null = null
let page: Page | null = null

test.beforeAll(async () => {
const context = await warmupWeb()
browser = context.browser
page = context.page
console.log('Starting Playwright test...')
})

test.afterAll(async () => {
if (browser) {
await browser.close()
browser = null
page = null
}
console.log('Closing Playwright test...')
})

return () => {
if (page !== null && browser !== null) {
return { browser, page }
} else {
throw new Error('Page is not initialized or invalid type.')
}
export const getCurrentContext = async () => {
if (!sharedContext) {
throw new Error(
'sharedContext is not initialized. Ensure it is set before calling getCurrentContext.'
)
}
const page = await sharedContext.newPage()
if (!page) {
throw new Error('Failed to create a new page.')
}
const playground = new PlaygroundPlaywrightPage(page)
const common = new CommonPlaywrightPage(page)
const dapps = new DappsPlaywrightPage(page)
return { sharedContext, page, playground, common, dapps }
}
3 changes: 2 additions & 1 deletion packages/core-mobile/e2e/locators/connectToSite.loc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ export default {
plusButton: 'add_svg',
signMessage: 'Sign Message',
accountCheckBox: 'account_check_box',
selectAccounts: 'Select Accounts'
selectAccounts: 'Select Accounts',
selectAccountsId: 'select_accounts'
}
8 changes: 6 additions & 2 deletions packages/core-mobile/e2e/pages/connectToSite.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ class ConnectToSite {
return by.text(connectToSiteLoc.selectAccounts)
}

get selectAccountsId() {
return by.id(connectToSiteLoc.selectAccountsId)
}

async tapPlusIcon() {
if (Action.platform() === 'ios') {
await Action.tapElementAtIndex(this.plusIcon, 1)
Expand Down Expand Up @@ -61,11 +65,11 @@ class ConnectToSite {
}

async tapSelectAccounts() {
await Action.tapElementAtIndex(this.selectAccounts, 0)
await Action.tapElementAtIndex(this.selectAccountsId, 0)
}

async selectAccountAndconnect() {
await Action.waitForElement(this.selectAccounts, 25000)
await Action.waitForElement(this.selectAccountsId, 25000)
await this.tapSelectAccounts()
await this.tapAccountCheckBox()
await this.tapApproveBtn()
Expand Down
72 changes: 72 additions & 0 deletions packages/core-mobile/e2e/pages/playgroundPlaywright.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { Page } from '@playwright/test'
import actions from '../helpers/playwrightActions'
import delay from '../helpers/waits'
import CommonElsPage from './commonPlaywrightEls.page'

class PlaygroundPlaywrightPage {
page: Page

constructor(page: Page) {
this.page = page
}

get url() {
return 'https://ava-labs.github.io/extension-avalanche-playground/'
}

get rpcCalls() {
return this.page.locator('text="RPC Calls"')
}

get response() {
return this.page.locator(
"//button[normalize-space()='Send']/following-sibling::h1"
)
}

async sendRpcCall(rpcCall: string) {
await actions.open(this.url, this.page)
await this.tapRpcCalls()
await this.selectMethod(rpcCall)
await this.tapSend()
await delay(5000)
}

async connect() {
const common = new CommonElsPage(this.page)
await actions.open(this.url, this.page)
await this.tapWagmi()
await common.tapWalletConnect()
const qrUri = await common.qrUriValue('wui')
if (qrUri) {
await actions.writeQrCodeToFile(qrUri)
}
console.log(qrUri)
await actions.waitFor(this.rpcCalls, 30000)
await delay(1000)
}

async tapWagmi() {
await this.page.locator('text="Connect via Wallet Connect - Wagmi"').click()
}

async tapRpcCalls() {
await this.rpcCalls.click()
}

async tapMethodsDropdown() {
await this.page.locator('[data-testid="ArrowDropDownIcon"]').click()
}

async selectMethod(rpcCall: string) {
await this.tapMethodsDropdown()
const dropdownOption = `//li[contains(@id, "option")]/span[text()="${rpcCall}"]`
await this.page.locator(dropdownOption).click()
}

async tapSend() {
await this.page.locator('text="Send"').click()
}
}

export default PlaygroundPlaywrightPage
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { test } from '@playwright/test'
import CommonPlaywrightPage from '../../../pages/commonPlaywrightEls.page'
import actions from '../../../helpers/playwrightActions'
import { playwrightSetup } from '../../../helpers/playwrightSetup'
import DappsPlaywrightPage from '../../../pages/dappsPlaywright.page'

const getContext = playwrightSetup()
import CommonPlaywrightPage from '../../../../pages/commonPlaywrightEls.page'
import actions from '../../../../helpers/playwrightActions'
import { playwrightSetup } from '../../../../helpers/playwrightSetup'
import DappsPlaywrightPage from '../../../../pages/dappsPlaywright.page'

test('Connect Aave', async () => {
const { page } = getContext()
const { page } = await playwrightSetup()
const common = new CommonPlaywrightPage(page)
const dapps = new DappsPlaywrightPage(page)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { test } from '@playwright/test'
import CommonPlaywrightPage from '../../../pages/commonPlaywrightEls.page'
import actions from '../../../helpers/playwrightActions'
import { playwrightSetup } from '../../../helpers/playwrightSetup'
import DappsPlaywrightPage from '../../../pages/dappsPlaywright.page'

const getContext = playwrightSetup()
import CommonPlaywrightPage from '../../../../pages/commonPlaywrightEls.page'
import actions from '../../../../helpers/playwrightActions'
import { playwrightSetup } from '../../../../helpers/playwrightSetup'
import DappsPlaywrightPage from '../../../../pages/dappsPlaywright.page'

test('Connect Balancer', async () => {
const { page } = getContext()
const { page } = await playwrightSetup()
const common = new CommonPlaywrightPage(page)
const dapps = new DappsPlaywrightPage(page)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { test } from '@playwright/test'
import CommonPlaywrightPage from '../../../pages/commonPlaywrightEls.page'
import actions from '../../../helpers/playwrightActions'
import { playwrightSetup } from '../../../helpers/playwrightSetup'
import DappsPlaywrightPage from '../../../pages/dappsPlaywright.page'

const getContext = playwrightSetup()
import CommonPlaywrightPage from '../../../../pages/commonPlaywrightEls.page'
import actions from '../../../../helpers/playwrightActions'
import { playwrightSetup } from '../../../../helpers/playwrightSetup'
import DappsPlaywrightPage from '../../../../pages/dappsPlaywright.page'

test('Connect Benqi', async () => {
const { page } = getContext()
const { page } = await playwrightSetup()
const common = new CommonPlaywrightPage(page)
const dapps = new DappsPlaywrightPage(page)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { test } from '@playwright/test'
import CommonPlaywrightPage from '../../../pages/commonPlaywrightEls.page'
import actions from '../../../helpers/playwrightActions'
import { playwrightSetup } from '../../../helpers/playwrightSetup'
import DappsPlaywrightPage from '../../../pages/dappsPlaywright.page'

const getContext = playwrightSetup()
import CommonPlaywrightPage from '../../../../pages/commonPlaywrightEls.page'
import actions from '../../../../helpers/playwrightActions'
import { playwrightSetup } from '../../../../helpers/playwrightSetup'
import DappsPlaywrightPage from '../../../../pages/dappsPlaywright.page'

test('Connect CompoundFinance', async () => {
const { page } = getContext()
const { page } = await playwrightSetup()
const common = new CommonPlaywrightPage(page)
const dapps = new DappsPlaywrightPage(page)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { test } from '@playwright/test'
import CommonPlaywrightPage from '../../../pages/commonPlaywrightEls.page'
import actions from '../../../helpers/playwrightActions'
import { playwrightSetup } from '../../../helpers/playwrightSetup'
import DappsPlaywrightPage from '../../../pages/dappsPlaywright.page'

const getContext = playwrightSetup()
import CommonPlaywrightPage from '../../../../pages/commonPlaywrightEls.page'
import actions from '../../../../helpers/playwrightActions'
import { playwrightSetup } from '../../../../helpers/playwrightSetup'
import DappsPlaywrightPage from '../../../../pages/dappsPlaywright.page'

test('Connect ConvexFinance', async () => {
const { page } = getContext()
const { page } = await playwrightSetup()
const common = new CommonPlaywrightPage(page)
const dapps = new DappsPlaywrightPage(page)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { test } from '@playwright/test'
import CoreApp from '../../../pages/coreApp.page'
import CommonPlaywrightPage from '../../../pages/commonPlaywrightEls.page'
import playwrightActions from '../../../helpers/playwrightActions'
import { playwrightSetup } from '../../../helpers/playwrightSetup'

const getContext = playwrightSetup()
import CoreApp from '../../../../pages/coreApp.page'
import CommonPlaywrightPage from '../../../../pages/commonPlaywrightEls.page'
import playwrightActions from '../../../../helpers/playwrightActions'
import { playwrightSetup } from '../../../../helpers/playwrightSetup'

test('Connect Core', async () => {
const { page } = getContext()
const { page } = await playwrightSetup()
const common = new CommonPlaywrightPage(page)
const core = new CoreApp(page)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { test } from '@playwright/test'
import CommonPlaywrightPage from '../../../pages/commonPlaywrightEls.page'
import actions from '../../../helpers/playwrightActions'
import { playwrightSetup } from '../../../helpers/playwrightSetup'
import DappsPlaywrightPage from '../../../pages/dappsPlaywright.page'

const getContext = playwrightSetup()
import CommonPlaywrightPage from '../../../../pages/commonPlaywrightEls.page'
import actions from '../../../../helpers/playwrightActions'
import { playwrightSetup } from '../../../../helpers/playwrightSetup'
import DappsPlaywrightPage from '../../../../pages/dappsPlaywright.page'

test('Connect GMX', async () => {
const { page } = getContext()
const { page } = await playwrightSetup()
const common = new CommonPlaywrightPage(page)
const dapps = new DappsPlaywrightPage(page)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { test } from '@playwright/test'
import CommonPlaywrightPage from '../../../pages/commonPlaywrightEls.page'
import actions from '../../../helpers/playwrightActions'
import { playwrightSetup } from '../../../helpers/playwrightSetup'
import DappsPlaywrightPage from '../../../pages/dappsPlaywright.page'

const getContext = playwrightSetup()
import CommonPlaywrightPage from '../../../../pages/commonPlaywrightEls.page'
import actions from '../../../../helpers/playwrightActions'
import { playwrightSetup } from '../../../../helpers/playwrightSetup'
import DappsPlaywrightPage from '../../../../pages/dappsPlaywright.page'

test('Connect GoGoPool', async () => {
const { page } = getContext()
const { page } = await playwrightSetup()
const common = new CommonPlaywrightPage(page)
const dapps = new DappsPlaywrightPage(page)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { test } from '@playwright/test'
import CommonPlaywrightPage from '../../../pages/commonPlaywrightEls.page'
import actions from '../../../helpers/playwrightActions'
import { playwrightSetup } from '../../../helpers/playwrightSetup'
import DappsPlaywrightPage from '../../../pages/dappsPlaywright.page'

const getContext = playwrightSetup()
import CommonPlaywrightPage from '../../../../pages/commonPlaywrightEls.page'
import actions from '../../../../helpers/playwrightActions'
import { playwrightSetup } from '../../../../helpers/playwrightSetup'
import DappsPlaywrightPage from '../../../../pages/dappsPlaywright.page'

test('Connect InstaDapp', async () => {
const { page } = getContext()
const { page } = await playwrightSetup()
const common = new CommonPlaywrightPage(page)
const dapps = new DappsPlaywrightPage(page)

Expand Down
Loading

0 comments on commit 63f1866

Please sign in to comment.