Skip to content

Instantly share code, notes, and snippets.

@leonardoeloy
Created July 9, 2012 12:06
Show Gist options
  • Save leonardoeloy/3076097 to your computer and use it in GitHub Desktop.
Save leonardoeloy/3076097 to your computer and use it in GitHub Desktop.
Multiple browsers tests with Webinator - Not pretty, but effective.
namespace Test
{
class UnitTest
{
private static MultipleBrowsers _multipleBrowsers;
[ClassInitialize]
public static void ClassInitialize(TestContext context)
{
_multipleBrowsers = new MultipleBrowsers();
}
/// <summary>
/// Verifies if an alert message is being displayed given an invalid e-mail.
/// </summary>
[TestMethod]
public void ShouldAlertWhenGivenInvalidEmail()
{
_multipleBrowsers.RunTest(_ShouldAlertWhenGivenInvalidEmail,
new Config.AvailableBrowsers[]
{
Config.AvailableBrowsers.InternetExplorer,
Config.AvailableBrowsers.Firefox,
Config.AvailableBrowsers.Chrome
});
}
private void _ShouldAlertWhenGivenInvalidEmail(IWebManager web)
{
var invalidEmail = "invalidemail.com";
var invalidEmailMessage = "Invalid e-mail, please verify and try again.";
RegisterWith(invalidEmail, web);
var alertMessage = web.GetText(LocateBy.Xpath("//*[@id='RegistrationMessage']"));
Assert.IsNotNull(alertMessage);
Assert.AreEqual(invalidEmailMessage, alertMessage);
}
}
}
namespace Test
{
class UnitTest
{
private static MultipleBrowsers _multipleBrowsers;
[ClassInitialize]
public static void ClassInitialize(TestContext context)
{
_multipleBrowsers = new MultipleBrowsers();
}
/// <summary>
/// Verifies if an alert message is being displayed given an invalid e-mail.
/// </summary>
[TestMethod]
public void ShouldAlertWhenGivenInvalidEmail()
{
_multipleBrowsers.RunTest(delegate(IWebManager web)
{
var invalidEmail = "invalidemail.com";
var invalidEmailMessage = "Invalid e-mail, please verify and try again.";
RegisterWith(invalidEmail, web);
var alertMessage =
web.GetText(LocateBy.Xpath("//*[@id='RegistrationMessage']"));
Assert.IsNotNull(alertMessage);
Assert.AreEqual(invalidEmailMessage, alertMessage);
},
new Config.AvailableBrowsers[]
{
Config.AvailableBrowsers.InternetExplorer,
Config.AvailableBrowsers.Firefox,
Config.AvailableBrowsers.Chrome
});
}
}
}
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Webinator;
namespace TestHelpers
{
class MultipleBrowsers
{
private Config _config;
public MultipleBrowsers()
{
_config = new Config
{
LogScreenshots = true,
LogLevel = Config.AvailableLogLevels.Verbose,
BaseUrl = "about:blank",
Framework = Config.AvailableFrameworks.WebDriver
};
}
public void RunTest(Action<IWebManager> action, Config.AvailableBrowsers[] browsers)
{
foreach(var browser in browsers)
{
// Diagnostics kinda deprecated, but should do the trick even with MSTest.
Debug.WriteLine("Running test with " + browser);
_config.Browser = browser;
var web = WebManagerFactory.CreateInstance(_config);
action(web);
web.CloseBrowser();
}
}
}
}
@leonardoeloy
Copy link
Author

If the test fails for one browser, it will flag the whole test as failed. Disadvantage? I don't think so.
I think this as a safe measure for a feature. If it isn't consistent for one browser, it will get fixed. This process might introduce a bug in another browser.

@leonardoeloy
Copy link
Author

Ok, found a proper way do this with NUnit: http://stackoverflow.com/a/7854838/1464825

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment