0

C#/Selenium/NUnit. Bamboo Server, AWS EC2.

  1. 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
    
  2. 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!

J-Roel
  • 520
  • 1
  • 4
  • 21
  • You should take the [tour], read [Ask] and [MCVE]. It sounds like your tests are finding a bug under some circumstances. Maybe it is a timing issue? It's not uncommon for some bugs to go unnoticed when tests are run on a single system under consistent circumstances. That's the whole point of distributing tests across environments. You haven't posted an MCVE, so it is unlikely anyone will be able to help you with this. Have you tried Amazon support? – jwdonahue Feb 12 '18 at 21:36

1 Answers1

1

This had nothing to do with the AWS Run-Command. It was in fact the EC2 instance's display resolution.

So after trying to force selenium into many "maximizes" I realized I was always getting weird resolutions 1040x784, 1004x748,1044x788... really odd. I knew that the full screen working resolution for our application requires a resolution of 1200.

So after many threads on stackoverflow, I was able to set the resolution using the "maximizing" functions below AND the headless versions of the browsers. I think the headless versions would not fall under the constraints of the EC2's display resolution. Without the headless attribute, nothing like setting the manage().Window.Size would work.

Here is the solution:

public static IWebDriver SetDriver(string _driver)
{
    IWebDriver driver;

    switch (_driver)
    {
        case "Chrome":
            ChromeOptions chrome_options = new ChromeOptions();
            chrome_options.AddArgument("headless");
            chrome_options.AddArgument("--window-size=1920,1080");
            driver = new ChromeDriver(chrome_options);
            break;
        case "Firefox":
            FirefoxOptions ffOptions = new FirefoxOptions();
            ffOptions.AddArgument("headless");
            ffOptions.AddArgument("--window-size=1920,1080");
            driver = new FirefoxDriver(ffOptions);
            break;
        //case "IE":
            //haven't looked this one up yet
            //break;
        default:
            break;
        }
        Thread.Sleep(1000);
        return driver;
    }
J-Roel
  • 520
  • 1
  • 4
  • 21
  • Here is an excellent post I found with more options and settings for the driver options: https://www.edgewordstraining.co.uk/2017/10/13/chromedriver-options-starting-chrome-webdriver/ – J-Roel Feb 12 '18 at 23:54