Skip to content

Commit

Permalink
#593: correct UT & grid compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
bhecquet committed Sep 13, 2023
1 parent 1d66f6e commit 65c3241
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package com.seleniumtests.util.logging;

import com.seleniumtests.core.SeleniumTestsContextManager;
import com.seleniumtests.util.helper.WaitHelper;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.FileFilterUtils;
Expand Down Expand Up @@ -74,8 +73,6 @@ private SeleniumRobotLogger() {
}

public static void createLoggerForTest(String outputDir, String loggerName) {



LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Configuration config = ctx.getConfiguration();
Expand All @@ -84,8 +81,10 @@ public static void createLoggerForTest(String outputDir, String loggerName) {
if (loggerNames.get() != null) {
String previousName = loggerNames.get();
Appender appender = ((BuiltConfiguration) config).getLogger(previousName).getAppenders().get(FILE_APPENDER_NAME + "-" + previousName);
appender.stop();
((BuiltConfiguration) config).getLogger(previousName).removeAppender(FILE_APPENDER_NAME + "-" + previousName);
if (appender != null) {
appender.stop();
((BuiltConfiguration) config).getLogger(previousName).removeAppender(FILE_APPENDER_NAME + "-" + previousName);
}
}

LoggerConfig loggerConfig = new LoggerConfig(loggerName, level, false);
Expand Down Expand Up @@ -292,7 +291,7 @@ public static void cleanTestLogs() {
}
}

for (File file: FileUtils.listFiles(new File(SeleniumTestsContextManager.getGlobalContext().getDefaultOutputDirectory()),
for (File file: FileUtils.listFiles(new File(defaultOutputDirectory),
FileFilterUtils.nameFileFilter("execution.log"),
TrueFileFilter.INSTANCE )) {
file.delete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@

import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

import com.seleniumtests.core.SeleniumTestsContextManager;
import com.seleniumtests.reporter.logger.TestStep;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
Expand Down Expand Up @@ -115,6 +117,15 @@ public void testReportGeneration() throws Exception {
Assert.assertTrue(logs.contains("Snapshot hasn't any name, it won't be sent to server")); // one snapshot has no name, error message is displayed

verify(serverConnector, times(30)).recordStepResult(any(TestStep.class), anyInt(), anyInt(), anyInt()); // all steps are recorded
// files are uploaded. Only 'testWithException' holds a Snapshot with snapshotCheckType.NONE and so, only its 2 files are uploaded
// other snapshots, which are used for image comparison / regression are uploaded through an other service 'createSnapshot'
verify(serverConnector).uploadFile(eq(Paths.get(SeleniumTestsContextManager.getGlobalContext().getOutputDirectory(), "testWithException", "htmls", "testWithException_0-1_step_1--tened.html").toFile()), anyInt());
verify(serverConnector).uploadFile(eq(Paths.get(SeleniumTestsContextManager.getGlobalContext().getOutputDirectory(), "testWithException", "screenshots", "testWithException_0-1_step_1--rtened.png").toFile()), anyInt());
// check image id and html id has been updated once files has been uploaded, for tests where snapshots has been uploaded
verify(serverConnector).updateStepResult(contains("\"snapshots\":[{\"idHtml\":0,\"displayInReport\":true,\"name\":\"testWithException_0-1_step_1--rtened.png\",\"idImage\":0,\"failed\":false,\"position\":0,\"type\":\"snapshot\",\"snapshotCheckType\":\"NONE\""), eq(0));
verify(serverConnector).updateStepResult(contains("\"snapshots\":[{\"idHtml\":null,\"displayInReport\":true,\"name\":\"testAndSubActions_0-1_step_1--rtened.png\""), eq(0));


} finally {
System.clearProperty(SeleniumRobotServerContext.SELENIUMROBOTSERVER_ACTIVE);
System.clearProperty(SeleniumRobotServerContext.SELENIUMROBOTSERVER_URL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,12 @@ public void testAndSubActions() throws IOException {

File tmpImg = File.createTempFile("img", "_with_very_very_very_long_name_to_be_shortened.png");
File tmpHtml = File.createTempFile("html", "_with_very_very_very_long_name_to_be_shortened.html");

ScreenShot screenshot = new ScreenShot(tmpImg, tmpHtml);
step1.addSnapshot(new Snapshot(screenshot, "main", SnapshotCheckType.FULL), 1, null);

ScreenShot screenshot2 = new ScreenShot(tmpImg, tmpHtml);
File tmpImg2 = File.createTempFile("img", "_with_very_very_very_long_name_to_be_shortened.png");
File tmpHtml2 = File.createTempFile("html", "_with_very_very_very_long_name_to_be_shortened.html");
ScreenShot screenshot2 = new ScreenShot(tmpImg2, tmpHtml2);
step1.addSnapshot(new Snapshot(screenshot2, null, SnapshotCheckType.FULL), 1, null);

step1.setActionException(new WebDriverException("driver exception"));
Expand Down Expand Up @@ -144,9 +145,16 @@ public void testSkipped() {
}

@Test(groups="stub")
public void testWithException() {
public void testWithException() throws IOException {
count++;
TestStep step1 = new TestStep("step 1", Reporter.getCurrentTestResult(), new ArrayList<>(), maskPassword);

File tmpImg2 = File.createTempFile("img", "_with_very_very_very_long_name_to_be_shortened.png");
File tmpHtml2 = File.createTempFile("html", "_with_very_very_very_long_name_to_be_shortened.html");
ScreenShot screenshot2 = new ScreenShot(tmpImg2, tmpHtml2);
step1.addSnapshot(new Snapshot(screenshot2, null, SnapshotCheckType.NONE), 1, null);


step1.addAction(new TestAction(String.format("played %d times", count), false, new ArrayList<>()));
step1.addAction(new TestAction("click button", false, new ArrayList<>()));
TestStepManager.logTestStep(step1);
Expand Down

0 comments on commit 65c3241

Please sign in to comment.