Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 327
Karthik Avatar asked Oct 30 '25 15:10

Karthik


1 Answers

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

like image 190
Phil Degenhardt Avatar answered Nov 01 '25 06:11

Phil Degenhardt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!