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!
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.
I could find some open issues related to this problem:
So, these are my questions:
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.
This works for me:
driver.manage().window().setSize(new Dimension(1250, 720));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With