Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/333.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.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_Eclipse_Selenium_Firefox - Fatal编程技术网

Java 执行selenium连接测试时出错(未定义为字符串)

Java 执行selenium连接测试时出错(未定义为字符串),java,eclipse,selenium,firefox,Java,Eclipse,Selenium,Firefox,我有一个错误:预期[object Undefined]Undefined为字符串 我也不知道如何修复它。 我不知道如何修复它,也不知道在哪里搜索潜在错误 Firefox已经启动,但除了访问该站点之外,没有执行任何操作 我的变量paramTest2,paramTest3,paramTest4。。。都是空的,我不明白为什么。。。只有paramets1包含一些东西,这就是web地址 以下是完整的跟踪: [TestNG] Running: C:\Temp\testng-eclipse--80631997

我有一个错误:预期[object Undefined]Undefined为字符串 我也不知道如何修复它。 我不知道如何修复它,也不知道在哪里搜索潜在错误

Firefox已经启动,但除了访问该站点之外,没有执行任何操作

我的变量paramTest2,paramTest3,paramTest4。。。都是空的,我不明白为什么。。。只有paramets1包含一些东西,这就是web地址

以下是完整的跟踪:

[TestNG] Running:
C:\Temp\testng-eclipse--806319973\testng-customsuite.xml

###################################################
##### TEST : Connexion
##### DESCRIPTION : Test sur la connexion
###################################################
1491402504078   geckodriver INFO    Listening on 127.0.0.1:13254
1491402504745   mozprofile::profile INFO    Using profile path    C:\Temp\rust_mozprofile.IGVKHcaTXwv0
1491402504751   geckodriver::marionette INFO    Starting browser C:\Program Files\Nightly\firefox.exe with args []
1491402504759   geckodriver::marionette INFO    Connecting to Marionette on localhost:60098
1491402505513   Marionette  WARN    Deprecated preference marionette.defaultPrefs.enabled detected, please use marionette.enabled
[GPU 7556] WARNING: pipe error: 109: file c:/builds/moz2_slave/m-cen-w64-ntly-000000000000000/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc,   line 346
[Child 11252] WARNING: pipe error: 109: file c:/builds/moz2_slave/m-cen-w64-ntly-  000000000000000/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc,   line 346
[Child 11252] WARNING: pipe error: 109: file c:/builds/moz2_slave/m-cen-w64-ntly-000000000000000/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346
1491402507490   Marionette  INFO    Listening on port 60098
1491402507875   Marionette  WARN    TLS certificate errors will be ignored for this session
avr. 05, 2017 4:28:27 PM org.openqa.selenium.remote.ProtocolHandshake  createSession
INFOS: Detected dialect: W3C
Connexion au site : https://wd3-impl.workday.com/ag_preview/login.htmld?redirect=n
Connexion à l'espace client
[Utils] Attempting to create C:\Users\ng647f1\Desktop\Worspaces_Automation\WD_Automation\WD_Automation_EXPORT\WD_Automation\test-output\Default suite\Default test.xml
[Utils]   Directory C:\Users\ng647f1\Desktop\Worspaces_Automation\WD_Automation\WD_Automation_EXPORT\WD_Automation\test-output\Default suite exists: true
[Utils] Attempting to create C:\Users\ng647f1\Desktop\Worspaces_Automation\WD_Automation\WD_Automation_EXPORT\WD_Automation\test-output\Default suite\Default test0.xml
[Utils]   Directory C:\Users\ng647f1\Desktop\Worspaces_Automation\WD_Automation\WD_Automation_EXPORT\WD_Automation\test-output\Default suite exists: true
FAILED: testCas("Connexion", "testcases\testcase1.csv", "Test sur la connexion")
org.openqa.selenium.InvalidArgumentException: Expected [object Undefined] undefined to be a string
Build info: version: '3.3.1', revision: '5234b325d5', time: '2017-03-10 09:10:29 +0000'
System info: host: 'TOLX300092143', ip: '44.10.108.53', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{moz:profile=C:\Temp\rust_mozprofile.IGVKHcaTXwv0, rotatable=false, timeouts={implicit=0, pageLoad=300000, script=30000}, pageLoadStrategy=normal, platform=ANY, specificationLevel=0, moz:accessibilityChecks=false, acceptInsecureCerts=true, browserVersion=55.0a1, platformVersion=6.1, moz:processID=7624, browserName=firefox, platformName=windows_nt}]
Session ID: 44ae5d76-506f-4cd3-95c6-b11b71455bfd
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:133)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:99)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:43)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:163)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:604)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:274)
at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:98)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at      org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:51)
at com.sun.proxy.$Proxy6.sendKeys(Unknown Source)
at selenium.FindElements.connexionWD(FindElements.java:27)
at selenium.SeleniumTest.testEtape(SeleniumTest.java:105)
at selenium.SeleniumTest.testCas(SeleniumTest.java:81)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:100)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:646)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:811)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1137)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:753)
at org.testng.TestRunner.run(TestRunner.java:607)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:368)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:363)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:321)
at org.testng.SuiteRunner.run(SuiteRunner.java:270)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1284)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1209)
at org.testng.TestNG.runSuites(TestNG.java:1124)
at org.testng.TestNG.run(TestNG.java:1096)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)


===============================================
Default test
Tests run: 1, Failures: 1, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================

[TestNG] Time taken by org.testng.reporters.jq.Main@13fee20c: 75 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@4cb2c100: 15 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@5d624da6: 8 ms
[Utils] Attempting to create C:\Users\ng647f1\Desktop\Worspaces_Automation\WD_Automation\WD_Automation_EXPORT\WD_Automation\test-output\old\Default suite\toc.html
[Utils]   Directory C:\Users\ng647f1\Desktop\Worspaces_Automation\WD_Automation\WD_Automation_EXPORT\WD_Automation\test-output\old\Default suite exists: true
[Utils] Attempting to create C:\Users\ng647f1\Desktop\Worspaces_Automation\WD_Automation\WD_Automation_EXPORT\WD_Automation\test-output\old\Default suite\Default test.properties
[Utils]   Directory C:\Users\ng647f1\Desktop\Worspaces_Automation\WD_Automation\WD_Automation_EXPORT\WD_Automation\test-output\old\Default suite exists: true
[Utils] Attempting to create C:\Users\ng647f1\Desktop\Worspaces_Automation\WD_Automation\WD_Automation_EXPORT\WD_Automation\test-output\old\Default suite\index.html
[Utils]   Directory C:\Users\ng647f1\Desktop\Worspaces_Automation\WD_Automation\WD_Automation_EXPORT\WD_Automation\test-output\old\Default suite exists: true
[Utils] Attempting to create C:\Users\ng647f1\Desktop\Worspaces_Automation\WD_Automation\WD_Automation_EXPORT\WD_Automation\test-output\old\Default suite\main.html
 [Utils]   Directory C:\Users\ng647f1\Desktop\Worspaces_Automation\WD_Automation\WD_Automation_EXPORT\WD_Automation\test-output\old\Default suite exists: true
 [Utils] Attempting to create C:\Users\ng647f1\Desktop\Worspaces_Automation\WD_Automation\WD_Automation_EXPORT\WD_Automation\test-output\old\Default suite\groups.html
 [Utils]   Directory C:\Users\ng647f1\Desktop\Worspaces_Automation\WD_Automation\WD_Automation_EXPORT\WD_Automation\test-output\old\Default suite exists: true
 [Utils] Attempting to create C:\Users\ng647f1\Desktop\Worspaces_Automation\WD_Automation\WD_Automation_EXPORT\WD_Automation\test-output\old\Default suite\classes.html
 [Utils]   Directory C:\Users\ng647f1\Desktop\Worspaces_Automation\WD_Automation\WD_Automation_EXPORT\WD_Automation\test-output\old\Default suite exists: true
 [Utils] Attempting to create C:\Users\ng647f1\Desktop\Worspaces_Automation\WD_Automation\WD_Automation_EXPORT\WD_Automation\test-output\old\Default suite\reporter-output.html
 [Utils]   Directory C:\Users\ng647f1\Desktop\Worspaces_Automation\WD_Automation\WD_Automation_EXPORT\WD_Automation\test-output\old\Default suite exists: true
 [Utils] Attempting to create C:\Users\ng647f1\Desktop\Worspaces_Automation\WD_Automation\WD_Automation_EXPORT\WD_Automation\test-output\old\Default suite\methods-not-run.html
 [Utils]   Directory C:\Users\ng647f1\Desktop\Worspaces_Automation\WD_Automation\WD_Automation_EXPORT\WD_Automation\test-output\old\Default suite exists: true
 [Utils] Attempting to create C:\Users\ng647f1 \Desktop\Worspaces_Automation\WD_Automation\WD_Automation_EXPORT\WD_Automation\test-output\old\Default suite\testng.xml.html
 [Utils]   Directory C:\Users\ng647f1\Desktop\Worspaces_Automation\WD_Automation\WD_Automation_EXPORT\WD_Automation\test-output\old\Default suite exists: true
 [Utils] Attempting to create C:\Users\ng647f1\Desktop\Worspaces_Automation\WD_Automation\WD_Automation_EXPORT\WD_Automation\test-output\old\index.html
