Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Selenium测试在直接运行时失败,但在作为测试运行时通过_Java_Selenium_Selenium Webdriver - Fatal编程技术网

Java Selenium测试在直接运行时失败,但在作为测试运行时通过

Java Selenium测试在直接运行时失败,但在作为测试运行时通过,java,selenium,selenium-webdriver,Java,Selenium,Selenium Webdriver,当我作为简单java程序运行时,我的简单selenium测试失败。 基本上,FF浏览器会立即启动并崩溃,出现以下错误 org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7056 after 45000 ms. Firefox console output: 79e-8d7a-e26a942a87c8}":{"d":"C:\\Program F

当我作为简单java程序运行时,我的简单selenium测试失败。 基本上,FF浏览器会立即启动并崩溃,出现以下错误

    org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7056 after 45000 ms. Firefox console output:
    79e-8d7a-e26a942a87c8}":{"d":"C:\\Program Files (x86)\\WinZip Courier\\FFExt","e":false,"v":"3.5","st":1340002031091,"mt":1324569850000},"light_plugin_D772DC8D6FAF43A29B25C4EBAA5AD1DE@kaspersky.com":{"d":"C:\\Program Files (x86)\\Kaspersky Lab\\Kaspersky Internet Security 16.0.0\\FFExt\\light_plugin_firefox","e":false,"v":"4.6.2-40","st":1464513627629,"mt":1464513107540}}}
    1464894922238   addons.xpi  DEBUG   Existing add-on fxdriver@googlecode.com in app-profile
    1464894922239   addons.xpi  DEBUG   getModTime: Recursive scan of {972ce4c6-7e08-4474-a285-3208198ce6fd}
    1464894922240   addons.xpi  DEBUG   Existing add-on {972ce4c6-7e08-4474-a285-3208198ce6fd} in app-global
    1464894922240   addons.xpi  DEBUG   Existing add-on {74c841e3-b59f-479e-8d7a-e26a942a87c8} in winreg-app-global
    1464894922241   addons.xpi  DEBUG   Existing add-on light_plugin_D772DC8D6FAF43A29B25C4EBAA5AD1DE@kaspersky.com in winreg-app-global
    1464894922241   addons.xpi  DEBUG   getInstallState changed: false, state: {"app-profile":{"fxdriver@googlecode.com":{"d":"C:\\Users\\manideep\\AppData\\Local\\Temp\\anonymous2127859292061232754webdriver-profile\\extensions\\fxdriver@googlecode.com","e":false,"v":"2.45.0","st":1464894915312,"mt":1464894915280}},"app-global":{"{972ce4c6-7e08-4474-a285-3208198ce6fd}":{"d":"C:\\Program Files (x86)\\Mozilla Firefox\\browser\\extensions\\{972ce4c6-7e08-4474-a285-3208198ce6fd}","e":true,"v":"44.0.2","st":1462469835718,"mt":1462469835312}},"winreg-app-global":{"{74c841e3-b59f-479e-8d7a-e26a942a87c8}":{"d":"C:\\Program Files (x86)\\WinZip Courier\\FFExt","e":false,"v":"3.5","st":1340002031091,"mt":1324569850000},"light_plugin_D772DC8D6FAF43A29B25C4EBAA5AD1DE@kaspersky.com":{"d":"C:\\Program Files (x86)\\Kaspersky Lab\\Kaspersky Internet Security 16.0.0\\FFExt\\light_plugin_firefox","e":false,"v":"4.6.2-40","st":1464513627629,"mt":1464513107540}}}
    1464894922243   addons.xpi  DEBUG   No changes found
    1464894922251   addons.manager  DEBUG   Registering shutdown blocker for XPIProvider
    1464894922252   addons.manager  DEBUG   Provider finished startup: XPIProvider
    1464894922252   addons.manager  DEBUG   Starting provider: LightweightThemeManager
    1464894922252   addons.manager  DEBUG   Registering shutdown blocker for LightweightThemeManager
    1464894922252   addons.manager  DEBUG   Provider finished startup: LightweightThemeManager
    1464894922253   addons.manager  DEBUG   Starting provider: GMPProvider
    1464894922259   addons.manager  DEBUG   Registering shutdown blocker for GMPProvider
    1464894922259   addons.manager  DEBUG   Provider finished startup: GMPProvider
    1464894922259   addons.manager  DEBUG   Starting provider: PluginProvider
    1464894922259   addons.manager  DEBUG   Registering shutdown blocker for PluginProvider
    1464894922260   addons.manager  DEBUG   Provider finished startup: PluginProvider
    1464894922260   addons.manager  DEBUG   Completed startup sequence
    1464894922402   addons.xpi-utils    DEBUG   Starting async load of XPI database C:\Users\manideep\AppData\Local\Temp\anonymous2127859292061232754webdriver-profile\extensions.json
    *** Blocklist::_loadBlocklistFromFile: blocklist is disabled
    1464894922542   addons.manager  DEBUG   Starting provider: <unnamed-provider>
    1464894922542   addons.manager  DEBUG   Registering shutdown blocker for <unnamed-provider>
    1464894922542   addons.manager  DEBUG   Provider finished startup: <unnamed-provider>
    1464894922657   addons.xpi-utils    DEBUG   Async JSON file read took 0 MS
    1464894922657   addons.xpi-utils    DEBUG   Finished async read of XPI database, parsing...
    1464894922658   addons.xpi-utils    DEBUG   Successfully read XPI database
    1464894922762   addons.manager  DEBUG   Starting provider: PreviousExperimentProvider
    1464894922762   addons.manager  DEBUG   Registering shutdown blocker for PreviousExperimentProvider
    1464894922763   addons.manager  DEBUG   Provider finished startup: PreviousExperimentProvider
    JavaScript warning: https://normandy.cdn.mozilla.net/static/js/bundles/selfrepair-7575f6d27445b45bcffb.js, line 9825: mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create

        at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:118)
        at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:246)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:114)
        at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:193)
        at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:186)
        at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:182)
        at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:95)
        at org.openqa.selenium.example.Selenium_Test.main(Selenium_Test.java:24)
    org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(C:\Program Files (x86)\Mozilla Firefox\firefox.exe) on port 7056; process output follows: 
    79e-8d7a-e26a942a87c8}":{"d":"C:\\Program Files (x86)\\WinZip Courier\\FFExt","e":false,"v":"3.5","st":1340002031091,"mt":1324569850000},"light_plugin_D772DC8D6FAF43A29B25C4EBAA5AD1DE@kaspersky.com":{"d":"C:\\Program Files (x86)\\Kaspersky Lab\\Kaspersky Internet Security 16.0.0\\FFExt\\light_plugin_firefox","e":false,"v":"4.6.2-40","st":1464513627629,"mt":1464513107540}}}
    1464894922238   addons.xpi  DEBUG   Existing add-on fxdriver@googlecode.com in app-profile
    1464894922239   addons.xpi  DEBUG   getModTime: Recursive scan of {972ce4c6-7e08-4474-a285-3208198ce6fd}
    1464894922240   addons.xpi  DEBUG   Existing add-on {972ce4c6-7e08-4474-a285-3208198ce6fd} in app-global
    1464894922240   addons.xpi  DEBUG   Existing add-on {74c841e3-b59f-479e-8d7a-e26a942a87c8} in winreg-app-global
    1464894922241   addons.xpi  DEBUG   Existing add-on light_plugin_D772DC8D6FAF43A29B25C4EBAA5AD1DE@kaspersky.com in winreg-app-global
    1464894922241   addons.xpi  DEBUG   getInstallState changed: false, state: {"app-profile":{"fxdriver@googlecode.com":{"d":"C:\\Users\\manideep\\AppData\\Local\\Temp\\anonymous2127859292061232754webdriver-profile\\extensions\\fxdriver@googlecode.com","e":false,"v":"2.45.0","st":1464894915312,"mt":1464894915280}},"app-global":{"{972ce4c6-7e08-4474-a285-3208198ce6fd}":{"d":"C:\\Program Files (x86)\\Mozilla Firefox\\browser\\extensions\\{972ce4c6-7e08-4474-a285-3208198ce6fd}","e":true,"v":"44.0.2","st":1462469835718,"mt":1462469835312}},"winreg-app-global":{"{74c841e3-b59f-479e-8d7a-e26a942a87c8}":{"d":"C:\\Program Files (x86)\\WinZip Courier\\FFExt","e":false,"v":"3.5","st":1340002031091,"mt":1324569850000},"light_plugin_D772DC8D6FAF43A29B25C4EBAA5AD1DE@kaspersky.com":{"d":"C:\\Program Files (x86)\\Kaspersky Lab\\Kaspersky Internet Security 16.0.0\\FFExt\\light_plugin_firefox","e":false,"v":"4.6.2-40","st":1464513627629,"mt":1464513107540}}}
    1464894922243   addons.xpi  DEBUG   No changes found
    1464894922251   addons.manager  DEBUG   Registering shutdown blocker for XPIProvider
    1464894922252   addons.manager  DEBUG   Provider finished startup: XPIProvider
    1464894922252   addons.manager  DEBUG   Starting provider: LightweightThemeManager
    1464894922252   addons.manager  DEBUG   Registering shutdown blocker for LightweightThemeManager
    1464894922252   addons.manager  DEBUG   Provider finished startup: LightweightThemeManager
    1464894922253   addons.manager  DEBUG   Starting provider: GMPProvider
    1464894922259   addons.manager  DEBUG   Registering shutdown blocker for GMPProvider
    1464894922259   addons.manager  DEBUG   Provider finished startup: GMPProvider
    1464894922259   addons.manager  DEBUG   Starting provider: PluginProvider
    1464894922259   addons.manager  DEBUG   Registering shutdown blocker for PluginProvider
    1464894922260   addons.manager  DEBUG   Provider finished startup: PluginProvider
    1464894922260   addons.manager  DEBUG   Completed startup sequence
    1464894922402   addons.xpi-utils    DEBUG   Starting async load of XPI database C:\Users\manideep\AppData\Local\Temp\anonymous2127859292061232754webdriver-profile\extensions.json
    *** Blocklist::_loadBlocklistFromFile: blocklist is disabled
    1464894922542   addons.manager  DEBUG   Starting provider: <unnamed-provider>
    1464894922542   addons.manager  DEBUG   Registering shutdown blocker for <unnamed-provider>
    1464894922542   addons.manager  DEBUG   Provider finished startup: <unnamed-provider>
    1464894922657   addons.xpi-utils    DEBUG   Async JSON file read took 0 MS
    1464894922657   addons.xpi-utils    DEBUG   Finished async read of XPI database, parsing...
    1464894922658   addons.xpi-utils    DEBUG   Successfully read XPI database
    1464894922762   addons.manager  DEBUG   Starting provider: PreviousExperimentProvider
    1464894922762   addons.manager  DEBUG   Registering shutdown blocker for PreviousExperimentProvider
    1464894922763   addons.manager  DEBUG   Provider finished startup: PreviousExperimentProvider
    JavaScript warning: https://normandy.cdn.mozilla.net/static/js/bundles/selfrepair-7575f6d27445b45bcffb.js, line 9825: mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create

    Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26 23:59:50'
    System info: host: 'manideep-PC', ip: '10.0.0.7', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_25'
    Driver info: driver.version: FirefoxDriver
        at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:130)
        at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:246)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:114)
        at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:193)
        at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:186)
        at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:182)
        at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:95)
        at org.openqa.selenium.example.Selenium_Test.main(Selenium_Test.java:24)
    Caused by: org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7056 after 45000 ms. Firefox console output:
    79e-8d7a-e26a942a87c8}":{"d":"C:\\Program Files (x86)\\WinZip Courier\\FFExt","e":false,"v":"3.5","st":1340002031091,"mt":1324569850000},"light_plugin_D772DC8D6FAF43A29B25C4EBAA5AD1DE@kaspersky.com":{"d":"C:\\Program Files (x86)\\Kaspersky Lab\\Kaspersky Internet Security 16.0.0\\FFExt\\light_plugin_firefox","e":false,"v":"4.6.2-40","st":1464513627629,"mt":1464513107540}}}
    1464894922238   addons.xpi  DEBUG   Existing add-on fxdriver@googlecode.com in app-profile
    1464894922239   addons.xpi  DEBUG   getModTime: Recursive scan of {972ce4c6-7e08-4474-a285-3208198ce6fd}
    1464894922240   addons.xpi  DEBUG   Existing add-on {972ce4c6-7e08-4474-a285-3208198ce6fd} in app-global
    1464894922240   addons.xpi  DEBUG   Existing add-on {74c841e3-b59f-479e-8d7a-e26a942a87c8} in winreg-app-global
    1464894922241   addons.xpi  DEBUG   Existing add-on light_plugin_D772DC8D6FAF43A29B25C4EBAA5AD1DE@kaspersky.com in winreg-app-global
    1464894922241   addons.xpi  DEBUG   getInstallState changed: false, state: {"app-profile":{"fxdriver@googlecode.com":{"d":"C:\\Users\\manideep\\AppData\\Local\\Temp\\anonymous2127859292061232754webdriver-profile\\extensions\\fxdriver@googlecode.com","e":false,"v":"2.45.0","st":1464894915312,"mt":1464894915280}},"app-global":{"{972ce4c6-7e08-4474-a285-3208198ce6fd}":{"d":"C:\\Program Files (x86)\\Mozilla Firefox\\browser\\extensions\\{972ce4c6-7e08-4474-a285-3208198ce6fd}","e":true,"v":"44.0.2","st":1462469835718,"mt":1462469835312}},"winreg-app-global":{"{74c841e3-b59f-479e-8d7a-e26a942a87c8}":{"d":"C:\\Program Files (x86)\\WinZip Courier\\FFExt","e":false,"v":"3.5","st":1340002031091,"mt":1324569850000},"light_plugin_D772DC8D6FAF43A29B25C4EBAA5AD1DE@kaspersky.com":{"d":"C:\\Program Files (x86)\\Kaspersky Lab\\Kaspersky Internet Security 16.0.0\\FFExt\\light_plugin_firefox","e":false,"v":"4.6.2-40","st":1464513627629,"mt":1464513107540}}}
    1464894922243   addons.xpi  DEBUG   No changes found
    1464894922251   addons.manager  DEBUG   Registering shutdown blocker for XPIProvider
    1464894922252   addons.manager  DEBUG   Provider finished startup: XPIProvider
    1464894922252   addons.manager  DEBUG   Starting provider: LightweightThemeManager
    1464894922252   addons.manager  DEBUG   Registering shutdown blocker for LightweightThemeManager
    1464894922252   addons.manager  DEBUG   Provider finished startup: LightweightThemeManager
    1464894922253   addons.manager  DEBUG   Starting provider: GMPProvider
    1464894922259   addons.manager  DEBUG   Registering shutdown blocker for GMPProvider
    1464894922259   addons.manager  DEBUG   Provider finished startup: GMPProvider
    1464894922259   addons.manager  DEBUG   Starting provider: PluginProvider
    1464894922259   addons.manager  DEBUG   Registering shutdown blocker for PluginProvider
    1464894922260   addons.manager  DEBUG   Provider finished startup: PluginProvider
    1464894922260   addons.manager  DEBUG   Completed startup sequence
    1464894922402   addons.xpi-utils    DEBUG   Starting async load of XPI database C:\Users\manideep\AppData\Local\Temp\anonymous2127859292061232754webdriver-profile\extensions.json
    *** Blocklist::_loadBlocklistFromFile: blocklist is disabled
    1464894922542   addons.manager  DEBUG   Starting provider: <unnamed-provider>
    1464894922542   addons.manager  DEBUG   Registering shutdown blocker for <unnamed-provider>
    1464894922542   addons.manager  DEBUG   Provider finished startup: <unnamed-provider>
    1464894922657   addons.xpi-utils    DEBUG   Async JSON file read took 0 MS
    1464894922657   addons.xpi-utils    DEBUG   Finished async read of XPI database, parsing...
    1464894922658   addons.xpi-utils    DEBUG   Successfully read XPI database
    1464894922762   addons.manager  DEBUG   Starting provider: PreviousExperimentProvider
    1464894922762   addons.manager  DEBUG   Registering shutdown blocker for PreviousExperimentProvider
    1464894922763   addons.manager  DEBUG   Provider finished startup: PreviousExperimentProvider
    JavaScript warning: https://normandy.cdn.mozilla.net/static/js/bundles/selfrepair-7575f6d27445b45bcffb.js, line 9825: mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create

        at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:118)
        ... 7 more

问题在于JAR文件,selenium 2.45和2.53独立JAR文件之间存在冲突

为了避免这个问题,请确保用于selenium的所有JAR都是相同的版本


从MAVEN成功执行的原因是,它从MAVEN依赖项中获取JAR,但当作为JAVA应用程序运行程序时,它面临冲突。

类似的程序在作为Cucumber/feature file.program运行时正确运行。WebDriver driver=new FirefoxDriver()上的程序崩溃;行本身。您使用的是哪个
firefox
selenium
版本?感谢您的帮助,问题在于JAR文件,selenium 2.45和2.53独立JAR文件之间存在冲突。
Code for above failing program is :
import java.util.List;

import net.sourceforge.htmlunit.corejs.javascript.tools.shell.Environment;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.Select;

public class Selenium_Test  {
//  public class Example  {
        public static void main(String[] args) {

            try {

                WebDriver driver = new FirefoxDriver();

                driver.get("http://www.moneycontrol.com/portfolio_plus/sso/portfolio_signup.php");

          }
                WebElement element = driver.findElement(By.className("btn_logpor"));
                System.out.println(element.getText());

                // Enter something to search for
                element.sendKeys("Cheese!");

                // Now submit the form. WebDriver will find the form for us from the element
                element.submit();

                // Check the title of the page
                System.out.println("Page title is: " + driver.getTitle());

                Select abc = new Select(driver.findElement(By.xpath("")));
//              abc.selectByValue(value);

            } catch (Exception e) {
                e.printStackTrace();
//          }
        }
    }
}