Search in sources :

Example 1 with GenericFile

use of com.seleniumtests.reporter.logger.GenericFile in project seleniumRobot by bhecquet.

the class TestGenericFile method testFileMovedOnCreation.

@Test(groups = { "ut" })
public void testFileMovedOnCreation() throws IOException {
    File videoFile = File.createTempFile("video", ".avi");
    videoFile.deleteOnExit();
    GenericFile genericFile = new GenericFile(videoFile, "description");
    Assert.assertEquals(genericFile.getFile(), Paths.get(SeleniumTestsContextManager.getThreadContext().getOutputDirectory(), videoFile.getName()).toFile());
}
Also used : File(java.io.File) GenericFile(com.seleniumtests.reporter.logger.GenericFile) GenericFile(com.seleniumtests.reporter.logger.GenericFile) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 2 with GenericFile

use of com.seleniumtests.reporter.logger.GenericFile in project seleniumRobot by bhecquet.

the class TestGenericFile method testFileReplaceOnCreation.

@Test(groups = { "ut" })
public void testFileReplaceOnCreation() throws IOException {
    File videoFile = File.createTempFile("video", ".avi");
    videoFile.deleteOnExit();
    FileUtils.write(videoFile, "bar", StandardCharsets.UTF_8);
    // put a file in the destination
    File dest = Paths.get(SeleniumTestsContextManager.getThreadContext().getOutputDirectory(), videoFile.getName()).toFile();
    FileUtils.write(dest, "foo", StandardCharsets.UTF_8);
    GenericFile genericFile = new GenericFile(videoFile, "description");
    Assert.assertEquals(genericFile.getFile(), dest);
    // check file has been replaced
    Assert.assertEquals(FileUtils.readFileToString(dest, StandardCharsets.UTF_8), "bar");
}
Also used : File(java.io.File) GenericFile(com.seleniumtests.reporter.logger.GenericFile) GenericFile(com.seleniumtests.reporter.logger.GenericFile) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 3 with GenericFile

use of com.seleniumtests.reporter.logger.GenericFile in project seleniumRobot by bhecquet.

the class TestGenericFile method testFileReplaceOnRelocate.

/**
 * Check relocate can replace file on move
 * @throws IOException
 */
@Test(groups = { "ut" })
public void testFileReplaceOnRelocate() throws IOException {
    File videoFile = File.createTempFile("video", ".avi");
    videoFile.deleteOnExit();
    FileUtils.write(videoFile, "bar", StandardCharsets.UTF_8);
    GenericFile genericFile = new GenericFile(videoFile, "description");
    File outputDir = Paths.get(SeleniumTestsContextManager.getThreadContext().getOutputDirectory(), "dest").toFile();
    File dest = Paths.get(outputDir.getAbsolutePath(), videoFile.getName()).toFile();
    FileUtils.write(dest, "foo", StandardCharsets.UTF_8);
    File previousLocation = genericFile.getFile();
    Assert.assertTrue(previousLocation.exists());
    genericFile.relocate(outputDir.getAbsolutePath());
    Assert.assertEquals(genericFile.getFile(), dest);
    Assert.assertTrue(genericFile.getFile().exists());
    // check file has been replaced
    Assert.assertEquals(FileUtils.readFileToString(dest, StandardCharsets.UTF_8), "bar");
}
Also used : File(java.io.File) GenericFile(com.seleniumtests.reporter.logger.GenericFile) GenericFile(com.seleniumtests.reporter.logger.GenericFile) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 4 with GenericFile

use of com.seleniumtests.reporter.logger.GenericFile in project seleniumRobot by bhecquet.

the class TestGenericFile method testFileNoReplaceOnCreation.

/**
 * Test case when file cannot be moved
 * @throws IOException
 */
@Test(groups = { "ut" })
public void testFileNoReplaceOnCreation() throws IOException {
    File videoFile = File.createTempFile("video", ".avi");
    videoFile.deleteOnExit();
    FileUtils.write(videoFile, "bar", StandardCharsets.UTF_8);
    // put a file in the destination
    File dest = Paths.get(SeleniumTestsContextManager.getThreadContext().getOutputDirectory(), videoFile.getName()).toFile();
    FileUtils.write(dest, "foo", StandardCharsets.UTF_8);
    try (InputStreamReader reader = new InputStreamReader(new FileInputStream(dest), StandardCharsets.UTF_8)) {
        GenericFile genericFile = new GenericFile(videoFile, "description");
        // file field has been updated with the source value as file has not been copied
        Assert.assertEquals(genericFile.getFile(), videoFile);
    }
    // check file has not been replaced
    Assert.assertEquals(FileUtils.readFileToString(dest, StandardCharsets.UTF_8), "foo");
}
Also used : InputStreamReader(java.io.InputStreamReader) File(java.io.File) GenericFile(com.seleniumtests.reporter.logger.GenericFile) FileInputStream(java.io.FileInputStream) GenericFile(com.seleniumtests.reporter.logger.GenericFile) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 5 with GenericFile

use of com.seleniumtests.reporter.logger.GenericFile in project seleniumRobot by bhecquet.

the class TestGenericFile method testRelocate.

@Test(groups = { "ut" })
public void testRelocate() throws IOException {
    File videoFile = File.createTempFile("video", ".avi");
    videoFile.deleteOnExit();
    GenericFile genericFile = new GenericFile(videoFile, "description");
    File outputDir = Paths.get(SeleniumTestsContextManager.getThreadContext().getOutputDirectory(), "dest").toFile();
    File previousLocation = genericFile.getFile();
    Assert.assertTrue(previousLocation.exists());
    genericFile.relocate(outputDir.getAbsolutePath());
    Assert.assertEquals(genericFile.getFile(), Paths.get(SeleniumTestsContextManager.getThreadContext().getOutputDirectory(), "dest", videoFile.getName()).toFile());
    Assert.assertTrue(genericFile.getFile().exists());
}
Also used : File(java.io.File) GenericFile(com.seleniumtests.reporter.logger.GenericFile) GenericFile(com.seleniumtests.reporter.logger.GenericFile) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Aggregations

GenericFile (com.seleniumtests.reporter.logger.GenericFile)12 GenericTest (com.seleniumtests.GenericTest)11 Test (org.testng.annotations.Test)11 File (java.io.File)7 TestStep (com.seleniumtests.reporter.logger.TestStep)5 HarCapture (com.seleniumtests.reporter.logger.HarCapture)2 TestAction (com.seleniumtests.reporter.logger.TestAction)2 TestMessage (com.seleniumtests.reporter.logger.TestMessage)2 FileInputStream (java.io.FileInputStream)2 InputStreamReader (java.io.InputStreamReader)2 ArrayList (java.util.ArrayList)2 Har (net.lightbody.bmp.core.har.Har)2 HarLog (net.lightbody.bmp.core.har.HarLog)2 HarPage (net.lightbody.bmp.core.har.HarPage)2 JSONObject (org.json.JSONObject)1