在执行测试套件时,我必须在Android设备中可用的不同wifi网络之间切换。在执行过程中,我必须将wifi连接从Wifi_Network_1更改为Wifi_Network_2,前提是知道wifi网络的ssid名称和密码。怎么做呢?我正在使用:
Appium server -->1.8.1
java-client --> 6.1.0
selenium-java --> 3.13.0由于NetworkConnectionSetting已被降级,我无法为其找到替代方案。我可以打开/关闭wifi
driver.toggleWifi();但是它不适合我的情况,因为我需要在使用SSID名称和密码的不同wifi网络之间切换。提前谢谢。
发布于 2018-07-13 07:35:04
嗨,我正在使用这个方法,Appium不推荐他们使用wifi,我已经通过来自亚行的命令通过控制台创建了我自己的覆盖。它对我有用,所以试一试:
public synchronized boolean wifiSetup(String udid, boolean flg) {
synchronized (this) {
String flgEnabled = (flg) ? "enable" : "disable";
List<String> output = Console.runProcess(false, "adb -s " + udid + " shell am broadcast -a io.appium.settings.wifi --es setstatus " + flgEnabled);
for (String line : output) {
System.err.println(line);
if (line.equalsIgnoreCase("Broadcast completed: result=-1"))
return true;
}
return false;
}
}使用关闭
wifiSetup("xxxUDIDfromAndroid", false); 使用在上切换
wifiSetup("xxxUDIDfromAndroid", true); 下面是调用控制台的部分内容:
public class Console {
private static final String[] WIN_RUNTIME = { "cmd.exe", "/C" };
private static final String[] OS_LINUX_RUNTIME = { "/bin/bash", "-l", "-c" };
private Console() {
}
private static <T> T[] concat(T[] first, T[] second) {
T[] result = Arrays.copyOf(first, first.length + second.length);
System.arraycopy(second, 0, result, first.length, second.length);
return result;
}
@SuppressWarnings({ "hiding"})
private static <String> String[] concatStr(String[] first, String[] second) {
String[] result = Arrays.copyOf(first, first.length + second.length);
System.arraycopy(second, 0, result, first.length, second.length);
return result;
}
public static List<String> runProcess(boolean isWin, String... command) {
String[] allCommand = null;
try {
if (isWin) {
allCommand = concat(WIN_RUNTIME, command);
} else {
allCommand = concat(OS_LINUX_RUNTIME, command);
}
ProcessBuilder pb = new ProcessBuilder(allCommand);
pb.redirectErrorStream(true);
Process p = pb.start();
p.waitFor();
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String _temp = null;
List<String> line = new ArrayList<String>();
while ((_temp = in.readLine()) != null) {
// system.out.println("temp line: " + _temp);
line.add(_temp);
}
// system.out.println("result after command: " + line);
return line;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}}
希望这能帮上忙
https://stackoverflow.com/questions/51319865
复制相似问题