0

Error:

Starting ChromeDriver 2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f) on port 8745
Only local connections are allowed.
Feb 01, 2018 1:09:16 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
java.lang.NullPointerException
    at utils.Reporter.reportStep(Reporter.java:29)
    at pages.Login.Loginapplcn(Login.java:18)
    at testcases.TestCase01.TC01(TestCase01.java:37)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)

Code:

    public void reportStep(String desc, String status) {

    long snapNumber = 100000l;
    
    try {
        snapNumber= takeSnap();
    } catch (Exception e) {
        e.printStackTrace();
    }
    
    // Write if it is successful or failure or information
    if(status.toUpperCase().equals("PASS")){
        test.log(LogStatus.PASS, desc+test.
                addScreenCapture("C:\\Users\\wb469604\\Anu\\Selenium_Handson\\CFA_Automation_New\\screenshot"+snapNumber+".jpg")); --------------> error in this step
    }else if(status.toUpperCase().equals("FAIL")){
        test.log(LogStatus.FAIL, desc+test.addScreenCapture("C:\\Users\\wb469604\\Anu\\Selenium_Handson\\CFA_Automation_New\\screenshot"+snapNumber+".jpg"));
        throw new RuntimeException("FAILED");
    }else if(status.toUpperCase().equals("INFO")){
        test.log(LogStatus.INFO, desc);
    }else if(status.toUpperCase().equals("WARN")){
        test.log(LogStatus.WARNING, desc+test.addScreenCapture("./../reports/images/"+snapNumber+".jpg"));
    }
}

Code of the page:

 public Login Loginapplcn(String Uname)
  {
        
            try {
                driver.findElement(By.name("userId")).sendKeys(Uname);
                reportStep("The element : "+Uname+" is passed "+Uname, "PASS"); --->error
                            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                reportStep("WebDriverException"+e.getMessage(), "FAIL");
            }
                                    
        return this;
4
  • In reportStep method, see this line reportStep(Reporter.java:29). Can you please share what code of line is there ?
    – Sagar007
    Feb 1, 2018 at 8:11
  • test.log(LogStatus.PASS, desc+test. addScreenCapture("C:\\Users\\wb469604\\Anu\\Selenium_Handson\\CFA_Automation_New\\screenshot"+snapNumber+".jpg"));
    – user30653
    Feb 1, 2018 at 9:03
  • As per my understanding, desc is passing null in method. Check Loginapplcn() method Uname value is null. Or your screenshot is not capture in test.addScreenCapture() method
    – Sagar007
    Feb 1, 2018 at 9:54
  • Please do not vandalize your posts. If you believe your question is not useful or is no longer useful, it should be deleted instead of editing out all of the data that actually makes it a question. By posting on the Stack Exchange network, you've granted a non-revocable right for SE to distribute that content under the CC BY-SA 4.0 license. By SE policy, any vandalism will be reverted. If you want to know more about deleting a post, consider taking a look at: How does deleting work?
    – Glorfindel
    May 19 at 11:07

1 Answer 1

1

Missed to pass extenttest in the constructor. update it and code worked.

public Login(WebDriver driver, ExtentTest test){
        Login.driver = driver;
        this.test=test;
    }