使用 selenium 和 Appium 是否可以在 wifi 网络之间切换? [英] Using selenium and Appium is it possible to change between wifi networks?

查看:29
本文介绍了使用 selenium 和 Appium 是否可以在 wifi 网络之间切换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用:selenium webdriver、rubygems、appium、android 和 ios 设备

Using: selenium webdriver, rubygems, appium, android and ios devices

我正在测试的应用程序有一个按钮,只有在连接到特定无线网络时才会启用该按钮.我想创建一个脚本来检查按钮是否处于活动状态

The app I am testing has a button which becomes enabled only when connected to a specific wireless network. I'd like to create a script which will check if the button is active or not

  vKioskStatus = element.enabled?
  puts(vKioskStatus)

如果它不活动,那么我想更改 wifi 网络.是否可以在移动设备上自动更改网络?

If it is not active, then I'd like to change wifi networks. Is that possible to automate changing networks on a mobile device?

更新

我在尝试使用 getNetworkConnection 时收到以下错误.有什么需要我添加的吗?

I'm receiving the following error when trying to use getNetworkConnection. Is there a require I need to add?

<main>': undefined method `getNetworkConnection' for #<Selenium::WebDriver::Driver:0x..fe1a5511e browser=:firefox> (NoMethodError)

这是我的代码:

require 'rubygems'
require 'selenium-webdriver'
require 'uri'
require 'appium_lib'

require_relative 'AndroidLib'
cButton = Buttons.new

driver = Selenium::WebDriver.for(:remote, :url => "http://127.0.0.1:4723/wd/hub") # Works for Android
sleep(5)

bob = driver.getNetworkConnection()
puts bob

推荐答案

您可以使用以下 appium 命令在 Android 中切换 wifi 连接(在 iOS 中不可用),

you can toggle the wifi connection in Android (not possible in iOS) using the below appium commands,

开启飞行模式:

# Python

def enableFlightMode(self,context):
        driver.mobile.set_network_connection(driver.mobile.AIRPLANE_MODE)
        driver.implicitly_wait(10)
        if driver.network_connection == 1:
            self.report_pass("The network connection is disabled in the mobile and flight mode is active.")
        else:
            self.report_fail("The flight mode is not active yet!")

并禁用飞行模式:

def enableFlightMode(self,context):
        driver.mobile.set_network_connection(driver.mobile.AIRPLANE_MODE)
        driver.implicitly_wait(10)
        if driver.network_connection == 1:
            self.report_pass("The network connection is disabled in the mobile and flight mode is active.")
        else:
            self.report_fail("The flight mode is not active yet!")

这篇关于使用 selenium 和 Appium 是否可以在 wifi 网络之间切换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