[Utils]   Directory C:\Users\ng647f1\Desktop\Worspaces_Automation\WD_Automation\WD_Automation_EXPORT\WD_Automation\test-output\old exists: true
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@5f2050f6: 44 ms
[Utils] Attempting to create C:\Users\ng647f1\Desktop\Worspaces_Automation\WD_Automation\WD_Automation_EXPORT\WD_Automation\test-output\junitreports\TEST-selenium.SeleniumTest.xml
[Utils]   Directory C:\Users\ng647f1\Desktop\Worspaces_Automation\WD_Automation\WD_Automation_EXPORT\WD_Automation\test-output\junitreports exists: true
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@77b52d12: 10 ms
 [Utils] Attempting to create C:\Users\ng647f1\Desktop\Worspaces_Automation\WD_Automation\WD_Automation_EXPORT\WD_Automation\test-output\testng-failed.xml
[Utils]   Directory C:\Users\ng647f1\Desktop\Worspaces_Automation\WD_Automation\WD_Automation_EXPORT\WD_Automation\test-output exists: true
[Utils] Attempting to create C:\Users\ng647f1\Desktop\Worspaces_Automation\WD_Automation\WD_Automation_EXPORT\WD_Automation\test-output\Default suite\testng-failed.xml
[Utils]   Directory C:\Users\ng647f1\Desktop\Worspaces_Automation\WD_Automation\WD_Automation_EXPORT\WD_Automation\test-output\Default suite exists: true
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 15 ms
以下是我的脚本findElements:

package selenium;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;


public class FindElements {

final WebDriver driver;

@FindBy(how = How.XPATH, using = "//input[@aria-label=\"Nom d'utilisateur\"]")
public WebElement PSEUDO;

@FindBy(how = How.XPATH, using = "//input[@aria-label='Mot de passe']")
public WebElement MDP;

@FindBy(how = How.CLASS_NAME, using = "GDQYR4DOVK")
public WebElement CONNECT;

public FindElements(WebDriver driver){
    this.driver = driver;
}

public void connexionWD(String EmailConnect, String MdpConnect){
    PSEUDO.sendKeys(EmailConnect);
    MDP.sendKeys(MdpConnect);
    CONNECT.click();
}

}
这是我的脚本SeleniumTest:

package selenium;

import java.io.IOException;
import org.testng.annotations.Test;
import org.testng.annotations.DataProvider;
import java.io.FileReader;
import java.util.List;
import com.opencsv.*;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.remote.DesiredCapabilities;

