Advanced Features - ProtoTest/ProtoTest.Golem GitHub Wiki
###Running Multiple Browsers In your App.Config you can set as many browsers as you want. All Tests will be repeated once per key that contains BrowserX.
<add key="Browser1" value="Firefox"/>
<add key="Browser2" value="Chrome"/>
<add key="Browser3" value="IE"/>
<add key="Browser4" value="Firefox"/>
###Parallel Tests
Multiple tests can be executed simultaneously using the [Parallelizable] attribute in MbUnit. Each test will automatically be spun up in a separate thread, with one driver each. The framework handles all this for you, use the driver class or Elements as normal. Use the [DependsOn("TestName")] attribute to order test execution.
The number of simultaneous threads must be set in the config. I don't recommend going over 5 when running locally :
In the App.Config :
<add key="DegreeOfParallelism" value="5" />
And now our code. This example just runs 5 copies of the same test simultaneously :
[Test, Parallelizable,ThreadedRepeat(5)]
public void TestThreadedRepeat()
{
OpenPage<GoogleHomePage>("http://www.google.com");
Assert.AreEqual(testDataCollection.Count,5);
}
###HTTP Proxy Golem includes a HTTP proxy, BrowserMob. It uses this proxy to capture HTTP traffic, and includes the .har file in the report. It also includes various methods for validating HTTP traffic. This is useful for testing services like Omniture or Google Analytics The proxy can be turned on using the following options :
<add key="StartProxy" value="True" />
<add key="UseProxy" value="True" />
The ports can be configured as such :
<add key="ProxyPort" value="18881" />
<add key="ProxyServerPort" value="18880" />
Traffic can be validated using the 'proxy' object's 'VerifyRequestMade' method included in the test :
proxy.VerifyRequestMade("http://www.google.com/");
Or it can be gotten using the "FilterEntries" method :
var entries = proxy.FilterEntries("www.google.com");
Full code example available in the Tests folder.
###Verifications and Waiting Golem includes the ability to perform Waits and Verifications. The two are identical, except that a Wait that fails will terminate the test, and a Verification will be logged with a screenshot and the test will continue. This allows multiple errors to be logged for a single run. By default, Golem will wait for an amount of time equal to the Config setting ElementTimeoutSec.
A custom Verification can be added using the TestBase.AddVerificationError() method. If no image is passed in a new screenshot will be taken.
TestBase.AddVerificationError("This is a failure message");
In addition verifications can be done using the driver object :
driver.VerifyElementVisible(By.Name("q"));
driver.WaitForPresent(By.Id("id"));
Or using the IWebDriver extensions :
driver.findElement(By.Name("q")).Verify().Visible();
Or using an Element;
searchField.Verify().Value(searchTerm);
The verification can even wait for a given amount of time :
searchField.Verify(30).Visible();
The Verify() and WaitUntil() methods can be chained together:
searchField.WaitUntil(30).Visible().Verify.Value(searchTerm).Click()
If the test should terminate, WaitUntil() can be used in place of Verify()
searchField.WaitUntil(30).Visible();
###Image Validations (Beta) Golem includes the ability to perform image based validations. For simplicity, the functionality is built into the Element class. Golem handles capturing, storing, and updating the images. If no image is found on the local system, it will automatically store the live image on the next run. In addition, all images can be updated using a Config value. The images are saved on the filesystem using the element name, so it should be unique. During runtime the new image is automatically scaled, so the image comparisons should work even when compared against an image of a different resolution, or rendered using a different browser or font.
Element searchField = new Element("SearchButton",By.Name("q"));
searchField.Verify().Image();
Image validations are configurable as follows :
<add key="UpdateImages" value="True" />
<add key="Fuzziness" value="50" />
<add key="Accuracy" value=".01" />
The image is analyzed in 256 sections. Fuzziness is the difference each section can have. Accuracy is the percentage of sections that can fail. Each image failure should highlight the sections that don't match. If a specific image needs to be tweaked, the fuzziness/accuracy parameters can be passed in :
searchField.Verify().Image(70,.05);
###Slowing down the tests If you want to slow down the rate of test execution, a sleep can be performed between each driver command :
<add key="CommandDelayMs" value="500" />