-
Notifications
You must be signed in to change notification settings - Fork 131
ProjectTestBase class
Jakub Raczek edited this page Apr 25, 2019
·
9 revisions
ProjectTestBase class should be added as a content to you project during installation of nuget package. Implementation of ProjectTestBase classes differs depending on unit test framework you selected to use with our test framework
Each of ProjectTestBase class contains methods for the internet browser to configure it with proper settings and start it before each of test:
this.DriverContext.CurrentDirectory = TestContext.CurrentContext.TestDirectory;
this.DriverContext.TestTitle = TestContext.CurrentContext.Test.Name;
this.LogTest.LogTestStarting(this.driverContext);
this.DriverContext.Start();
after each test the browser is stopped and additional action are taken in case of test failure, like taking the screen shots
this.DriverContext.IsTestFailed = TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Failed || !this.driverContext.VerifyMessages.Count.Equals(0);
this.SaveTestDetailsIfTestFailed(this.driverContext);
this.DriverContext.Stop();
this.LogTest.LogTestEnding(this.driverContext);
if (this.IsVerifyFailedAndClearMessages(this.driverContext) && TestContext.CurrentContext.Result.Outcome.Status != TestStatus.Failed)
{
Assert.Fail();
}
You can modify ProjectTestBase class to fit your needs, e.g. to start the browser once before all tests from your test class instead of starting it before each of tests methods from that test class.
Implementation for NUnit:
namespace Ocaramba.Tests.NUnit
{
using global::NUnit.Framework;
using global::NUnit.Framework.Interfaces;
using Ocaramba;
using Ocaramba.Logger;
/// <summary>
/// The base class for all tests
/// </summary>
public class ProjectTestBase : TestBase
{
private readonly DriverContext driverContext = new DriverContext();
/// <summary>
/// The browser manager
/// </summary>
protected DriverContext DriverContext
{
get
{
return this.driverContext;
}
}
/// <summary>
/// Logger instance for driver
/// </summary>
public TestLogger LogTest
{
get
{
return this.DriverContext.LogTest;
}
set
{
this.DriverContext.LogTest = value;
}
}
/// <summary>
/// Before the class.
/// </summary>
[OneTimeSetUp]
public void BeforeClass()
{
this.DriverContext.CurrentDirectory = TestContext.CurrentContext.TestDirectory;
this.DriverContext.Start();
}
/// <summary>
/// After the class.
/// </summary>
[OneTimeTearDown]
public void AfterClass()
{
this.DriverContext.Stop();
}
/// <summary>
/// Before the test.
/// </summary>
[SetUp]
public void BeforeTest()
{
this.DriverContext.TestTitle = TestContext.CurrentContext.Test.Name;
this.LogTest.LogTestStarting(this.driverContext);
}
/// <summary>
/// After the test.
/// </summary>
[TearDown]
public void AfterTest()
{
this.DriverContext.IsTestFailed = TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Failed || !this.driverContext.VerifyMessages.Count.Equals(0);
this.SaveTestDetailsIfTestFailed(this.driverContext);
this.LogTest.LogTestEnding(this.driverContext);
if (this.IsVerifyFailedAndClearMessages(this.driverContext) && TestContext.CurrentContext.Result.Outcome.Status != TestStatus.Failed)
{
Assert.Fail();
}
}
}
}
- Home
- Getting started
- Parallel tests execution
- MsTest DataDriven tests from Xml and CSV files
- NUnit DataDriven tests from Xml, CSV and Excel files
- Comparing files by NUnit DataDriven tests
- Visual Testing
- Screen shots: full desktop, selenium. PageSource saving
- Verify-asserts without stop tests
- Downloading files
- Helpers
- Override browser profile preferences, install browser extensions, Headless mode
- Debugging Test.Automation framework
- Logging
- Performance measures
- Webdriver Extends
- More common locators
- Selenium-Grid-support
- Advanced Browser Capabilities and Options
- AngularJS synchronization
- Update App.config or appsettings.json
- Cross browser parallel test execution with testing-Cloud-Providers\SeleniumGrid
- Verifying Javascript Errors from browser
- Enabling Performance Log for Chrome
- Azure DevOps Support
- Edge browser Support
- Downloading and running Selenium Grid with Powershell
- Run Ocaramba tests with Docker container
- HTTP auth in Internet explorer
- ExtentReports Support