C#/Selenium/NUnit. Bamboo Server, AWS EC2.
From Bamboo I use AWS Run-Command from CLI in a Bamboo Script
aws ssm send-command --instance-ids "<instace id>" --document-name "AWS-RunRemoteScript" --parameters "{\"sourceType\":[\"GitHub\"],\"sourceInfo\":[\"{}\"],\"executionTimeout\":[\"3600\"],\"commandLine\":[\"C:\\\\scripts\\\\My_Tests.bat\"]}" --timeout-seconds 600 --region us-east-1
This talks to a .bat file that runs the tests, then when the tests are finished it fires a Powershell script to parse the TestResult.xml
@echo off start /w "CIT MyLoans Admin Tests" /D "C:\scripts\NUnit.ConsoleRunner.3.7.0\tools\" "nunit3-console.exe" "C:\MyTests\bin\Debug\Testing.dll" powershell "C:\scripts\parse-test.ps1"
The tests run correctly on my local machine in the foreground and background. The tests run correctly when manually run on the EC2 in the foreground and background.
The only time I have an issue is when I run the tests with that AWS Run-command.
The tests fail because of an element not displayed exception. This behavior is random. It doesn't always fail on the same DOM element.
The only way I can reproduce this exception is by setting my browser size small enough that the mobile menu takes over and the clickable element is indeed not displayed. I believe the AWS Run-Command is not allowing the browser to maximize as per the Selenium instructions:
try
{
driver.Manage().Window.Maximize();
}
catch
{
Comment("driver.Manage().Window.Maximize() did not work.");
((IJavaScriptExecutor)driver).ExecuteScript("window.resizeTo(1200, 1000);");
}
Comment("Window size: " + driver.Manage().Window.Size.ToString());
I Have tried:
- I force the browser to maximize in the .bat file.
- Using a PowerShell script in-place of the .bat file, with multiple ways to force a maximum window size with Process-Start -wait and other options.
- Put Thread.Sleep in many places for extended periods of time to ensure the browser window had time to maximize.
- I tried to force the AWS Agent service to run on the desktop as explained here. But, that did not seem to change anything.
- I have changed the .bat file command tho force the tests to run in the foreground. Did not work.
None of these solutions work.
So what is the difference between AWS Run-Command background and running the Selenium tests in the background manually? Why does Run-Command seem to run the tests so differently? I do not see any documentation from AWS about this situation.
Thank you for any advice!