How to Set capability for IE browser to run in Headless mode - selenium

I want to run the scripts in Headless mode for all the 3 browsers Chrome, Firefox & IE
The following is the code for Chrome:
System.setProperty("webdriver.chrome.driver", "./drive/chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("headless");
options.addArguments("window-size=1400,600");
WebDriver driver = new ChromeDriver(options);
driver.get("http://www.google.com/");
Note : Its working fine
Firefox:
FirefoxBinary firefoxBinary = new FirefoxBinary();
firefoxBinary.addCommandLineOptions("--headless");
System.setProperty("webdriver.gecko.driver", "./drive/geckodriver.exe");
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setBinary(firefoxBinary);
FirefoxDriver driver = new FirefoxDriver(firefoxOptions);
driver.get("http://www.google.com/");
Note : Its working fine
IE:
Similarly i want to execute in IE with options

IE does not have support for a headless mode (since IE nowadays does not recieve any kind of update or improvements.).
But you can use trifle.js, a kind of browser that can emulate some IE versions in a headless mode, since its coded as a port of PhantomJS.

Related

selenium RemoteWebDriver opens but ChromeOptions are not passed to Selenium Grid

I have been trying to resolve a few issues with RemoteWebDriver and ChromeOptions using docker and selenium grid. The main issue is with the proxy but I half resolved that with a proxy pac file passing the pac file url as an arg into ChromeOptions. The below code runs great in docker debug and standalone locally but as soon as I try with the grid or deploy and run with bamboo the driver opens and I can see that ChromeOptions are not being passed because the poxy pac file is not being used and it's just frozen at org.openqa.selenium.remote.ProtocolHandshake createSession. I have been researching for a few weeks now and I am at a hard blocker with this now. I have seen some posts that DesiredCapabilities is deprecated but I have not found a way to implement ChromeOptions without it.
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
options.addArguments("--disable-infobars");
options.addArguments("--proxy-pac-url= http://ProxyPacURL.com");
DesiredCapabilities dc = DesiredCapabilities.chrome();
dc.setCapability(ChromeOptions.CAPABILITY, options);
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), dc);
Update to latest Selenium Jars, make sure your java is version 1.8 or greater, then you can pass ChromeOptions into the driver because DesiredCapabilities is deprecated. I am now able to run selenium docker nodes with selenium grid and all ChromeOptions arguments are now being passed to the containers.
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
options.addArguments("--disable-infobars");
options.addArguments("--proxy-pac-url=http://myPacFile.com");
options.addArguments("--no-sandbox");
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), options);
I was facing same issue and I have found the solution as below:
We need to set "goog:chromeOptions" instead of "chromeOptions".
In your Java code, following line is present:
dc.setCapability(ChromeOptions.CAPABILITY, options);
If you navigate to ChromeOptions.CAPABILITY, you will notice that it is a constant with value "chromeOptions". This works fine for local web driver, but not for remote web driver (i.e. selenium grid).
Just change above line to this:
dc.setCapability("goog:chromeOptions", options);
Now when you execute your Java code, it will work fine and all your options will show their effect too.
I came across other pages, such as this, which referred to above solution.
Try this:
const GRID_HOST = 'http://localhost:4444/wd/hub';
var options = new chrome.Options();
options.addArguments("--start-maximized");
options.addArguments("--disable-infobars");
options.addArguments("--proxy-pac-url=http://myPacFile.com");
options.addArguments("--no-sandbox");
driver = new webdriver.Builder()
.usingServer(GRID_HOST)
.forBrowser("chrome")
.setChromeOptions(options)
.build()

How to launch IE browser using selenium webdriver 3.4.0

How to launch IE browser using selenium webdriver 3.4.0? I have tried, but unable to open an IE browser. I have downloaded IE Driver and followed the same like launching firefox driver.
Launching of Firefox browser is working fine, below are command lines
System.setProperty("webdriver.gecko.driver","C:\\Users\\vidhya.r\\Desktop\\Automation\\Jars\\geckodriver.exe");
FirefoxOptions options = new FirefoxOptions();
options.setBinary("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
driver = new FirefoxDriver(options);
Download IEDriverServer, put it to path or use
System.setProperty("webdriver.ie.driver", ieDriverPath);
launch via
driver = new InternetExplorerDriver();
DesiredCapabilities capability = DesiredCapabilities.internetExplorer();
capability.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);
capability.setCapability(InternetExplorerDriver.ELEMENT_SCROLL_BEHAVIOR, 1);
capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capability.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
System.setProperty("webdriver.ie.driver", ieDriverPath);
WebDriver driver = new InternetExplorerDriver(capability);
First download IEDriver from this Link
Use this:
System.setProperty("webdriver.ie.driver", "Path of IE driver");
WebDriver driver = new InternetExplorerDriver();
If you want to add some capabilities then use DesiredCapabilities

