2016-11-27 21 views
0

私はキュウリをjavaとselenium webdriverで使用する方法を学んでいます。私はその場所にアーキテクチャを持っており、私は非常に特定の問題に直面しています。キュウリの解析文字列

@When("^I login with the parameters \"([^\"]*)\" and \"([^\"]*)\" and \" ([^\"]*)\"") 

    public void I_login_with_the_parameters(String arg1, String arg2, String arg3) throws Throwable{ 

     if (arg1.equals("PRO")) { 
      arg1 = "PRO"; 
     } 
     if (arg2.equals("testleader")) { 
      arg2 = "testleader"; 
     } 
     if (arg3.equals("Chrome")) { 
      arg3 = "Chrome"; 
     } 
     assertTrue (codebase.Beoordeling_Login.correctinloggen(arg1, arg2, arg3)); 

    } 

このコードが動作する理由を私は理解していない、と私は去るときのステートメントは、私はこのように、nullポインタ例外を取得する場合:

@When("^I login with the parameters \"([^\"]*)\" and \"([^\"]*)\" and \"([^\"]*)\"") 

public void I_login_with_the_parameters(String arg1, String arg2, String arg3) throws Throwable{ 

    assertTrue (codebase.Beoordeling_Login.correctinloggen(arg1, arg2, arg3)); 

} 

は私を取得します。

java.lang.NullPointerException 
at codebase.LoginPortal.inloggen(LoginPortal.java:14) 
at codebase.Beoordeling_Login.correctinloggen(Beoordeling_Login.java:12) 
at steps.InloggenSteps.I_login_with_the_parameters(InloggenSteps.java:32) 
at ✽.When I login with the parameters "PRO" and "testleader" and "Chrome" (featurefiles/inloggen.feature:9) 

if文を返すと、期待通りに動作するので、arg1、arg2、arg3の文字列は実際には文字列であり、使用することができます。

なぜ私はログイン方法でそれらを使用できないのでしょうか?醜い方法で文字列を再設定する必要がありますか?

編集1:githubの上

public class LoginPortal { public WebDriver inloggen(String Omgeving, String Rol, String Browser) { 
String InlogUrl = null; WebDriver driver = anroepDriver.roepdriver(Browser); 
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 

完全なコード:https://github.com/Yourtestprofessionals/YourCucumber

EDIT2:これまでの回答のために歓声。私の問題はまだ解決されていません。

答えて

0

EDIT

は、ここに私の変更のpom.xmlです。私はselenium-javaバージョン2.53.1に戻った。私はまた確実にJava 1.8(Oracle)を追加しました。このポンと私に知らせてください。

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 

<modelVersion>4.0.0</modelVersion> 
<groupId>com.czeczotka.bdd</groupId> 
<artifactId>cucumber-jvm-maven</artifactId> 
<packaging>jar</packaging> 
<version>1.0-SNAPSHOT</version> 
<name>cucumber-jvm-maven</name> 
<url>http://maven.apache.org</url> 

<dependencies> 
    <dependency> 
     <groupId>info.cukes</groupId> 
     <artifactId>cucumber-java</artifactId> 
     <version>1.2.5</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>info.cukes</groupId> 
     <artifactId>cucumber-junit</artifactId> 
     <version>1.2.5</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.12</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>info.cukes</groupId> 
     <artifactId>cucumber-junit</artifactId> 
     <version>1.2.5</version> 
    </dependency> 
    <dependency> 
     <groupId>org.seleniumhq.selenium</groupId> 
     <artifactId>selenium-java</artifactId> 
     <version>2.53.1</version> 
    </dependency> 
    <dependency> 
     <groupId>org.seleniumhq.selenium</groupId> 
     <artifactId>selenium-firefox-driver</artifactId> 
     <version>2.53.1</version> 
    </dependency> 
</dependencies> 

<build> 
    <pluginManagement> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-surefire-plugin</artifactId> 
       <version>2.19.1</version> 
       <configuration> 
        <additionalClasspathElements> 
         <!-- ${basedir} needed in classpath so that log4j can find the log4j.properties file --> 
         <additionalClasspathElement>${basedir}</additionalClasspathElement> 
        </additionalClasspathElements> 
       </configuration> 
       <dependencies> 
        <dependency> 
         <groupId>org.apache.maven.surefire</groupId> 
         <artifactId>surefire-junit47</artifactId> 
         <version>2.19.1</version> 
        </dependency> 
       </dependencies> 
      </plugin> 

      <!-- Specifying the maven-compiler-plugin allows us to set default JDK --> 
      <plugin> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.5.1</version> 
       <configuration> 
        <source>1.8</source> 
        <target>1.8</target> 
        <encoding>UTF-8</encoding> 
       </configuration> 
      </plugin> 
     </plugins> 
    </pluginManagement> 
</build> 

I最後のポイント。私はChromeDriver 2.25.426923を使用しています。

EDIT 2

私はあなたのランナーを修正。私はプラグインでフォーマットを置き換えました。

package runner; 

import cucumber.api.CucumberOptions; 
import cucumber.api.junit.Cucumber; 
import org.junit.runner.RunWith; 

@RunWith(Cucumber.class) 
@CucumberOptions(
    plugin = {"pretty", "html:target/cucumber"}, 
    glue = "steps", 
    features = "classpath:featurefiles/nieuwe_bevinding.feature" 
) 
public class RunInloggerTest { 
} 
+0

感謝。それは私の問題を解決しませんでした – Teefy

+0

意味がありません。 LoginPortal.javaのコード、特にライン14 – MikeJRamsey56

+0

パブリッククラスLoginPortal { \t \t \t \t公共webdriverをするinloggen(文字列Omgeving、文字ロル、列ブラウザ){ \t \t \t \tストリングInlogUrl = NULLを投稿してください。 \t \t \t \t \t \t WebDriver driver = AanroepDriver。roepdriver(ブラウザ); \t \t \t \t \t \t driver.manage()タイムアウト()implicitlyWait(10、TimeUnit.SECONDS)。 – Teefy

0

これが実際に問題を解決する場合は驚くでしょうが、試行は傷つかないでしょう。正規表現 'ワイルドカード': '。*'を使って試してみましたか?このよう

:返信用

@When("^I login with the parameters \"(.*)\" and \"(.*)\" and \"(.*)\"")