提高AWS实例中的硒测试的屏幕分辨率

问题描述 投票:3回答:1

我正在用竹子进行硒测试。在竹子中,我使用的是aws实例的弹性剂-Windows 2012。默认情况下,代理的屏幕分辨率为1024x768。我只想提高屏幕分辨率。

是否可以在创建AMI时或启动代理后提高屏幕分辨率?

任何帮助将不胜感激。谢谢。

selenium amazon-ec2 bamboo
1个回答
0
投票

对于这种确切的情况,我可以提出一种解决方法-

问题是,除非您使用RDP进行连接,否则AWS EC2实例将使用默认基本图形适配器,其最大分辨率为1024x768。尝试通过Selenium设置浏览器大小将not有效,因为浏览器窗口将自动调整为最大桌面分辨率大小。

但是,您可以执行以下操作:在测试运行期间打开浏览器之后,您可以调用非托管代码,并通过user32.dll中的方法设置浏览器窗口的大小,并带有一个标志,该标志可以阻止Windows自动将浏览器窗口的大小调整为最大桌面分辨率大小。 >

代码如下(部分取自pinvoke.net)。这是一个C#示例,但可以重新设计成其他类型的解决方案,以从您的框架中调用。

在框架内某个类的类中,放置以下内容,然后在代码中实例化浏览器窗口,只需调用SetBrowserLocAndSize方法:

// Windows Interop Screen window position setter extern method
[DllImport("user32.dll", SetLastError = true)]
private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);

public static void SetBrowserLocAndSize(string windowTitle, int x, int y, int width, int height)
{
    var proc = Process.GetProcesses().FirstOrDefault(p => p.MainWindowTitle.Contains(windowTitle));

    if(proc == null)
    {
        throw new NotFoundException($"Could not find a window containing a window title of '{windowTitle}'");
    }

    var hwnd = proc.MainWindowHandle;

    // See https://www.pinvoke.net/default.aspx/user32.setwindowpos for information on this method
    SetWindowPos(hwnd, new IntPtr(0), x, y, width, height, 0x0100 | 0x0400 | 0x0040);
}
© www.soinside.com 2019 - 2024. All rights reserved.