【问题标题】:Access iOS Control Center using appium使用 appium 访问 iOS 控制中心
【发布时间】:2015-09-03 23:58:26
【问题描述】:

我正在尝试使用 appium 和以下代码打开控制中心:

    int halfWidth = driver.manage().window().getSize().width / 2;
    int screenHeight = driver.manage().window().getSize().height;
    driver.swipe(halfWidth, screenHeight-5, halfWidth, screenHeight-300, 500);  // driver is instance of IOSDriver

应用程序无需打开控制中心,而是简单地从底部向上绘制屏幕(使用坐标输入)。有人知道如何使用 appium 和滑动(或任何其他方式)打开控制中心吗?

谢谢,查理

【问题讨论】:

  • 看 swipe() 方法的细节,我怀疑可能是因为我们按下,然后移动,而不是从头开始移动......但我会等待看看其他人可以确认一下。

标签: ios automation swipe appium control-center


【解决方案1】:

好的,经过大量调查,在我看来这是不可能的。如果你真的需要这个功能,那么我认为像茄子这样的工具可能是合适的。

【讨论】:

    【解决方案2】:

    我们可以做到。我在 Appium 1.4.13 中尝试过,我可以更改设置。

    我使用下面的代码来更改我的 iPadAir2 中的设置。

    int height = driver.findElementByClassName("UIAWindow").getSize().getHeight();
    int width = driver.findElementByClassName("UIAWindow").getSize().getWidth();
    driver.swipe(width-100, height, width-100, height-200, 500);
    driver.findElementByAccessibilityId("Wi-Fi").click();
    

    【讨论】:

    • iOS 版本和/或设备之间的 wifi 可访问性 ID 是否发生了变化?您在哪里找到控制中心 wifi 的可访问性 ID 值?它是否记录在某处?我已经使用代码 sn-p 调出控制中心,但它无法通过可访问性 ID 找到 wifi 按钮/图标。我在运行 iOS 8.4.1、Appium 1.4.16 和 XCode 7.2 的 iPod Touch 上进行了测试。
    • 我不认为accessibilityId 操作系统版本之间的变化。我使用 Appium Inspector 来识别 Wifi 按钮的accessibilityID。
    • 嗨,我收到以下错误。任何建议都会很棒代理 [POST /element] 到 [POST localhost:8100/session/340CCDB4-E673-42F7-8767-FE27934B2917/… with body: {"using":"xpath","value":"//XCUIElementTypeOther[@label='Wi-Fi']"}状态为 200 的响应: {"value":"*** setObjectForKey: object cannot be nil (key: top)\n\n(\n\t0 HTTP]
    【解决方案3】:

    我可以使用适用于 iOS 的 Appium 1.6.4-beta 关闭 Wifi 或打开飞行模式

    从屏幕底部向上滑动 点击继续链接 点击 Wifi 或 Airplane 按钮 从屏幕中间向下滑动

    但这似乎在模拟器中没有做任何事情。我实际上必须关闭我的计算机互联网连接才能禁用模拟器上的互联网。

    @iOSFindBy(xpath = "//XCUIElementTypeSwitch[@name='Wi-Fi']")
    private MobileElement WIFI_MODE_BUTTON;
    
    public void disableWifi()  {
        openToolBarMenu();
        //if wifi is on/true then turn it off
       if (WIFI_MODE_BUTTON.getAttribute("value") == "true" ) {
           Autoscope.tap(WIFI_MODE_BUTTON);
       }
        closeToolBarMenu();
    }
    
    
    @iOSFindBy(xpath = "//XCUIElementTypeButton[@name='Continue']")
    private MobileElement CONTINUE_BUTTON; //continue button on control center
    
    public void openToolBarMenu() {
        Autoscope.scrollFromBottomOfScreen();
        if (Autoscope.isElementDisplayed(CONTINUE_BUTTON)) {
            Autoscope.tap(CONTINUE_BUTTON);
        }
    }
    
    
    static public void scrollFromBottomOfScreen() {
        TouchAction touchAction = new TouchAction(autoscopeDriver);
    
        int xStartPoint = Math.round(pixelWidth() / 2);
        int yStartPoint = pixelHeight();
        int yEndPoint = 0 - yStartPoint;
        touchAction.press(xStartPoint, yStartPoint).moveTo(0, yEndPoint).release().perform();
    }
    

    【讨论】:

      【解决方案4】:

      Appium 1.6.5,你可以使用滑动方法,下面是我的 Python 代码:

      window_size = self.driver.get_window_size()  # this returns dictionary
      el = self.driver.find_element(*self.configuration.CommonScreen.WEB_VIEW)
      action = TouchAction(self.driver)
      start_x = window_size["width"] * 0.5
      start_y = window_size["height"]
      end_x = window_size["width"] * 0.5
      end_y = window_size["height"] * 0.5
      action.press(el, start_x, start_y).wait(100).move_to(el, end_x, end_y).release().perform() 
      

      【讨论】:

        【解决方案5】:

        此代码将有助于调出控制中心,当您在应用程序中时,您可以执行控制中心中可用的所有操作

        new TouchAction(DriverConfig.getInstance().getDriver()).press(point(250, 735)).waitAction(waitOptions(Duration.ofSeconds(3))).moveTo(point(250, -460)).release()
                                .perform();
        

        【讨论】:

        • @Alessio 很高兴代码有效,我将编辑我的答案并提供更多详细信息,谢谢
        【解决方案6】:

        C#:iOS 13.x

        //Opening control center
        
        var size = Driver.Manage().Window.Size;
        
        var height = size.Height;
        
        var width = size.Width;
        
        var touchAction = new TouchAction(Driver);
        
        touchAction.Press(width - 100, height).Wait(1000).MoveTo(width - 100, height - 200).Release().Perform();
        
        //Clicking the WiFi button
        
        Driver.FindElementByAccessibilityId("wifi-button").Click();
        
        //Checking if WiFi enabled or not
        
        var myElement = Driver.FindElementByAccessibilityId("wifi-button");
        
        var result = myElement.GetAttribute("label");
        
        if(!result.Contains("Wi-Fi, Not Connected") && !result.Equals("Wi-Fi"))
        {
            // WiFi connected
        }
        else
        {
            // WiFi Not connected
        }
        

        【讨论】:

          【解决方案7】:

          这个想法是模拟您用来在相应 iOS 设备上打开控制中心的滑动操作。我的设备是 iPhone 11,所以它从右上角(凹槽的右侧)向下滑动。我的代码是从 position(x,y) (80% width, 0) 滑动到 (80% width, 50% height)

              Dimension size = getScreenSize();
          
              int x = (size.getWidth() / 5) * 4;
              int startY = 0;
              int endY = size.getHeight() / 2;
          
              new TouchAction(driver).press(PointOption.point(x, startY))
                      .waitAction(WaitOptions.waitOptions(Duration.ofSeconds(1)))
                      .moveTo(PointOption.point(x, endY))
                      .release().perform();
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2016-02-09
            • 1970-01-01
            • 1970-01-01
            • 2018-11-21
            • 2022-07-15
            • 2019-11-16
            • 2020-12-15
            • 2016-06-01
            相关资源
            最近更新 更多