chromedriver full screen doesn't work on Linux - selenium

I am trying to start Chrome browser in full screen mode (similar to using F11) on Ubuntu 12.04. I am using the following code, but this doesn't see to work:
if (browser.equalsIgnoreCase("chrome")) {
//Set full screen mode (similar to F11)
ChromeOptions options = new ChromeOptions();
options.addArguments("start-fullscreen");
//Create a new Chrome Driver
System.setProperty("webdriver.chrome.driver","./lib/chromedriver");
this.driver = new ChromeDriver(options);
}
I am using Chrome version 34 with WebDriver version 2.41. Any suggestions?

Linux Mint 16, Chrome version 34.0.1847.132, Selenium 2.41.
Full screen mode works fine.
Try to use:
driver.manage().window().maximize();
to maximize browser window.
Edited.
Also you can try to run chrome in kiosk mode:
ChromeOptions options = new ChromeOptions();
options.addArguments("--kiosk");
driver = new ChromeDriver(options);
This works fine in Linux with Chrome 34.
Or try to press F11 like:
driver.findElement(By.tagName("html")).sendKeys(Keys.F11);
But for me it works fine only in Firefox.

If you're trying to send F11 to the browser, you can probably do it this way:
driver.FindElement(By.TagName("html")).SendKeys(Keys.F11);

Related

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

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.

How to automatically close firebug tab when launching selenium firefox webdriver with firebug?

I have included firebug when launching firefox driver and it works very fine with latest selenium web driver 3.0 but meanwhile it also opens new firebug tab every time when launching browser.
As code says, i have included firebug file and added this extension in created profile. Is there any way to close the firebug tab automatically after launching the browser? If there is no automatic way then i need to use tweak to close window named "Firebug" right?
Code:
File file = new File("./firebug-2.0.17-fx.xpi");
System.setProperty("webdriver.gecko.driver", config.getStringProperty("geckodriver.path"));
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
FirefoxProfile profile = new FirefoxProfile();
profile.addExtension(file);
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
capabilities.setCapability("marionette", true);
webDriver = new FirefoxDriver(capabilities);
You can set the "showFirstRunPage" flag to "false" in your porfile.
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("extensions.firebug.showFirstRunPage", false);
Here is a link to all firebug preferences you can set.
Firebug Preferences
An other solution is to set the "currentVersion" to a big number like this.
profile.setPreference("extensions.firebug.currentVersion", "999");
I prefer the first on ;)
I was looking for automatically closing Firebug window but i think its not possible so posting an answer to handle opened windows after launching firebox browser with firebug capabilities, unfortunately you need to deal with extra lines of code due to this issue :)
Below solution it works fine, just use it like below:
Working code:
File file = new File("./firebug-2.0.17-fx.xpi");
System.setProperty("webdriver.gecko.driver", config.getStringProperty("geckodriver.path"));
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
FirefoxProfile profile = new FirefoxProfile();
profile.addExtension(file);
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
capabilities.setCapability("marionette", true);
webDriver = new FirefoxDriver(capabilities);
// Close the firebug window
Thread.sleep(4000); // Firebug window takes time to open it
Set <String> windows = webDriver.getWindowHandles();
String mainwindow = webDriver.getWindowHandle();
for (String handle: windows) {
webDriver.switchTo().window(handle);
if (!handle.equals(mainwindow)) {
webDriver.close();
}
}
webDriver.switchTo().window(mainwindow);

How to handle downloading popup alert, while downloading a file in chrome

Point 1. If I launched normal chrome driver without loading any profile then it would block all exe (keep/discard)
Point 2. When I provided my chrome profile, these are my observations:
Clean exe downloading normally
Download error exe giving same dialogue on chrome driver as normally on chrome browser
Issue is here: those exe which are througing alert of keep/decline popup normally ...those are normally downloading on driver.
SNAPSHOT attached (http://i.stack.imgur.com/PtZ18.png)
I am loading chrome profile by this pattern
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir="+userProfile);
options.addArguments("--start-maximized");
options.addArguments("test-type");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(options);
So this is the main Issue
One more thing: Actually these popups are not html pages. These are over layer on chrome so any technique to spy those using any other free tool? or selenium?
Try this maybe
((JavascriptExecutor) driver).executeScript("window.confirm = function(msg) { return true; }");

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.

ChromeDriver in Fullscreen Mode

I am trying to send F11 to ChromeDriver, however it does not respond to it. When I press F11, it turns Chrome into fullscreen mode. When I send F11 through ChromeDriver, it does not. This is the same for any F-key in ChromeDriver. It works fine with FirefoxDriver and IEDriver, just not ChromeDriver. Is there any way I could get ChromeDriver into fullscreen mode ?
Note : Fullscreen mode is different from maximized mode, as it hides all toolbars.
I was able to solve it using kiosk mode, which keeps the browser in full screen
ChromeOptions options = new ChromeOptions();
options.addArguments("--kiosk");
WebDriver driver = new ChromeDriver(options);
The argument is changed:
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
Another option is change the startup script of google-chrome, set start-maximized as default.
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-fullscreen");
WebDriver driver = new ChromeDriver(options);
if you use RemoteWebDriver:
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-fullscreen");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
Instance = new RemoteWebDriver(new URL(<SeleniumServerURL>), capabilities);
driver.manage().window().fullscreen();
In my case, i fix the differences between selenium webdriver coordinates and screen absolute coordinates (root cause: chrome tab, header and address field size are ignored by selenium .getcoordinate mechanism) by this way:
String shortcutGoToFullScreen = Keys.chord(Keys.F11);
WebDriver.findElement(By.tagName("body")).sendKeys(shortcutGoToFullScreen);
Only one problem, that this fullscreen mode became non full after any page code updates. So, it should be used carefully )
Use --start-fullscreen argument to Specify the browser should start in fullscreen mode, like if the user had pressed F11 right after startup.
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-fullscreen");
WebDriver driver = new ChromeDriver(options);
You can change the behavior as you prefer by providing arguments to ChromeOptions.
Following link gives you in detail view of arguments and their behaviour. Hope it helps.
https://peter.sh/experiments/chromium-command-line-switches/#start-fullscreen
With Powershell/Selenium I wrote the script:
$Driver = Start-SeChrome -Fullscreen -StartUrl "https://........."
This worked perfectly for me