Karthik
Karthik

Reputation: 1074

Loading Browser only once in Protractor.NET?

I am a newbie to Protractor.NET and I apologize if it is a layman question.

I am testing my AngularJs application using Protractor.NET. I have written multiple Test scenarios in C#. But for each and every test which is executed, the Protractor loads the Browser again and again and closes/quits it. Is it possible to avoid this?? and just load the browser only once and with that instance let my test scenario executes.

Is that possible to achieve?

[TestClass]
public class BaseTest
{

    protected IWebDriver _driver;
    protected NgWebDriver _ngWebDriver;

    [TestInitialize]
    public void Setup()
    {
        var key = ConfigurationManager.AppSettings["key"];
        _driver = new ChromeDriver(key);
        _driver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromSeconds(10));
        _ngWebDriver = new NgWebDriver(_driver);
    }

    [TestCleanup]
    public void Teardown()
    {
        _ngWebDriver.Quit();
    }
}

If I comment out the [TestCleanup] method, the browser does not close and new instances are created. I just need to use a single instance and execute my test cases.

Upvotes: 4

Views: 160

Answers (1)

Phil Degenhardt
Phil Degenhardt

Reputation: 7264

Yes. Just use the [ClassInitialize] and [ClassCleanup] attributes instead of [TestInitialize] and [TestCleanup].

Upvotes: 3

Related Questions