-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
03b8b57
commit e267aa3
Showing
3 changed files
with
140 additions
and
16 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
using OpenQA.Selenium; | ||
using OpenQA.Selenium.Chrome; | ||
using OpenQA.Selenium.Firefox; | ||
using OpenQA.Selenium.Remote; | ||
using OpenQA.Selenium.Safari; | ||
|
||
namespace NUnit_TestingBot_Sample; | ||
|
||
public class ParallelTests | ||
{ | ||
[TestFixture("chrome", "latest", "Windows 10")] | ||
[TestFixture("firefox", "latest", "SONOMA")] | ||
[Parallelizable(ParallelScope.Fixtures)] | ||
public class TbNUnit_ParallelTest | ||
{ | ||
private IWebDriver driver; | ||
private string browser; | ||
private string version; | ||
private string os; | ||
|
||
public TbNUnit_ParallelTest(String browser, String version, String os) | ||
{ | ||
this.browser = browser; | ||
this.version = version; | ||
this.os = os; | ||
} | ||
|
||
[SetUp] | ||
public void Init() | ||
{ | ||
DriverOptions browserOptions; | ||
if (this.browser == "firefox") | ||
{ | ||
browserOptions = new FirefoxOptions() | ||
{ | ||
BrowserVersion = this.version, | ||
PlatformName = this.os | ||
}; | ||
} | ||
else if (this.browser == "safari") | ||
{ | ||
browserOptions = new SafariOptions() | ||
{ | ||
BrowserVersion = this.version, | ||
PlatformName = this.os | ||
}; | ||
} | ||
else | ||
{ | ||
browserOptions = new ChromeOptions() | ||
{ | ||
BrowserVersion = this.version, | ||
PlatformName = this.os | ||
}; | ||
} | ||
|
||
var tbOptions = new Dictionary<string, string> | ||
{ | ||
["key"] = Environment.GetEnvironmentVariable("TESTINGBOT_KEY"), | ||
["secret"] = Environment.GetEnvironmentVariable("TESTINGBOT_SECRET"), | ||
["name"] = TestContext.CurrentContext.Test.Name, | ||
["selenium-version"] = "3.14.0" | ||
}; | ||
|
||
browserOptions.AddAdditionalOption("tb:options", tbOptions); | ||
|
||
driver = new RemoteWebDriver(new Uri("https://hub.testingbot.com/wd/hub"), browserOptions.ToCapabilities(), TimeSpan.FromSeconds(600)); | ||
} | ||
|
||
[Test] | ||
public void GoogleTest() | ||
{ | ||
driver.Navigate().GoToUrl("http://www.google.com"); | ||
StringAssert.Contains("Google", driver.Title); | ||
IWebElement query = driver.FindElement(By.Name("q")); | ||
query.SendKeys("TestingBot"); | ||
query.Submit(); | ||
} | ||
|
||
[TearDown] | ||
public void CleanUp() | ||
{ | ||
bool passed = TestContext.CurrentContext.Result.Outcome.Status == NUnit.Framework.Interfaces.TestStatus.Passed; | ||
try | ||
{ | ||
// Logs the result to TestingBot | ||
((IJavaScriptExecutor)driver).ExecuteScript("tb:test-result=" + (passed ? "passed" : "failed")); | ||
} | ||
finally | ||
{ | ||
// Terminates the remote webdriver session | ||
driver.Quit(); | ||
} | ||
} | ||
} | ||
} |
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
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