Created
July 9, 2012 12:06
-
-
Save leonardoeloy/3076097 to your computer and use it in GitHub Desktop.
Multiple browsers tests with Webinator - Not pretty, but effective.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.