public class SeleniumTest {

private static WebDriver driver = null;

@DataProvider(name = "testPlan")
public Object[][] motCles() throws IOException {
      //Lecture du plan de test avec Open CSV
      CSVReader reader = new CSVReader(new FileReader("testplan.csv"), ';', '"', 1);
             int i = 0;
             List<String[]> allRows = reader.readAll();
             Object testPlan[][]= new Object[allRows.size()][3];
             for(String[] row : allRows){
                   testPlan[i][0] = row[0];
                   testPlan[i][1] = row[1];
                   testPlan[i][2] = row[2];
                   i++;
             }
             reader.close();
      return testPlan;
}


@Test(dataProvider = "testPlan")

public void testCas(String nomTest, String lienTest, String descTest) throws Exception {

        //Lecture du cas de test avec OpenCSV
        CSVReader reader = new CSVReader(new FileReader(lienTest), ';', '"', 1);

        //System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
        //System.setProperty("webdriver.ie.driver", "IEDriverServer.exe");
        System.setProperty("webdriver.firefox.marionnette","C:\\Users\\ng647f1\\Desktop\\Worspaces_Automation\\WD_Automation\\WD_Automation_EXPORT\\WD_Automation\\geckodriver.exe");

        int i = 0;
        int j = 0;

        System.out.println("###################################################");
        System.out.println("##### TEST : " + nomTest);
        System.out.println("##### DESCRIPTION : " + descTest);
        System.out.println("###################################################");

        List<String[]> allRows = reader.readAll();
        String testDescription[][]= new String[50][21];

        //Sélection du navigateur utilisé pour le test en cours. Ce navigateur est défini dans les cas de tests.
        DesiredCapabilities capabilities;
        capabilities = DesiredCapabilities.firefox();
        capabilities.setCapability("marionette", true);
        capabilities.setCapability("proxyType", "pac");
        capabilities.setCapability("acceptInsecureCerts", true);
        capabilities.setCapability("browser.private.browsing.autostart", true); 

        driver = new FirefoxDriver(capabilities);

        //On agrandit la fenêtre de test pour éviter les problèmes d'invisibilité d'éléments avec ChromeDriver.
        driver.manage().window().maximize();
        //On définit le temps d'attente avant qu'un cas de test tombe en erreur quand un élément n'est pas trouvé.
        driver.manage().timeouts().implicitlyWait(1000, TimeUnit.SECONDS);

        //On lit les paramètres du cas de test dans le fichier du plan de test
        for(String[] row : allRows){
              for(j = 0; j<=20; j++){
                     testDescription[i][j] = row[j];
              }
              if (testDescription[i][0] != null) {
                     //On lance le cas de test
                     testEtape(testDescription[i][0], testDescription[i][1], testDescription[i][2], testDescription[i][3], testDescription[i][4], testDescription[i][5], testDescription[i][6], testDescription[i][7], testDescription[i][8], testDescription[i][9], testDescription[i][10], testDescription[i][11], testDescription[i][12], testDescription[i][13], testDescription[i][14], testDescription[i][15], testDescription[i][16], testDescription[i][17], testDescription[i][18], testDescription[i][19], testDescription[i][20]);
              }
              i++;
        }
        driver.quit();
        reader.close();     
}

// Interprétation des mots-clés

public void testEtape(String motCle, String paramTest1, String paramTest2, String paramTest3, String paramTest4, String paramTest5, String paramTest6, String paramTest7, String paramTest8, String paramTest9, String paramTest10, String paramTest11, String paramTest12, String paramTest13, String paramTest14, String paramTest15, String paramTest16, String paramTest17, String paramTest18, String paramTest19, String paramTest20) throws Exception {    

    //On initialise les classes des pages avec PageFactory
    FindElements FindElements1 = PageFactory.initElements(driver, FindElements.class);

    //Pour chaque mot clé, des actions sont lancées. Certaines de ces actions sont des fonctions définies dans les classes des pages
    switch(motCle.toUpperCase()){ 
        case "ALLER":
            System.out.println("Connexion au site : " + paramTest1);
            driver.get(paramTest1);
            driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        break;
        case "CONNEXION":
             System.out.println("Connexion à l'espace client");
             FindElements1.connexionWD(paramTest1, paramTest2);
             driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        break;
        default :
             System.out.println("||||| Mot clé non trouvé : " + motCle.toUpperCase());  
    }

}


}
目前只包含一个测试用例testcase1.csv:

Mot clé;Paramètre 1;Paramètre 2;Paramètre 3;Paramètre 4;Paramètre 5;Paramètre 6;Paramètre 7;Paramètre 8;Paramètre 9;Paramètre 10;Paramètre 11;Paramètre 12;Paramètre 13;Paramètre 14;Paramètre 15;Paramètre 16;Paramètre 17;Paramètre 18;Paramètre 19;Paramètre 20
ALLER;https://wd3-impl.workday.com/ag_preview/login.htmld?redirect=n;;;;;;;;;;;;;;;;;;;
CONNEXION;thisIsMySecret@email;MySecretPassword;;;;;;;;;;;;;;;;;;

我希望你们中的一位能帮助我:)

如果你只是想在
testCas
内部调用方法
testtape
,而不是作为一个单独的测试,那么从
testtape
中删除
@test
,看起来selenium跟不上WebDriver

从stacktrace上看,Selenium似乎发送了错误的JSON 尸体到壁虎河。壁虎河

    {text: "string"} 
而Selenium中的RemoteWebElement.java

    {value: ["s", "t", "r", "i", "n", "g"]} 
我会向Selenium提交一个bug


是 啊它适用于“TesteTapel需要21个参数,但@Test注释中提供了0”错误,但不适用于“预期[object Undefined]Undefined to a string”错误,可能尝试使用
testDescription[i][0]。在
testCas
中调用
TesteTapel
作为
TesteTapel(testDescription[i][0]时使用字符串.toString,testDescription[i][1]。toString(),testDescription[i][2]。toString()
它没有改变任何内容尝试在调用
FindElements1.connexionWD(paramts1,paramts2)之前在
testtape
中打印
paramTest1,paramTest2
paramTest1包含web地址,paramTest2为空!
    {value: ["s", "t", "r", "i", "n", "g"]}