How To Automatically Retry Failed Tests in Nunit

If you have some randomly failing tests, such as Selenium driver based tests and are using Nunit as testing framework, here is one way to enable automatic re-run of the those failing tests. (Works with Nunit 3+ adding a custom method attribute)

Source: How To Automatically Retry Failed Tests in Nunit – Testing repository

Problem with remote Selenium IE driver “Unable to find element with css selector”

Running my Selenium tests locally against IE11 works fine, but when calling remote Selenium server running the same browser and Selenium drivers setup I get this:

System.Exception : Timed out after 10 seconds, could not find visible element 'By.CssSelector: body'
 ----> OpenQA.Selenium.WebDriverTimeoutException : Timed out after 10 seconds
 ----> OpenQA.Selenium.NoSuchElementException : Unable to find element with css selector == body

The problem is connected to the fact that the IEDriverServer.exe runs the server IE11 version. In my case this is a Windows Server 2016 which has a higher security restriction.

For me the solution was to disable the Internet Explorer Enhanced Security Configuration. Follow this guide for the Windows Server 2016 version.

Disable Internet Explorer Enhanced Security Configuration in Windows Server 2016

The same error could also be caused by javascript not enabled for the driver:

options.AddAdditionalCapability("javascriptEnabled", "true");

or need driver to switch to the correct frame/window

webDriver.switchTo().defaultContent()

More info here:
https://github.com/SeleniumHQ/selenium/issues/3611

Powershell Generic Invoke-RestMethod / WebRequest error handler

From: https://stackoverflow.com/questions/39319680/onelogin-rest-api-with-powershells-invoke-restmethod

#generic Invoke-RestMethod / WebRequest error handler
#https://stackoverflow.com/questions/39319680/onelogin-rest-api-with-powershells-invoke-restmethod
function Failure {
$global:helpme = $body
$global:helpmoref = $moref
$global:result = $_.Exception.Response.GetResponseStream()
$global:reader = New-Object System.IO.StreamReader($global:result)
$global:responseBody = $global:reader.ReadToEnd();
Write-Host -BackgroundColor:Black -ForegroundColor:Red "Status: A system exception was caught."
Write-Host -BackgroundColor:Black -ForegroundColor:Red $global:responsebody
Write-Host -BackgroundColor:Black -ForegroundColor:Red "The request body has been saved to `$global:helpme"
break
}

Then, wrap all of your Invoke-RestMethod calls in a try Catch block like this.

try { 
  $e = Invoke-WebRequest 'https://api.us.onelogin.com/api/1/users/$id' `
     -Headers  @{ Authorization = "bearer:$token" } `
     -Body  ( @{ phone = "7709746046" } | ConvertTo-Json ) `
     -Method Put -ErrorAction:Stop -ContentType 'application/json' 
     } 
catch {Failure}

Now when you run into an error, you can see the actual message, like this

> Status: A system exception was caught.
{"status":{"error":true,"code":400,"type":"bad request","message":{"description":"notes is not a valid attribute for user model","attribute":"notes"}}}
The request body has been saved to $global:helpme

Windows PowerShell concatenate and escape multi-line string

$x = @"
"Curiouser and curiouser!" cried Alice (she was so much surprised, that for the moment she quite forgot how to speak good English); "now I'm opening out like the largest telescope that ever was! Good-bye, feet!"
"@
$x

Source: Windows PowerShell Tip: Using Windows PowerShell “Here-Strings”