Hello friends. I would like some help.
I've been trying to use the same instance of Firefox window open by Visual Studio at first time.
The question is, how to pickup the same window browser and continue to testing without it close the browser and open again every time i want to do a testing?
I know there is a lot of questions about this topic, but some that I've found is applicable for old versions of selenium and some codes didn't work due to be deprecated.
What i can do with success:
I can work normally with traditional method to test a unit, opening Firefox at beginning and close after the end of test:
[ClassInitialize]
public static void InitializeClass(TestContext testContext) {
driver = new FirefoxDriver();
}
Then i commented the following lines to keep the window open when test is complete:
//driver.Quit();
//driver.Close();
//driver.Dispose();
What i can't manage to:
With searches I've been made, i read that we can connect to an existing session already open before. So i tried with the following:
[ClassInitialize]
public static void InitializeClass(TestContext testContext) {
FirefoxOptions options = new FirefoxOptions();
driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), options);
//driver = new FirefoxDriver();
On the example above, I've commented driver = new FirefoxDriver();
and used the method FirefoxOptions
instead of the deprecated DesiredCapabilities.firefox()
and when i try to connect to the open firefox window, i got an error and i can't go on. On log, there's a line saying:
Was'n possible to copy the file "..\packages\Selenium.Firefox.WebDriver.0.27.0\build\driver\geckodriver.exe" to "..\bin\debug\geckodriver.exe"
The file geckodriver.exe (61484) is being used by another process
With this, i tried another different ways to reach what i expect like:
[ClassInitialize]
public static void InitializeClass(TestContext testContext) {
FirefoxOptions options = new FirefoxOptions();
driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), options);
options.AddArgument("--marionette-port " + "2828" + "--connect-existing");
FirefoxDriverService ffDriverService = FirefoxDriverService.CreateDefaultService();
ffDriverService.BrowserCommunicationPort = 4444;
}
for last i tried to open a separated instance of Firefox to try to connect to like below:
firefox.exe --marionette -start-debugger-server 2828 -profile %temp%\FirefoxTEMP
I got success on open a instance of marionette,but i continuing unable to attach the test to this open window.
I appreciate your attention and forgive me for some newbie techniques i made.
Questions I've read:
How to connect Selenium to existing Firefox browser? (Python)
How to connect Selenium Webdriver to existing Firefox/Chrome browser session?
How to connect to an already open browser?
edit:
take a look on this thread to understand that it's a common request: