Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
526 views
in Technique[技术] by (71.8m points)

java - Firefox selenium webdriver gives "Insecure Connection"

I've created a Maven project with 20 tests made with Selenium Webdriver (java). Now, when I want to execute my Maven project, I get sometimes the following error:

Mozilla error

This is due to login every test. So, when I want to run 20 tests, sometimes that error appears and I can't continue my test, so it returns "Failed test" in Selenium Webdriver.

Does anybody know how to fix this problem? I've tried to put "Thread.sleep(30000);" at the end of every test to give them some time "not to seem a robot", but it doesn't work...

Thanks so much for your help guys!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here is the Answer to your Question:

The Real Issue:

  1. The URL/Connection with which you are a working if it is Not Secure then whenever you access the URL through Mozilla Firefox 53.0, Firefox will display a lock icon with red strike-through red strikethrough icon in the address bar. Now when URL gets loaded the cursor by default will be positioned on Username field and there will be popup showing a message This connection is not secure. Logins entered here could be compromised. Learn More like this:

enter image description here

  1. Now your script through Selenium enters the username within the Username input field and the Not Secure popup overlays the Password input field.
  2. Next if you try to call the click() or sendKeys() operation in the Password input field the Not Secure popup receives the click and Insecure password warning in Firefox page opens up in the next tab along with Selenium shifting its focus to new tab. Hence test-case starts Failing.

enter image description here

Solution:

In these cases the best solution is:

  1. Create a new Mozilla Firefox Profile. You will find the documentation here. For Example, I have created a Firefox Profile by the name debanjan
  2. Configure the Firefox Profile debanjan to ignore all the UntrustedCertificate issues.
  3. Rerun your Test Script without any issues.
  4. Here is a sample code block to disable insecure_field_warning:

    System.setProperty("webdriver.gecko.driver", "C:\Utility\BrowserDrivers\geckodriver.exe");
    ProfilesIni profile = new ProfilesIni();
    FirefoxProfile testprofile = profile.getProfile("debanjan");
    testprofile.setAcceptUntrustedCertificates(true);
    testprofile.setAssumeUntrustedCertificateIssuer(true);
    testprofile.setPreference("security.insecure_field_warning.contextual.enabled", false);
    DesiredCapabilities dc = DesiredCapabilities.firefox();
    dc.setCapability(FirefoxDriver.PROFILE, testprofile);
    dc.setCapability("marionette", true);
    WebDriver driver =  new FirefoxDriver(dc);
    driver.manage().window().maximize();
    driver.navigate().to("http://demosite.center/wordpress/wp-login.php");
    

Let me know if this Answers your Question.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...