Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EdgeDriver - Cannot change window size in Edge

I am using the EdgeDriver for running automation tests on my browser (Edge 38.14393.0.0). My tests are in C#, so I am using the .NET driver:

using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Edge;

var options = new EdgeOptions();
options.PageLoadStrategy = EdgePageLoadStrategy.Normal;

RemoteWebDriver driver = return new EdgeDriver(Environment.CurrentDirectory, options, TimeSpan.FromSeconds(60));

driver.SetDocumentSize(new Size(800, 600)); // HERE!

The error

This code is the one I run at the beginning of the test. And it fails at the last line with:

Class Initialization method Web.TestSuite.UIRendering.RenderingTestSuiteEdge.TestClassInitialize threw exception. System.InvalidOperationException: System.InvalidOperationException: A window size operation failed because the window is not currently available.

With this stack trace:

OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse) in c:\Projects\webdriver\dotnet\src\webdriver\Remote\RemoteWebDriver.cs: line 1126
OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) in c:\Projects\webdriver\dotnet\src\webdriver\Remote\RemoteWebDriver.cs: line 920
OpenQA.Selenium.Remote.RemoteWindow.set_Size(Size value) in ...

FYI Be aware that I have other tests running on Chrome and IE11 using their respective drivers. When I call SetDocumentSize on those, I get no errors.

Open issues

I could find some open issues related to this problem:

  • https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/9340417/
  • https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8778306/

Questions

So, these are my questions:

  • Has anybody succeeded in setting the window size in Edge?
  • Is this problem I am hitting a known issue? If so, is it fixed? The referenced issues (which look similar) are still open and no status provided.
  • Is there any workaround?
like image 219
Andry Avatar asked Oct 18 '22 20:10

Andry


2 Answers

Try one of those for C#:

driver.Manage().Window.Size = new Size(1920, 1080);
driver.Manage().Window.Maximize();

Although I encounter that error for different reason (like the one here -> https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10319887/).

Now I kill all process of the driver & edge before each test so hopefully it will be resolved like that:

try
{
     foreach (var process in Process.GetProcessesByName("MicrosoftWebDriver"))
     {
           process.Kill();
     }

     foreach (var process in Process.GetProcessesByName("MicrosoftEdge"))
     {
           process.Kill();
     }
}
catch (Exception)
{
}

Also if you run them on remote machine via RDP for example it will make the same error when you close the RDP. This is the current workaround that I found for it:

Create a batch file with this code:

for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do (
  %windir%\System32\tscon.exe %%s /dest:console
)

Create a desktop shortcut to this file. To do this, right-click the batch
file and select Send to | Desktop (create shortcut).

In the shortcut properties, click Advanced and select Run as administrator.

Now, when you need to disconnect from Remote Desktop, double-click this shortcut on the remote computer (in the Remote Desktop window).

Thanks to https://support.smartbear.com/testcomplete/docs/testing-with/running/via-rdp/keeping-computer-unlocked.html for the script.

like image 131
Rain9333 Avatar answered Oct 21 '22 09:10

Rain9333


This works for me:

driver.manage().window().setSize(new Dimension(1250, 720));
like image 21
Travis Needham Avatar answered Oct 21 '22 07:10

Travis Needham