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.
Related
I am getting connection refused error while creating a firefox driver.
System.setProperty("webdriver.gecko.driver", "path to gecko driver");
FirefoxOptions options = new FirefoxOptions();
options.setLogLevel(FirefoxDriverLogLevel.FATAL);
options.setAcceptInsecureCerts(true);
options.addArguments("-profile", "./firefoxprofile");
options.setHeadless(true);
LOGGER.info("Completed setting firefox optons");
WebDriver driver = new FirefoxDriver(options);
Log:
1550014357421 mozrunner::runner INFO Running command: "/Applications/Firefox.app/Contents/MacOS/firefox-bin" "-marionette" "-profile" "./firefoxprofile" "-foreground" "-no-remote"
1550014357464 geckodriver::marionette DEBUG Waiting 60s to connect to browser on 127.0.0.1:61008
[GFX1-]: [OPENGL] Failed to init compositor with reason: FEATURE_FAILURE_OPENGL_CREATE_CONTEXT
Can't find symbol 'GetGraphicsResetStatus'.
1550014417545 mozrunner::runner DEBUG Killing process 38393
Exiting due to channel error.
1550014417592 webdriver::server DEBUG <- 500 Internal Server Error {"value":{"error":"unknown error","message":"connection refused","stacktrace":""}}
Web server is running and I could able to test it with curl command and I tried with 777 permissions on gecko driver bin file.
Also updated Gecko driver to latest version (0.24.0)
Your configurations looks good.
I had a similar problems in Linux.
In my case the solution was test with all versions of gecko driver and with one of them, it worked.
Also you can check if the o.s user of your IDE (eclipse, intellij) is the same user of the firefox. In my case, eclipse was starting with root but firefox could not start with root user.
I hope this help you.
While working with Selenium v3.x, GeckoDriver v0.24.0 and Firefox Quantum v65.0 to use a new Firefox Profile on every run of your Test Execution you can use the following code block :
System.setProperty("webdriver.gecko.driver", "C:\\path\\to\\geckodriver.exe");
FirefoxOptions options = new FirefoxOptions();
options.setProfile(new FirefoxProfile());
options.setLogLevel(FirefoxDriverLogLevel.FATAL);
options.setAcceptInsecureCerts(true);
options.setHeadless(true);
WebDriver driver = new FirefoxDriver(options);
driver.get("https://www.google.com");
You can find a detailed discussion in Cannot resolve constructor FirefoxDriver(org.openqa.selenium.firefox.FirefoxProfile)
I was facing the same problem in Windows using python. Make sure that your Firefox browser version is also the latest one.
After searching a lot, I finally found it was because a previous instance of the browser was running. Keep in mind, not another instance like one opened by me but an instance which was previously opened by selenium. If you can, close all the background browser processes. I restarted my system and it works perfectly fine as long as I remember to do browser.quit().
If you stop the program before closing the object properly, there is a chance the background instance will keep running unless eclipse or whichever IDE you are using closes it.
I'm getting the chrome didn't shut down correctly error message when I reopen a chrome browser in my selenium framework.
In the framework I'm opening the browser instance at the beginning for each of my test case using the below code
if (browserType.equalsIgnoreCase("Chrome")) {
try {
System.setProperty("webdriver.chrome.driver", curProj+"\\drivers\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("useAutomationExtension", false);
options.addArguments("disable-infobars");
//options.addArguments("user-data-dir=C:/Users/xw20/AppData/Local/Google/Chrome/User Data");
options.addArguments(chromeProfile);
webdriver = new ChromeDriver(options);
logger.info("getWebDriver - Setting webdriver.chrome.driver system property as: " + System.getProperty("webdriver.chrome.driver"));
}
catch(IllegalStateException e) {
logger.error("The path to the driver executable must be set by the webdriver.chrome.driver system property. ",e.fillInStackTrace());
throw new IllegalStateException("The path to the driver executable must be set by the webdriver.chrome.driver system property.");
}
and closing at the end using the below code
driver.close();
driver.quit();
But when I open a browser for the second test case I'm getting "chrome didn't shut down correctly" popup message.
I tried updating the below in the Preferences file of chrome profile but no luck
exit_type:Crashed
exited_cleanly:true
Configuration :
Chrome Version: Version 64.0.3282.186 (Official Build) (32-bit)
Selenium Version: 3.11.0
As per your code it would be tough to analyze the reason behind the error chrome didn't shut down correctly without knowing your framework structure. Perhaps a more details about how code block was invoked (i.e. main() or TestNG) would have helped us.
Having said that there still seems some more factors to look at as follows :
If you are using an existing Chrome Profile through user-data-dir ideally you should avoid the switches setExperimentalOption and addArguments for customization as those should be set within the respective Chrome Profile.
As you are using an existing Chrome Profile through user-data-dir as per the documentation ChromeDriver - WebDriver for Chrome the path should point the profile directory as follows :
options.add_argument("user-data-dir=C:/Users/xw20/AppData/Local/Google/Chrome/User Data/Profile 2")
Here you can find a detailed discussion at How to open a Chrome Profile through Python
Avoid using driver.close(); and always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
Here you can find a detailed discussion at PhantomJS web driver stays in memory
Upgrade JDK to recent levels JDK 8u162.
Upgrade Selenium to current levels Version 3.11.0.
Upgrade ChromeDriver to current ChromeDriver v2.37 level.
Upgrade Chrome version to current Chrome v65.x levels.
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
Use CCleaner tool to wipe off all the OS chores before and after the execution of your test Suite.
If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
Execute your #Test.
Did you set exit_type:Normal, I'm currently doing that before the test start, and or after the test ends and it Works.
on C#
public static void FixChromeSingleProfile(string dataDir)
{
FileStream fs = new FileStream(dataDir, FileMode.OpenOrCreate);
StreamReader sr = new StreamReader(fs);
string json = sr.ReadToEnd();
sr.Close();
fs.Close();
dynamic jsonDe = JsonConvert.DeserializeObject(json);
if (jsonDe.profile.exit_type != "Normal")
{
jsonDe.profile.exit_type = "Normal";
string r = JsonConvert.SerializeObject(jsonDe);
StreamWriter sw = new StreamWriter(dataDir, false);
sw.Write(r);
sw.Close();
}
}
This solution is in Python and works 100% but you should be able to implement this in Java as well. I just call the close_windows function every time I am finished using Selenium.
def close_windows():
windows = driver.window_handles
for w in windows:
driver.switch_to.window(w)
driver.close()
driver.quit()
close_windows()
I'm trying to run the following sample snippet
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Test
{
public static void main(String[] args)
{
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
//System.out.println("My new program");
}
}
When I run this code, getting the following error.
Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
e6fd}","syncGUID":"zxeywUS-QRBG","location":"app-global","version":"48.0","type":"theme","internalName":"classic/1.0","updateURL":null,"updateKey":null,"optionsURL":null,"optionsType":null,"aboutURL":null,"icons":{"32":"icon.png","48":"icon.png"},"iconURL":null,"icon64URL":null,"defaultLocale":{"name":"Default","description":"The default theme.","creator":"Mozilla","homepageURL":null,"contributors":["Mozilla Contributors"]},"visible":true,"active":true,"userDisabled":false,"appDisabled":false,"descriptor":"C:\\Program Files (x86)\\Mozilla Firefox\\browser\\extensions\\{972ce4c6-7e08-4474-a285-3208198ce6fd}.xpi","installDate":1469556455000,"updateDate":1469556455000,"applyBackgroundUpdates":1,"skinnable":true,"size":21899,"sourceURI":null,"releaseNotesURI":null,"softDisabled":false,"foreignInstall":false,"hasBinaryComponents":false,"strictCompatibility":true,"locales":[],"targetApplications":[{"id":"{ec8030f7-c20a-464f-9b0e-13a3a9e97384}","minVersion":"48.0","maxVersion":"48.0"}],"targetPlatforms":[],"seen":true}
1471332673510 addons.xpi DEBUG getModTime: Recursive scan of {972ce4c6-7e08-4474-a285-3208198ce6fd}
Firfox version is 48.0
Jar which added in eclipse is selenium-java-2.53.0, selenium-java-2.53.0-srcs.
Could anyone please help me to fix this issue.
FireFox 48 brought in some changes that don't play nicely with webdriver. You will need to switch the firefox over to Marionette.
Instructions found here: https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette
Wes Young is right. Firefox changed behavior starting version 48.
You need to use selenium 3 with gecko driver provided by firefox.
Little explanation :
Before Selenium 3, FirefoxDriver used to be in form of Firefox Extension which used to get installed when we instantite firefox driver.
But starting with version 48, Firefox made a change how extensions behave in firefox, basically every extension has to be signed by firefox and driver extension did not qualify for that.
So Firefox took the responsibility of developing the standalone driver for firefox like we have in chrome.
Basically you will have to download gecko driver place it somewhere and configure the path in webdriver.gecko.driver system variable and then use it. It is almost identical to how we use chromedriver now.
PS : we can still use previous versions of firefox with selenium 3 using old firefox driver (in extension form). There is a property to tell we want to use legacy driver (old firefox driver in extension form) or new driver (gecko driver). This has to be set in capabilities.
caps["marionette"] = True/False in python
Similar in other languages
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.
Is there any way how to run Selenium automation test in Internet Explorer 9 in InPrivate mode with IEDriverServer?
I need to test 2 (two) testcases:
1. browser is closed. Open one window of IE InPrivate mode. Run test.
2. browser is opened in normal mode. Open new window of IE InPrivate mode. Run test.
How should JAVA code look for this tests?
Thank you
public void openBrowserInPrivacyMode(boolean isBrowserActive) {
System.setProperty("webdriver.ie.driver", "path/to/IEDriverServer_x32.exe");
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.FORCE_CREATE_PROCESS, true);
сapabilities.setCapability(InternetExplorerDriver.IE_SWITCHES, "-private");
InternetExplorerDriver driver = new InternetExplorerDriver(capabilities);
#Roman's solution is now deprecated.
The new way to do this is as follows:
InternetExplorerOptions ieOptions = new InternetExplorerOptions();
ieOptions.setCapability(InternetExplorerDriver.FORCE_CREATE_PROCESS, true);
ieOptions.addCommandSwitches("-private");
InternetExplorerDriver driver = InternetExplorerDriver(ieOptions));
Also, I had problems doing this, until I set a TabProcGrowth registry value. Before doing this I got the following exception:
org.openqa.selenium.SessionNotCreatedException: Unexpected error launching Internet Explorer.
Unable to use CreateProcess() API. To use CreateProcess() with Internet Explorer 8 or higher,
the value of registry setting in
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\TabProcGrowth must be '0'.
I had this with happening with Windows 10 and Selenium 3.14. Curiously enough, setting the TabProcGrowth value also fixed this for me.