Selenium Webdriver cookie / use of a web browser is already open

I have 2 questions:

  • I created a selenium script web editor that works correctly, but it opens a new instance of Firefox. Can I use Firefox that is already open? If so, how?

  • I need to send information to the site so that my session is active. I think to use a cookie and send a request every 10 minutes. I don’t know if this is a good idea ... (I cannot use selenium authentication, because the site generates a table with numbers, for example, for a banking site)

If someone can help me ...

+4
source share
2 answers

If you use Seleium2 / WebDriver, you can create a launch instance of the browser by calling new FirefoxDriver() , then it can be reused for several tests. For example, if you use JUNIT, you can create a FirefoxDriver driver in @BeforeClass and exit it in @AfterClass .

browserSessionReuse

The SO post below will explain why the session might expire. It may also depend on how you wrote the test case (maybe you initialize it in the setUp() method). Selenium mode in -browserSessionReuse launches a new browser

NOTE. It is always best to isolate tests by creating and closing a browser instance for each test.

+3
source

If you opened a FireFox Browser instance with firefox webdriver in your test case and you did not close this instance, you can use this instance with RemoteWebDriver. You can even use this instance if one test case fails and you want to run another test case manually. use this code.

 IWebDriver WebDriver = null; try { System.Uri uri = new System.Uri("http://localhost:7055/hub"); WebDriver = new RemoteWebDriver(uri, DesiredCapabilities.Firefox()); Console.WriteLine("Executed on remote driver"); } catch (Exception) { WebDriver = new FirefoxDriver(firefoxProfile); Console.WriteLine("Executed on New FireFox driver"); } 

see the details here in this blog post. http://binaryclips.wordpress.com/2014/09/16/selenium-web-driver-in-c-how-to-continue-script-on-the-already-opened-browser-instance/

0
source

Source: https://habr.com/ru/post/1389121/


All Articles