How to maximise the window in chrome browser in incognito mode using Selenium WebDriver?

How to maximise the window in chrome browser in incognito mode using Selenium WebDriver
I am using the below code:
ChromeOptions options = new ChromeOptions();
options.addArguments("--incognito");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(capabilities);
driver.manage().window().maximize();
But in the last line code I am getting error as Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: No current window
To maximize the Chrome Browser in incognito mode you need to use the ChromeOptions class as follows:
ChromeOptions options = new ChromeOptions();
options.addArguments("--incognito");
options.addArguments("start-maximized");
WebDriver driver = new ChromeDriver(options);

when I'm running my automation tests,I keep getting the "Disable Developer Mode Extension" in mobile emulation,I am using Chrome 2.21 driver

Here is the Sample code:
System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\chromedriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
//this line of code added to disable extension but still getting the alert capabilities.setCapability("chrome.switches", Arrays.asList("--disable-extensions"));
WebDriver driver = new ChromeDriver(capabilities);
How to disable this extension alert in mobile emulation mode?
If I add the below code,mobile emulation is not showing:
ChromeOptions options= new ChromeOptions();
options.addArguments("--disable-extensions");
How to disable this alert in mobile emulation mode using Selenium webdriver?
Try this...
ChromeOptions chop = new ChromeOptions();
chop.addArguments("--disable-extensions");
WebDriver driver = new ChromeDriver(chop);

Browser Plugin Testing With Selenium

I am writing a webapp that has a browser plugin component for both firefox and chrome. My current testing system uses a series of Selenium tests created through Selenium IDE.
Is it possible to also have selenium install, activate, and delete browser plugins for firefox and chrome (possibly other browsers as well)?
I think the biggest concern is that installing/enabling the browser plugin requires a browser restart, and I'm not sure if that would through selenium off.
The acquisition of the plugin is easily handled by visiting an internal site-link to a php-script that detects your browser.
The answer is Yes, Selenium 2 supports (remote) installation of browser extensions.
The Chrome and Firefox WebDriver support the installation of extensions, remotely. Here's sample code for Chrome and Firefox:
Chrome
File file = new File("extension.crx"); // zip files are also accepted
ChromeOptions options = new ChromeOptions();
options.addExtensions(file);
// Option 1: Locally.
WebDriver driver = new ChromeDriver(options);
// Option 2: Remotely
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
Firefox
File file = new File("extension.xpi");
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.addExtension(file);
// Option 1: Locally
WebDriver driver = new FirefoxDriver(firefoxProfile);
// Option 2: Remotely
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, firefoxProfile);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
I have also implemented automated installation of Opera and Safari extensions, and they have been merged upstream:
OperaDriver: https://github.com/operasoftware/operadriver/pull/93
SafariDriver: https://github.com/SeleniumHQ/selenium/pull/87
Opera
This API is similar to the FirefoxDriver.
File file = new File("extension.oex"); // Must end with ".oex"
OperaProfile operaProfile = new OperaProfile();
operaProfile.addExtension(file);
// Option 1: Locally
WebDriver driver = new OperaDriver(operaProfile);
// Option 2: Remotely
DesiredCapabilities capabilities = DesiredCapabilities.opera();
capabilities.setCapability("opera.profile", operaProfile);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
Safari
This API is similar to the ChromeDriver.
File file = new File("extension.safariextz");
SafariOptions options = new SafariOptions();
options.addExtensions(file);
// Option 1: Locally.
WebDriver driver = new SafariDriver(options);
// Option 2: Remotely
DesiredCapabilities capabilities = DesiredCapabilities.safari();
capabilities.setCapability(SafariOptions.CAPABILITY, options);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
Internet Explorer
Good luck.
Short answer: no
Installing a browser extension is outside of the scope of handling in Selenium.
In Chrome, it displays a modal window that is not "clickable" with Selenium when you want to add a plugin or app. Chrome does not require restarting.
Firefox has the same kind of behaviour to prompt for extension permissions.
You can try something that resides outside of the browser to do what you want. Sikuli might do the trick.