Skip to content

Commit

Permalink
#593: if description is null, set it as empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
bhecquet committed Feb 8, 2024
1 parent dca17f0 commit 55e40f6
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public Integer createTestCaseInSession(Integer sessionId, Integer testCaseId, St
.field(FIELD_STATUS, status)
.field("gridNode", gridNode)
.field(FIELD_NAME, strippedName)
.field("description", description));
.field("description", description == null ? "": description));
return testInSessionJson.getInt("id");
} catch (UnirestException | JSONException | SeleniumRobotServerException e) {
throw new SeleniumRobotServerException("cannot create test case", e);
Expand Down Expand Up @@ -554,7 +554,7 @@ public void recordTestInfo(Map<String, Info> infos, Integer testCaseInSessionId)
try {
getStringResponse(buildPostRequest(url + TESTINFO_API_URL)
.field(FIELD_TEST_CASE, testCaseInSessionId.toString())
.field("infoKey", info.getKey())
.field("name", info.getKey())
.field("info", info.getValue().toJson().toString()));
} catch (UnirestException | JSONException | SeleniumRobotServerException e) {
logger.error("cannot create test info", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,16 @@
import java.io.IOException;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.seleniumtests.core.TestStepManager;
import com.seleniumtests.reporter.info.ImageLinkInfo;
import com.seleniumtests.reporter.info.Info;
import com.seleniumtests.reporter.info.MultipleInfo;
import com.seleniumtests.reporter.info.StringInfo;
import com.seleniumtests.reporter.logger.FileContent;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.Rectangle;
import org.testng.Assert;
Expand Down Expand Up @@ -51,7 +59,7 @@ public void init(ITestContext ctx) {
initThreadContext(ctx);

// pass the token via -DseleniumRobotServerToken=xxxxxx
connector = new SeleniumRobotSnapshotServerConnector(true, "http://localhost:8002", SeleniumTestsContextManager.getThreadContext().seleniumServer().getSeleniumRobotServerToken());
connector = new SeleniumRobotSnapshotServerConnector(true, "http://localhost:8000", SeleniumTestsContextManager.getThreadContext().seleniumServer().getSeleniumRobotServerToken());
if (!connector.getActive()) {
throw new SkipException("no seleniumrobot server available");
}
Expand Down Expand Up @@ -107,6 +115,22 @@ public void testCreateTestCaseInSession() {
Assert.assertNotNull(testCaseInSessionId);
Assert.assertNotNull(connector.getApplicationId());
}

@Test(groups={"it"})
public void testSendTestInfos() {
Integer sessionId = connector.createSession("Session1");
Integer testCaseId = connector.createTestCase("Test 1");
Integer testCaseInSessionId = connector.createTestCaseInSession(sessionId, testCaseId, "Test 1", "SUCCESS", "LOCAL", null);

Map<String, Info> infos = new HashMap<>();
MultipleInfo mInfo = new MultipleInfo(TestStepManager.LAST_STATE_NAME);
File imageFile = Paths.get(SeleniumTestsContextManager.getThreadContext().getOutputDirectory(), "image", "imageCapture.png").toFile();
mInfo.addInfo(new ImageLinkInfo(new FileContent(imageFile)));
infos.put(TestStepManager.LAST_STATE_NAME, mInfo);
infos.put("Issue", new StringInfo("ID=12"));

connector.recordTestInfo(infos, testCaseInSessionId);
}

/**
* create a test step and check it's added to test case
Expand Down Expand Up @@ -249,6 +273,7 @@ public void testGetStepReferenceDetectFieldInformation() throws IOException {
Assert.assertNull(detectionData.get("error"));

}




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ public void testReportGenerationServerInactive() throws Exception {
}
}

/**
* When creation of test steps fails, logs and test infos are not sent
* @throws Exception
*/
@Test(groups={"it"})
public void testReportGenerationErrorCreatingTestStep() throws Exception {

Expand Down Expand Up @@ -204,6 +208,43 @@ public void testReportGenerationErrorCreatingTestStep() throws Exception {
System.clearProperty(SeleniumRobotServerContext.SELENIUMROBOTSERVER_RECORD_RESULTS);
}
}

/**
* When creation of test case fails, steps, logs and test infos are not sent
* @throws Exception
*/
@Test(groups={"it"})
public void testReportGenerationErrorCreatingTestCase() throws Exception {

try {
System.setProperty(SeleniumRobotServerContext.SELENIUMROBOTSERVER_ACTIVE, "true");
System.setProperty(SeleniumRobotServerContext.SELENIUMROBOTSERVER_COMPARE_SNAPSHOT, "true");
System.setProperty(SeleniumRobotServerContext.SELENIUMROBOTSERVER_RECORD_RESULTS, "true");
System.setProperty(SeleniumRobotServerContext.SELENIUMROBOTSERVER_URL, "http://localhost:1234");

initMocks();
doThrow(SeleniumRobotServerException.class).when(serverConnector).createTestCase(anyString());
executeSubTest(1, new String[] {"com.seleniumtests.it.stubclasses.StubTestClass"}, ParallelMode.METHODS, new String[] {"testAndSubActions"});

String logs = readSeleniumRobotLogFile();
Assert.assertTrue(logs.contains("Error recording result on selenium robot server")); // one snapshot has no name, error message is displayed

// check steps are NOT sent
verify(serverConnector, never()).createTestStep(anyString(), anyInt());

// check logs has NOT been uploaded
verify(serverConnector, never()).uploadLogs(any(File.class), eq(0));

// check test infos has NOT been sent
verify(serverConnector, never()).recordTestInfo(any(), eq(0));

} finally {
System.clearProperty(SeleniumRobotServerContext.SELENIUMROBOTSERVER_ACTIVE);
System.clearProperty(SeleniumRobotServerContext.SELENIUMROBOTSERVER_URL);
System.clearProperty(SeleniumRobotServerContext.SELENIUMROBOTSERVER_COMPARE_SNAPSHOT);
System.clearProperty(SeleniumRobotServerContext.SELENIUMROBOTSERVER_RECORD_RESULTS);
}
}

/**
* Test that focuses on snapshots: it's sent to server, exclusion zones are also sent
Expand Down

0 comments on commit 55e40f6

Please sign in to comment.