【发布时间】:2021-08-14 08:54:20
【问题描述】:
我正在构建一个在浏览器中运行的网络应用程序。此 Web 应用是 PWA,如果设备“离线”,应该可以继续正常工作。
我正在尝试编写要在 AWS Device Farm 上运行的 Appium 测试以验证此行为。
AWS Device Farm Docs 建议可以“在测试期间更改网络条件”,并指出使用CreateNetworkProfile。然而,当我使用这个 API 时,虽然我可以创建一个新的网络配置文件,但我无法在测试中途激活配置文件。
这是一个简单测试的例子:
const webdriverio = require('webdriverio')
const assert = require('chai').assert
const {
CreateNetworkProfileCommand,
DeviceFarmClient
} = require('@aws-sdk/client-device-farm')
const offlineProfile = new CreateNetworkProfileCommand({
projectArn:
'arn:aws:devicefarm:us-west-2:XXXXXXXXXXXX:project:XXXXXXXXXXXXXXXXXXX',
name: 'offline',
uplinkBandwidthBits: 0,
downlinkBandwidthBits: 0
})
const onlineProfile = new CreateNetworkProfileCommand({
projectArn:
'arn:aws:devicefarm:us-west-2:XXXXXXXXXXXX:project:XXXXXXXXXXXXXXXXXXX',
name: 'online',
uplinkBandwidthBits: 104857600,
downlinkBandwidthBits: 104857600
})
const credentials = {
accessKeyId: '',
secretAccessKey: '',
sessionToken: ''
}
const deviceFarmClient = new DeviceFarmClient({
region: 'us-west-2',
credentials
})
describe('Test Online and Offline', function () {
it('Should go to Google then go offline then fail to get to Bing', async function () {
const client = await webdriverio.remote({
capabilities: {
automationName: 'XCUITest',
platformName: process.env.DEVICEFARM_DEVICE_PLATFORM_NAME,
deviceName: process.env.DEVICEFARM_DEVICE_NAME,
platformVersion: process.env.DEVICEFARM_DEVICE_OS_VERSION,
browserName: 'Safari'
},
path: '/wd/hub',
host: process.env.APPIUM_HOST || 'localhost',
port: process.env.APPIUM_PORT || 4723,
logLevel: 'info'
})
await client.url('https://www.google.com')
const title = await client.getTitle()
assert.equal(title, 'Google')
console.log('Online check completed')
const response = await deviceFarmClient.send(offlineProfile)
console.log(response)
// At this point I need the device to switch to using the new "offlineProfile" NetworkProfile
console.log("Network switched to 'offline'")
await client.url('https://www.bing.com')
const title2 = await client.getTitle()
assert.equal(title2, 'Bing') // This step is expected to fail because the device should be offline
const response2 = await deviceFarmClient.send(onlineProfile)
console.log(response2)
// At this point I need the device to switch to using the new "onlineProfile" NetworkProfile to clean up
await client.deleteSession()
})
})
是否可以使用 Device Farm 做我想做的事情?如果是,我将如何在测试中切换活动的网络配置文件?
【问题讨论】:
标签: amazon-web-services automated-tests appium aws-device-farm