Skip to content

Commit

Permalink
#593: correct UT
Browse files Browse the repository at this point in the history
  • Loading branch information
bhecquet committed Sep 12, 2023
1 parent 1b51a66 commit 2e7512c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public GenericFile(File file, String description, boolean move) throws IOExcepti
relativeFilePath = file.getName(); // correct relavtive path, as we moved the file

try {
loggedFile.mkdirs();
Files.move(file.toPath(), loggedFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
this.file = new FileContent(loggedFile);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ public HarCapture(Har har, String name, FileContent harFile) {
public HarCapture(Har har, String name) throws IOException {
super(name, false, new ArrayList<>());
this.har = har;
harFile = new FileContent(Paths.get(SeleniumTestsContextManager.getThreadContext().getOutputDirectory(), name + "-" + HAR_FILE_NAME).toFile());
File f = Paths.get(SeleniumTestsContextManager.getThreadContext().getOutputDirectory(), name + "-" + HAR_FILE_NAME).toFile();
f.getParentFile().mkdirs();
harFile = new FileContent(f);

har.writeTo(harFile.getFile());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void testRelocateScreenshotHtmlOnly() throws IOException {

// relocate
TestStepManager.getParentTestStep().getSnapshots().get(0).relocate(SeleniumTestsContextManager.getThreadContext().getOutputDirectory() + "_moved");
File movedFile = Paths.get(SeleniumTestsContextManager.getThreadContext().getOutputDirectory() + "_moved", ScreenshotUtil.HTML_DIR, "N-A_0-1_step--pture.html").toFile();
File movedFile = Paths.get(SeleniumTestsContextManager.getThreadContext().getOutputDirectory() + "_moved", ScreenshotUtil.HTML_DIR, initialFile.getName()).toFile();

Assert.assertTrue(movedFile.exists());
Assert.assertFalse(initialFile.exists());
Expand All @@ -139,11 +139,11 @@ public void testRelocateScreenshotImageOnly() throws IOException {
logger.logScreenshot(screenshot);
File initialFile = TestStepManager.getParentTestStep().getSnapshots().get(0).getScreenshot().getImage().getFile();
Assert.assertTrue(initialFile.exists()); // file exists before moving
Assert.assertEquals(FileUtils.readFileToString(TestStepManager.getParentTestStep().getSnapshots().get(0).getScreenshot().getHtml().getFile(), StandardCharsets.UTF_8), "");
Assert.assertEquals(FileUtils.readFileToString(TestStepManager.getParentTestStep().getSnapshots().get(0).getScreenshot().getImage().getFile(), StandardCharsets.UTF_8), "");

// relocate
TestStepManager.getParentTestStep().getSnapshots().get(0).relocate(SeleniumTestsContextManager.getThreadContext().getOutputDirectory() + "_moved");
File movedFile = Paths.get(SeleniumTestsContextManager.getThreadContext().getOutputDirectory() + "_moved", ScreenshotUtil.SCREENSHOT_DIR, "N-A_0-1_step--apture.png").toFile();
File movedFile = Paths.get(SeleniumTestsContextManager.getThreadContext().getOutputDirectory() + "_moved", ScreenshotUtil.SCREENSHOT_DIR, initialFile.getName()).toFile();

Assert.assertTrue(movedFile.exists());
Assert.assertFalse(initialFile.exists());
Expand All @@ -165,7 +165,7 @@ public void testRelocateScreenshotSamePath() throws IOException {
logger.logScreenshot(screenshot);
File initialFile = TestStepManager.getParentTestStep().getSnapshots().get(0).getScreenshot().getImage().getFile();
Assert.assertTrue(initialFile.exists()); // file exists before moving
Assert.assertEquals(FileUtils.readFileToString(TestStepManager.getParentTestStep().getSnapshots().get(0).getScreenshot().getHtml().getFile(), StandardCharsets.UTF_8), "");
Assert.assertEquals(FileUtils.readFileToString(TestStepManager.getParentTestStep().getSnapshots().get(0).getScreenshot().getImage().getFile(), StandardCharsets.UTF_8), "");

// check no error is raised if we ask the files to be moved at the same place
TestStepManager.getParentTestStep().getSnapshots().get(0).relocate(SeleniumTestsContextManager.getThreadContext().getOutputDirectory());
Expand Down

0 comments on commit 2e7512c

Please sign in to comment.