Join 34,000+ subscribers and receive articles from our
blog about software quality, testing, QA and security.

Status update failed for add_result_for_case


#1

Good morning, i’m new subscriber and need your help
This is my code:

import org.json.simple.JSONObject;
import org.junit.*;

import java.io.IOException;
import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;

import com.gurock.testrail.APIClient;
import com.gurock.testrail.APIException;

public class Login {
public WebDriver driver;

String usuario1 = “…”;

private APIClient client1;

Before
public void setUp() {
System.setProperty(“webdriver.chrome.driver”, “C://Selenium/chromedriver.exe”);
driver = new ChromeDriver();
driver.manage().window().maximize();
String URL = “http://urbania.pe”;
driver.get(URL);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

}

Test
public void testLogin() throws APIException, MalformedURLException, IOException{
client1 = null;
loginTestrail(client1);

driver.findElement(By.id("lnkLogin")).click();
System.out.println("Entro al login");
driver.findElement(By.id("email")).clear();
System.out.println("Limpio email");
driver.findElement(By.id("email")).sendKeys("...");
System.out.println("Ingreso email");
driver.findElement(By.id("clave")).clear();
System.out.println("Limpio password");
driver.findElement(By.id("clave")).sendKeys("...");
System.out.println("Ingreso password");
driver.findElement(By.name("btnLogin")).click();
System.out.println("Dio click a loguear");
System.out.println("Se logeo");

Map<String,Integer> data = new HashMap<String, Integer>();
String nombreUsuario = driver.findElement(By.className("e-name-user")).getText();

Boolean coincide = nombreUsuario.equals(usuario1);
System.out.println(coincide);
if(coincide) {
	data.put("status_id", new Integer(1));
	System.out.println("PASSED");
	
}else {
	data.put("status_id", new Integer(2));
	System.out.println("FAILED");    	    	
}

JSONObject r = (JSONObject) client1.sendPost(“add_result_for_case/1/10”, data);

}

@After
public void tearDown() {
driver.close();
driver.quit();

}

public void loginTestrail(APIClient client1) {
APIClient client = new APIClient("…");
client.setUser("…");
client.setPassword("…");
}
}

I can not update the status of the test case in Testrail

Error:
image

java.lang.NullPointerException
at LoginPre3b.testLoginPre3b(LoginPre3b.java:80)
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)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:539)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:761)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:461)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:207)

Thank you!