提供异常" java.lang.NullPointerException"同时执行两个测试用例

时间:2016-03-25 10:31:06

标签: java testng eclipse-mars

//这是我的XML代码...当我执行(InvalidLogin方法)"使用有效数据登录"测试套件它成功运行但是当我尝试在不同的测试套件中执行(InvalidLogin方法)代码时(ex.Login with Invalid Data)它会生成错误

 <suite name="Test Login" verbose="2" parallel="methods" thread-count="2">

<test name="Login with valid data" >
<parameter name="UserName" value="priyanka"></parameter>
<parameter name="Password" value="vrs~123"></parameter>

<!-- <parameter name="UserNam" value="Chetna12345"></parameter>
<parameter name="Passwor" value="Chetna12345"></parameter> -->


<classes>
<class name="Login_Test">
<methods>
    <include name="openBrowser"></include>
      <include name="SuccessfulLogin"></include>
       <!--  <include name="InvalidLogin"></include> -->

</methods>
</class>
</classes>
</test>
<test name="Login with Invalid Data">
<parameter name="UserNam" value="priyanka"></parameter>
<parameter name="Passwor" value="priyanka"></parameter>    

<groups>
<run>
<include name="TC02"></include>
</run>
</groups>
<classes>
<class name="Login_Test">
<methods>
      <include name="InvalidLogin"></include>
</methods>
</class>
</classes>

</test>
</suite>

//这是我成功登录的方法,我在登录后进行注销,因此浏览器上的URL仍然打开,但无效的值不会传递到文本框......

public void SuccessfulLogin(String userName, String passWord) {

    try {

        driver.findElement(By.id("UserName")).sendKeys(userName);
        driver.findElement(By.id("Password")).sendKeys(passWord);

        driver.findElement(By.id("btnLogin")).submit();

//退出代码

  driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
            driver.findElement(By.className("dropdown-toggle")).click();

            driver.findElement(By.xpath("//a[contains(@href,    'Account/LogOff')]")).click();


    } catch (Exception ex) {

    }
}
public void InvalidLogin(String Uname,String Pword)
    {   
        driver.findElement(By.id("UserName")).sendKeys(Uname);
        driver.findElement(By.id("Password")).sendKeys(Pword);

        driver.findElement(By.id("btnLogin")).submit();
    }

//输入控制台

Login success!!
PASSED: openBrowser
PASSED: SuccessfulLogin("priyanka", "vrs~123")

===============================================
    Login with valid data
    Tests run: 2, Failures: 0, Skips: 0
===============================================

[TestRunner] Starting executor for test Login with Invalid Data with time out:2147483647 milliseconds.
FAILED: InvalidLogin("priyanka", "priyanka")
java.lang.NullPointerException

1 个答案:

答案 0 :(得分:0)

根据XML,我想你需要将<include name="openBrowser"></include>添加到第二个测试