0

// This is my XML code... when i execute (InvalidLogin method) in "Login with valid data" test suite it works successfully but when i try to execute (InvalidLogin method)code in different test suite (ex.Login with Invalid Data) it generates error

 <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>

//This is My method for Successful login and i am doing Logout after login so URL on browser remains open but values for invalid are not getting passed on to Text box...

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();

//Logout Code

  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();
    }

//Out put in Console

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
Sumit
  • 33
  • 6
  • Your second `Login_Test` doesn't include `openBrowser`. – Elliott Frisch Mar 25 '16 at 10:34
  • hello @ElliottFrisch i have updated my code in which i am doing logout after my first test case execution so, when execution starts for "Invalid Login" Login page remains open in browser so, it directly starts to pass invalid data into it.. – Sumit Mar 25 '16 at 10:54
  • Can you create a [Minimal, Computer, and Verifiable example](http://stackoverflow.com/help/mcve)? It should help us help you. – mfulton26 Mar 25 '16 at 11:20

1 Answers1

0

According to XML I suppose you need to add <include name="openBrowser"></include> to the second test

RocketRaccoon
  • 2,559
  • 1
  • 21
  • 30