【问题标题】:Switching off wifi on android application using appium dot net driver使用appium dot net driver在android应用程序上关闭wifi
【发布时间】:2015-10-05 12:08:23
【问题描述】:

我正在使用 appium dot net 驱动程序,我想关闭/打开 wifi。请建议在 c# 中使用 appium 或 adb 命令的方法,可以发送到设备以关闭 wifi

【问题讨论】:

    标签: c# android appium


    【解决方案1】:

    来自问题How to turn off Wifi via ADB?:

    启用 Wi-Fi:

    adb shell svc wifi enable 
    

    禁用 Wi-Fi:

    adb shell svc wifi disable
    

    来自问题Run Command Prompt Commands:

    System.Diagnostics.Process process = new System.Diagnostics.Process();
    System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
    startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
    startInfo.FileName = "cmd.exe";
    startInfo.Arguments = "/C adb shell svc wifi enable/disable";
    process.StartInfo = startInfo;
    process.Start();
    

    注意:我不懂C#,如有错误请指正。

    【讨论】:

      【解决方案2】:

      在 C# 中,我不确定直接方法,但你可以试试这个:

      禁用 WIFI:

      ((AndroidDriver<AppiumWebElement>)appiumDriver).ConnectionType = ConnectionType.AirplaneMode;
      

      启用 WIFI:

      ((AndroidDriver<AppiumWebElement>)appiumDriver).ConnectionType = ConnectionType.AllNetworkOn;
      

      【讨论】:

      • 不确定这个答案是否有效——抛出错误OpenQA.Selenium.WebDriverException : An unknown server-side error occurred while processing the command. Original error: Error executing adbExec. Original error: 'Command ''C:\\Program Files (x86)\\Android\\android-sdk\\platform-tools\\adb.exe' -P 5037 -s 19025D8359 shell am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true' exited with code 1'; Stderr: 'java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.AIRPLANE_MODE from pid=29791, uid=2000
      猜你喜欢
      • 2018-01-16
      • 1970-01-01
      • 2016-03-14
      • 1970-01-01
      • 1970-01-01
      • 2015-03-30
      • 2021-10-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多