【问题标题】:Change orientation through Selenium tests in BrowserStack通过 BrowserStack 中的 Selenium 测试改变方向
【发布时间】:2013-12-26 17:13:08
【问题描述】:

我正在评估使用 BrowserStack 的自动化 selenium 测试的使用。我目前正在尝试更改在 BrowserStack 上的模拟器上运行的设备的方向,无论是 Android 还是 iPad。我已经按照 Selenium 文档实现了 IRotatable 接口:

public class RotatableRemoteWebDriver : RemoteWebDriver, IRotatable
{
    public RotatableRemoteWebDriver(Uri uri, DesiredCapabilities dc, ScreenOrientation initialOrientation = ScreenOrientation.Portrait): base(uri, dc)
    {
        this.Orientation = initialOrientation;
    }

    public ScreenOrientation Orientation
    {
        get
        {
            var orientationResponse = this.Execute(DriverCommand.GetOrientation, null);
            return (ScreenOrientation)Enum.Parse(typeof(ScreenOrientation), orientationResponse.Value.ToString(), true);
        }
        set
        {
            var response = this.Execute(DriverCommand.SetOrientation, new Dictionary<string, object>() { { "orientation", value.ToString().ToUpperInvariant() } });
        }
    }
}

当我尝试将它与 iPad 功能一起使用时,我直接收到一个异常,提示“资源方法无效:POST /session/1d410f56479543a99410140bc39dc3d0d6d94c57/orientation”。对 Android 功能的相同调用确实成功了,但它似乎并没有改变方向,因为我之后直接截取了屏幕截图并且设备仍处于纵向模式。

知道是否可以通过自动化测试改变方向,还是我应该放弃并为此使用 Screenshots API?

【问题讨论】:

    标签: selenium browserstack


    【解决方案1】:

    如我所见,BrowserStack 在 iOS 模拟器上运行 iPhone 驱动程序进行硒测试。由于根据 selenium 站点不推荐使用驱动程序 [请参阅:https://code.google.com/p/selenium/wiki/IPhoneDriver],因此在 selenium 中支持 iOS 的命令非常有限。方向是驱动程序本身不支持的方向。 BrowserStack 正在开发该功能以提供支持,并会在完成后立即更新。

    对于您的 android 问题。您可以通过将“browserstack.debug”功能传递为“true”来在调试模式下运行测试吗?这将为您提供完整的桌面屏幕截图,并向您显示命令前后的方向。如果您尝试打开的网站没有响应,您可能会看到横向和纵向屏幕截图没有区别。

    希望我回答了您的疑虑。

    【讨论】:

    • 感谢您的回复,我现在看到iPhone驱动程序不支持它。不过,对于 android,我将 debug 设置为 true 并看到 Set Orientation LANDSCAPE 命令已发送并且似乎已被理解。但是我在改变方向之前和之后的截图是一样的,都是纵向截图。
    • 哦.. 如果网站没有响应(在方向更改时不会更改尺寸),应该会发生这种情况。您可以 ping 网站吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多