Allan
asked on
Selenium C#: Browser Fires Up Once
Hi Experts!
Trying to create a Selenium test class (MSTest) in C#. Would like the browser to fire up only once before we run all tests from Test Explorer,
so that for each test method it would be able to use the same browser.
Running the following code below we have this error:
SetupToRunOnceBeforeAllTes tsRun has wrong signature. The method must be static, public, does not return a value and should take a single parameter of type TestContext. Additionally, if you are using async-await in method then return-type must be Task.
SearchPageTest
BasePageTest:
Any help is appreciated to get this working.
TIA!
Trying to create a Selenium test class (MSTest) in C#. Would like the browser to fire up only once before we run all tests from Test Explorer,
so that for each test method it would be able to use the same browser.
Running the following code below we have this error:
SetupToRunOnceBeforeAllTes
SearchPageTest
[TestClass]
public class SearchPageTest : BasePageTest
{
private SearchPage searchPage { get; private set; }
private SearchCriteria searchCriteria;
[ClassInitialize]
public void SetupToRunOnceBeforeAllTestsRun(TestContext context)
{
driver = GetChromeDriver();
searchPage = new SearchPage(driver);
}
[TestMethod]
[TestCategory("IntegrationAutomation"), TestCategory("UI"), TestCategory("SearchPage")]
public void SearchPage_GoToSearchPage_Success()
{
//Arrange
//Act
//Assert
Assert.IsTrue(searchPage.GoToSearchPage().IsPageVisible);
}
[TestMethod]
[TestCategory("IntegrationAutomation"), TestCategory("UI"), TestCategory("SearchPage")]
public void SearchPage_SomeOtherTest_Success()
{
//Arrange
//Act
//Assert
Assert.IsTrue(searchPage.SomeThingElse());
}
[ClassCleanup]
public void CleanUpAfterAllTestsRan()
{
driver.Close();
driver.Quit();
}
}
BasePageTest:
public class BasePageTest
{
internal IWebDriver driver { get; set; }
public IWebDriver GetChromeDriver()
{
var outPutDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\Driver";
return new ChromeDriver(outPutDirectory);
}
}
Any help is appreciated to get this working.
TIA!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Open in new window
Open in new window