【问题标题】:Is it possible to modify the Network Profile during a test case on Device Farm?是否可以在 Device Farm 上的测试用例期间修改网络配置文件?
【发布时间】: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


    【解决方案1】:

    我已收到 AWS Support 对此的答复 - 不幸的是,不支持对网络配置文件进行动态更改(在撰写本文时)。

    支持回复:

    AWS Device Farm 服务仅允许在安排测试运行时而不是在测试处于运行状态时选择自定义网络配置文件。通过指定“networkProfileArn”参数,只能选择在 Device Farm 中创建的自定义网络配置文件在“ScheduleRun”API [1] 中使用。因此,我们必须通过我们的测试脚本或任何支持的库来管理网络配置。

    根据服务团队的上述声明;很抱歉,我们的自定义配置文件的动态网络配置文件处理尚不支持。因此,我们可以选择使用 Selenium 框架提供的“Mobile JSON Wire Protocol Specification”API,并控制设备的网络连接设置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多