Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
zetavg committed Jan 19, 2025
1 parent 2cb6c64 commit a9f18b1
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 1 deletion.
10 changes: 9 additions & 1 deletion .github/workflows/test-native-2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
# with:
# workspace-focus: ${{ env.test_app_package_name }}

- name: Download Built Native App
- name: Download Built Test Container App
uses: actions/cache/restore@v4
with:
fail-on-cache-miss: true
Expand Down Expand Up @@ -100,6 +100,14 @@ jobs:
appium > /tmp/appium.log &
sleep 3
- name: Test
env:
SIMULATOR_UDID: ${{ steps.get-simulator-udid.outputs.simulator_udid }}
TEST_CONTAINER_PATH: ${{ needs.build-ios-test-container-prod.outputs.built-app-path }}
run: |
cd tests/rn-test-container
yarn vitest
- name: Upload Appium Logs
uses: actions/[email protected]
if: ${{ always() }}
Expand Down
98 changes: 98 additions & 0 deletions tests/rn-test-container/native-test.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { beforeAll, describe, expect, inject, it, test } from 'vitest'
import { remote } from 'webdriverio'
import { execSync } from 'node:child_process'

function getSimulatorUdid() {
if (process.env.SIMULATOR_UDID) {
return process.env.SIMULATOR_UDID
}

console.warn('No SIMULATOR_UDID provided, trying to find a simulator automatically...')

try {
const listDevicesOutput = execSync('xcrun simctl list --json devices').toString()

const devicesData = JSON.parse(listDevicesOutput).devices

const runtimes = Reflect.ownKeys(devicesData)

const runtime = runtimes.find((r) => typeof r === 'string' && r.includes('SimRuntime.iOS-18'))

if (!runtime) {
throw new Error(`No available runtime found from ${JSON.stringify(runtimes)}`)
}

const device = devicesData[runtime].find((d) => d.name.includes('iPhone 16 Pro'))

if (!device) {
throw new Error(`No available device found from ${JSON.stringify(devicesData[runtime])}`)
}

console.info(`Found simulator device ${device.name} with udid ${device.udid}`)

return device.udid
} catch (error) {
if (error instanceof Error) {
error.message = `Failed to find an available simulator: ${error.message}`
}

throw error
}
}

function getWebDriverOpts() {
const capabilities = {
platformName: 'iOS',
'appium:options': {
automationName: 'XCUITest',

// deviceName: 'iPhone mini 2',
udid: getSimulatorUdid(),

app: process.env.TEST_CONTAINER_PATH,
// app: '/Users/z/Downloads/ios-test-container-prod.app',
// bundleId: 'host.exp.Exponent',

// Do not reset the simulator
// noReset: true,
},
}

const wdOpts = {
hostname: process.env.APPIUM_HOST || 'localhost',
port: process.env.APPIUM_PORT ? Number.parseInt(process.env.APPIUM_PORT, 10) : 4723,
logLevel: 'info' as const,
capabilities,
}

return wdOpts
}

describe('Native Test Test', () => {
test('should pass', () => {
getWebDriverOpts()
expect(true).toBe(true)
})

test('hello world', async () => {
const driver = await remote(getWebDriverOpts())

Check failure on line 78 in tests/rn-test-container/native-test.test.ts

View workflow job for this annotation

GitHub Actions / Native iOS Test (Prod)

native-test.test.ts > Native Test Test > hello world

Error: Failed to create session. WebDriverError: The operation was aborted due to timeout when running "http://localhost:4723/session" with method "POST" and args "{"capabilities":{"alwaysMatch":{"platformName":"iOS","appium:options":{"automationName":"XCUITest","udid":"E39D259E-3B73-4067-9C27-D156CD9558AF","app":"tests/rn-test-container/build/Build/Products/Release-iphonesimulator/RNTestContainer.app"}},"firstMatch":[{}]}}" ❯ startWebDriverSession ../../node_modules/webdriver/build/node.js:1033:11 ❯ Function.newSession ../../node_modules/webdriver/build/node.js:1265:41 ❯ Module.remote ../../node_modules/webdriverio/build/index.js:8147:20 ❯ native-test.test.ts:78:20
// console.log(JSON.stringify(driver.commandList))
// driver.executeScript('mobile: terminateApp', [{ bundleId: 'host.exp.Exponent' }])
// driver.executeScript('mobile: launchApp', [{ bundleId: 'host.exp.Exponent' }])

// const screenShot = await driver.takeScreenshot()
// console.log('screenShot', screenShot)
await driver.saveScreenshot('./screenshot.png')

// Select with accessibility id
const element = driver.$('~hello-word')

// expect element to contain text "Hello, World!"
const text = await element.getText()
expect(text).toBe('Hello One!')


// const settingsItem = await driver.$('//*[@text="Settings"]');
// await settingsItem.click();
}, 10 * 60 * 1000)
})

0 comments on commit a9f18b1

Please sign in to comment.