Appium ios 7.x 中的 appium 封装的的锁屏以及网络连接方法根本无用啊

云飞凌风 · 2014年09月18日 · 1548 次阅读

下面是我的代码

//开关网络连接操作
public static void networkConnectionTest(boolean airplaneMode, boolean wifi, boolean data,AppiumDriver driver){
    log.info("开关网络连接操作");
    try{
      NetworkConnectionSetting networkConnection = new NetworkConnectionSetting(false, true, true);
      networkConnection.setData(data);
      networkConnection.setWifi(wifi);
      driver.setNetworkConnection(networkConnection);
      networkConnection = driver.getNetworkConnection();
      assertEquals(new NetworkConnectionSetting(false, wifi, data), networkConnection);
    }catch(Exception e){
        log.info("开关网络连接操作失败"+ e.getMessage());
    }
}

下面是报错信息,无法断开网络连接

ERROR running Appium command: Object [object Object] has no method 'setNetworkConnection'
Command duration or timeout: 20 milliseconds
Build info: version: '2.42.2', revision: '6a6995d31c7c56c340d6f45a76976d43506cd6cc', time: '2014-06-03 10:52:47'
System info: host: 'ifufeiyangtekiMac.local', ip: '192.168.235.131', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.4', java.version: '1.8.0'
Driver info: io.appium.java_client.AppiumDriver

请问,有没有其它的方法?

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 15 条回复 时间 点赞

试了好多次,上面的办法无法断开 wifi,模拟器以及真机上都无断开 wifi,
下面为我的调用方法

networkConnectionTest(false,false,true, driver);

运行提示报错,说是没有 setNetworkConnection 这个方法,但是我看到 AppiumDriver 中有这个方法啊。

org.openqa.selenium.WebDriverException: ERROR running Appium command: Object [object Object] has no method 'setNetworkConnection'
Command duration or timeout: 8 milliseconds
Build info: version: '2.42.2', revision: '6a6995d31c7c56c340d6f45a76976d43506cd6cc', time: '2014-06-03 10:52:47'
System info: host: 'ifufeiyangtekiMac.local', ip: '192.168.235.131', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.4', java.version: '1.8.0'
Driver info: io.appium.java_client.AppiumDriver
Capabilities [{app=net.os.iosapp, networkConnectionEnabled=false, warnings={}, databaseEnabled=false, deviceName=iPhone, platform=MAC, desired={app=net.os.iosapp, appium-version=1.0, platformVersion=7.1, platformName=iOS, deviceName=iPhone}, appium-version=1.0, platformVersion=7.1, webStorageEnabled=false, locationContextEnabled=false, browserName=iOS, takesScreenshot=true, javascriptEnabled=true, platformName=iOS}]
Session ID: d77c5c8b-e941-479a-983a-53cac363281a
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:95)
    at io.appium.java_client.AppiumDriver.setNetworkConnection(AppiumDriver.java:558)
    at com.teiron.app.oschina.TestRealDevice.testHello(TestRealDevice.java:79)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

java.lang.IllegalMonitorStateException
    at java.lang.Object.wait(Native Method)
    at java.lang.Object.wait(Object.java:502)
    at com.teiron.app.oschina.TestRealDevice.tearDown(TestRealDevice.java:69)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:33)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)


你自己这个 java client 是啥版本啊

匿名 #4 · 2014年09月18日

被楼主彪悍的主题吸引,以为 iOS 居然有开放控制 WiFi 的接口。。。结果一看楼主的截图。。艾玛。。。This is an Android-only method !😒

不写环境,不写版本,不写平台,不看日志,不看提示,这种问题无法回答

#3 楼 @lihuazhang java client 版本是:1.6.2

#4 楼 @link1220 那 ios 的就无法控制了么?请问有没有其它的版本可以控制网络?

我测试下可以运行。

#8 楼 @lihuazhang 运行在苹果真机或者 ios 模拟器上没问题,但是起不到关闭网络连接的作用。

#9 楼 @wangcityboy 。。。你真是无敌了。这个是只给 android。 ios 凑什么热闹啊。

#10 楼 @lihuazhang 那 ios 的断开网络连接就没其它的办法通过代码来实现了么?

#11 楼 @wangcityboy 期待你的分享。

匿名 #12 · 2014年09月19日

#7 楼 @wangcityboy 自己封装一个方法,把系统 Settings 调起来,通过 Xpath 一步步的去点击。。。

#13 楼 @link1220 好像比较难做。 Settings 这种都是不允许操作的。

匿名 #14 · 2014年09月21日

#14 楼 @lihuazhang 先把自己的 APP 启起来,然后通过小助手点击一步步的可以把 Setting 从后台调到前台,然后就可以通过 xpath 来点击所有设置选项了,只是这个时候如果涉及输入法会比较难搞,得自己写一个方法解析系统键盘,当然我认为这是一种非常 low 的方法。。。暂时没有找到方便的啊。。。😁

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册