Learner
Learner

Reputation: 947

How to continue to run Tests in same browser in selenium webdriver

Iam new to selenium webdriver,

In some scenario my tests case got failed,i want to run the tests from the same place (i.e. w/o closing the browser)from where the issue occured by commenting the previous code. how to do that in selenium webdriver. ( Like run from step in QTP )

Can anyone Please guide me.

Thanks

Upvotes: 2

Views: 11276

Answers (3)

Gabriel Pita
Gabriel Pita

Reputation: 336

Workaround found here: https://code.google.com/p/selenium/issues/detail?id=3927

WebDriver  driver=new RemoteWebDriver(new URL("http://localhost:7055/hub" DesiredCapabilities.firefox());
        driver.get("http://www.google.com");

Upvotes: 0

aimbire
aimbire

Reputation: 3697

There is one way i am aware of, but that can should implicate in some problems if you decide to run the same test in parallel. I'd advise you study a little bit about static parameters to see if it suits you.

When you start your first test do it as follows:

static WebDriver driver = new FirefoxDriver(); // Could be any Driver();

That way any test that you call driver.someFunction(); will work, as long as you don't call for close() or quit() until you reach the last test.

Upvotes: 1

Johnbo
Johnbo

Reputation: 498

In order to reuse the browser, you can't initialize it in every test, so you need to use a singleton pattern in which you will have an unique webdriver.

So, instead of using the @before and @after clauses to initialize and close that browser, you want to use @beforeclass and @afterclass. Then, every test method in that class will use the same browser, from the exact point where the previous test left it.

But this will happen in the same test cycle. As far as I know, there is no possibility to use an instance of a browser launched in a different cycle, or manually opened.

Upvotes: 2

Related Questions