Does PhantomJS headless execution allow to set the browser preferences - java

We are using the PhantomJS for the Headless execution of our scripts which are written in Selenium Webdriver(2.42.2)+Java using browser Firefox 29.0.1 . We could able to integrate the PhantomJS successfully with our framework. But the issue we are facing is to set the MIME types using PhantomJS. i.e., Using selenium Webdriver we set the browser level preferences to do the actions like, download the files(pdf,csv,zip etc) but unable to find how to do with PhantomJS.
sample code below for the firefox browser level preferences:
FirefoxProfile profile = new FirefoxProfile();
profile.setEnableNativeEvents(true);
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.manager.showWhenStarting",false);
profile.setPreference("browser.download.dir","D:\downloads");
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf,application/download,application/force-download,application/x-download,text/csv,image/jpeg,application/zip");
profile.setPreference("pdfjs.disabled", true);
Tried passing arguments to "PHANTOMJS_CLI_ARGS" as below:
System.setProperty("phantomjs.download.folderList", "2");
System.setProperty("phantomjs.download.dir","D:\downloads");
but PhantomJS is not recognized the valid input arguments.

Related

unable to run the HtmlUnit Driver with selenium Webdriver using java

This is the code :
And error :
I am trying to run the script in headless browser but it gives the error as mentioned in screenshot.
I will suggest to use phantomjs instead of HTMLUnit driver for headless automation
Now if you want to use headless with phantomjs. download the stable build of phantomjs for your headleass jobs. download it from below link :-
http://phantomjs.org/download.html
Now add System.setPropertybefore driver instance
DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true); // not really needed: JS enabled by default
caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "C:/phantomjs.exe");
WebDriver driver = new PhantomJSDriver(caps);
refer the link below for more info :-
http://seleniumworks.blogspot.in/2013/03/headless-browser-testing-using.html

Selenium 3 - Marionette - Custom Firefox profile

I am running into a huge problem regarding selenium 3 automated ui tests. First of all, I clarify how I run selenium tests on Firefox 46 with selenium 2.x:
- Start selenium server on console: java -jar selenium.jar -firefoxProfileTemplate c:\selenium\firefox_profile
- Run (behat) tests from another console
Now, I've read that Firefox 48 does not support the webdriver anymore, and moved to Marionette webdriver. Ok, so I downloaded Selenium 3 beta with the corresponding geckodriver and startet the above worflow again - it worked BUT:
My site uses a self signed ssl certificate. Ok this was no problem in previous selenium version with webdriver, I could just create a custom firefox profile and use it by appending firefoxProfileTemplate flag. The problem on Selenium 3 with Marionette driver is, that this flag does not exist anymore.
So how to specify the firefox profile, which selenium / Marionette should use when opening firefox, from the command line? Is there a new option? Or maybe a global config file somewhere?
Regards-
Not sure which language you're using ,but for java side you can use the old FirefoxProfile to set the firefox driver support SSL. see below code:
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
FirefoxProfile fp = new FirefoxProfile();
// fp.addExtension(extensionToInstall);
// http://stackoverflow.com/questions/15292972/auto-download-pdf-files-in-firefox
// http://www.webmaster-toolkit.com/mime-types.shtml
// for config list see this :
// http://kb.mozillazine.org/About:config_entries#Profile.
fp.setAcceptUntrustedCertificates(true);
fp.setAssumeUntrustedCertificateIssuer(true);
fp.setEnableNativeEvents(false);
capabilities.setCapability(FirefoxDriver.PROFILE, fp);
It's a bit hard when selenium switch all the old drivers to W3C WebDriver, there are no much document here for user,hope this helps you.

How can I start installed browser without adding IE driver or Chrome driver in selenium web driver?

I have installed IE and chrome browser in my computer. I want to run my selenium script from original browser with all add-ons and default setting.
I am able to find *.exe of browser with some capabilities.But can not able to write and open link (driver.get()) in browser. Please refer following code.
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
cap.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, DriverTestNG.url);
DesiredCapabilities.internetExplorer().setCapability("ignoreProtectedModeSettings", true);
System.setProperty("webdriver.ie.driver", "src/main/resources/Framework/Drivers/Windows/IEDriverServer_Win32_2.40.0/IEDriverServer.exe");
cap.setCapability("IE.binary", "C:\\Program Files\\Internet Explorer\\iexplore.exe");
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setJavascriptEnabled(true);
cap.setCapability("requireWindowFocus", true);
cap.setCapability("enablePersistentHover", false);
cap.setCapability("elementScrollBehavior", 1);
cap.setCapability("cssSelectorsEnabled", true);
cap.setCapability("nativeEvents", true);
driver = new InternetExplorerDriver(cap);
May be I have missed something.I am not sure about this that selenium web driver supports this functionality or not.
Please guide me for it.
Thanks in advance.
Regarding to your title, you can not run Internet Explorer or Chrome without using a webDriver because you need the webDriver as an API to access the functionality of IE or chrome.
But you can still use extensions and your default settings. The reason why you don't see any extensions running chromeDriver is that it always creates a new temporary profile for each test-session. If you want to run your own custom profile with extensions and settings you have to tell chromeDriver which user profile it should use by defining the user-data-dir.
You can find the capabilities here:
https://sites.google.com/a/chromium.org/chromedriver/capabilities
example:
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=C:/Users/user_name/AppData/Local/Google/Chrome/User Data");
You can also specifiy extensions by using:
https://sites.google.com/a/chromium.org/chromedriver/extensions
I don't use IEdriver so I can't tell you how it works with the IE but as far as i know the internet explorer does not have profiles and the extensions are managed somewhere in the registry. So I would assume that extensions installed before running the tests are available also trough IEWebDriver.

How can I add an addon to my webdriver browser

Whenever I execute my script created in selenium webdriver (java), the webdriver browser does not show the addons that I had installed in my actual browser.
I want that the add ons should also be displayed in webdriver browser.
How can I add an addon to my webdriver browser.
This is an example how you can add Firebug add-on in the Firefox profile used for the Selenium tests:
File file = new File("firebug-1.8.1.xpi");
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.addExtension(file);
firefoxProfile.setPreference("extensions.firebug.currentVersion", "1.8.1"); // Avoid startup screen
WebDriver driver = new FirefoxDriver(firefoxProfile);
Source: http://code.google.com/p/selenium/wiki/FirefoxDriver

I need to enable java (tm) plugin which installs applet in the browser.. How is it possible in Web Driver

I need to enable java (tm) plugin which installs applet in the browser.. How is it possible in Web Driver?
I am testing a web app where some functionality has to be verified by enabling java(i.e., by installing applet) and also some functionality by disabling it. If applet works fine, then I need some expected results and if applet is not installed, I need some other results.. so how do i enable/disable applets(i.e.,java tm plugin) before launching browser..??
Please Help..
Currently am using WebDriver...
Create a firefox profile to load firefox with the plugin which you want. Use the below code and replace the plugin name with your plugin name.
File file = new File("firebug-1.8.1.xpi");
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.addExtension(file);
firefoxProfile.setPreference("extensions.firebug.currentVersion", "1.8.1"); // Avoid startup screen
WebDriver driver = new FirefoxDriver(firefoxProfile);
Source: Click Here
You can enable any Firefox plugin creating new profile and setting the preference.
For e.g.
to enable java plugin
profile.setPreference("plugin.state.java", 2);
To enable flash plugin
profile.setPreference("plugin.state.flash", 2);
Sample code:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("plugin.state.java", 2);
WebDriver driver = new FirefoxDriver(profile);
I presume the "2" activates the plugin.

Categories

Resources