Reuse session variables while opening a browser with selenium webdriver - vb.net

When opening a new browser doing
Dim driver As IWebDriver
the session variables are lost, I have thought about saving these variables in xml files to reload them in the webdriver browser, but it really doesn't seem like the best option. Is there a way to pass these session variables to the new browser in Visual Basic and Firefox Driver?

When you configure an instance of a WebDriver using
Dim driver As IWebDriver
the configuration gets baked into the webdriver session and will persist till the lifetime of the WebDriver being uneditable.
Even if you are able to extract the Session attributes e.g. Session ID, Cookies, UserAgent and other session attributes from the already initiated WebDriver still you won't be able to pass them while initiating a new WebDriver session.

Related

Hide browser bot during code execution display at end selenium VBA

I am trying to find a way that enables me to hide the driver (bot) of the selenium in VBA during the execution of the code and display it at end
I can hide it using this line
bot.AddArgument "--headless"
But how I restore it?
No, it won't be possible to make Chrome operate initially in headless mode and then switch back to normal mode within the same session.
When you configure an instance of a WebDriver with Options() to span a new Browsing Context the configuration gets baked within the driver executable which will persist for the lifetime of the WebDriver and being uneditable. So you can't modify/add any existing/new configuration through Options() class to the WebDriver instance which is currently in execution.
Even if you are able to extract the Driver and Session attributes e.g. Session ID, Cookies, UserAgent and other session attributes from the already initiated Driver and Browsing Session still you won't be able to change the set of attributes of the Driver.
You can find more details in these discussions:
How to set selenium webdriver from headless mode to normal mode within the same session?
Change ChromeOptions in an existing webdriver
How do I make Chrome Headless after I login manually
Credits to undetected Selenium

why the code //RemoteWebDriver driver= new FirefoxDriver(); is not used instead of //WebDriver driver= new FirefoxDriver()?

Why is the code //RemoteWebDriver driver= new FirefoxDriver(); not used instead of //WebDriver driver= new FirefoxDriver() to create a driver object?
I feel that RemoteWebDriver gives more capabilities for the driver instance than webdriver reference. Can someone clarify this?
WebDriver will start up a web browser on the computer where the code instantiates it. For example. If you write a bit of code, and then run it to see how you are doing, the browser will pop up on your screen and you will see WebDriver begin to manipulate that web browser window (if everything went well!)
With a major exception which I will explain below, RemoteWebDriver will do the same thing; it will open and manipulate a browser window (if everything went well!) Generally speaking, You can actually switch the instatiation of a WebDriver with a RemoteWebDriver (well, there are advanced cases where you might not be able too do this) The major difference is that RemoteWebDriver sends that request to open and control a web browser to a server, so you normally wouldn’t see the browser open and do it’s thing.
Selenium server is the program that runs and waits for RemoteWebDriver connections. You can run it on your local computer to test it out. If you get it set up and running, you’ll be able to create a RemoteWebDriver and see that the Selenium server accepts the connection and allows you to control the web browser window.
The gains from using RemoteWebDriver?
If you can do connect to a local Selenium server, you can be confident that you have the knowledge and skills needed to connect to a remote Selenium server, or even to a paid service like SauceLabs (Hosting Selenium for you) that allows you to run lots of tests on lots of OS’s and lots of browsers without having to actually maintain or install any of them (Linux, Windows 8, Windows 10, MacOS, Andriod, IOS, IE, Firefox, Opera, Safari, Firefox Mobile, etc) You’ll want to look into running tests asynchronously at this point. You don’t have to run them one at a time, so can test a large number of OS/Browser variations in a very short time.
What does it mean when something is used only for client/server communication?
When you uses a Selenium grid with have one hub and multiple clients, you invoke RemoteWebDriver through which you instantiate the server and and make the request to it.
WebDriver is an interface in selenium which extends SearchContext interface (super most interface in selenium)
Where as RemoteWebdriver is a class which implements WebDriver,
We can use RemoteWebdriver, when we going to execute the test in romote environment,(selenium grid).
WebDriver interface will invoke the driver locally,
Currently in automation mostly we are using WebDriver only.
Grid not using widely.
WebDriver driver=new ChromeDriver() ;
driver is the reference variable where used to access chromedriver class.
Using driver instance we can access all the unimplemented methods available in WebDriver interface, also able to access all the properties available in chromedriver class.
For more details
https://www.softwaretestingmaterial.com/webdriver-driver-new-firefoxdriver/

Selenium code not identifying the webelements on IE10

Selenium code doesn't identifying the webelements on IE10. Even after the path is set for the driver.
File file = new File("D:\\Driver\\IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
dr=new InternetExplorerDriver();
Configure the same protected modes for all of the security items in internet properties. The checkboxes must match for all 4 otherwise WebDriver loses the window after it opens.

Selenium grid2: how to close and open browser on remote

I have a test where I need to do a login, close browser and open it again then check something on the page.
How can I do this when running webdriver with remote hub setup? or do i have to run this without remote?
Test is something like this:
Open browser
Login
Close browser
Open browser again
Check login is remembered
The process to accomplish this is going to be very similar to that of a solution in a non-grid environment. Note that the following code is written for Java, but I can't imagine C# being much different.
WebDriver driver = new RemoteWebDriver("hubURL", desiredCapabilities);
driver.manage().deleteAllCookies();
driver.get("http://path/to/page");
//login to application
driver.quit(); //This will close the browser on the remote machine
//Now to try it again
driver = new RemoteWebDriver("hubURL", desiredCapabilities);
driver.get("http://path/to/page");
Assert.assertTrue(some element that is not on the login page but is on the page after is present);
driver.quit();
Presumably you're testing some cookie stuff. Unfortunately, there's no guarantee any particular node will execute any request, unless you constrain it properly. You need to have a node advertise a unique capability that the client then requests, ensuring the hub will route to that node every time. But, naturally, if that node goes down, you won't have any others that could service the request.

Webdriver : how to set IE in virtual environment?

I am setting up the Virtual Environment for my grid-based Webdriver tests. And sure enough, there are problems with IE driver.
First of all, Internet Options → Security should have the same Protected Mode setting. It's an easy fix if you have an access to the browser, but in my case, I won't have physical access to the browser.
In Webdriver's FAQ it says you can do the following:
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.set(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
WebDriver driver = new InternetExplorerDriver(capabilities);
Ruby bindings have no reference to setting up this capability in IE. It there a way to code it out in Ruby?
The other thing is what can be done against "unsecure connection" pop-ups? Again, they are easy to deal with manually after the first run, but what about running "clean" IE instance each time?
There are probably more concerns,
I'd like to hear your opinion.
Thank you!