Skip to content

Commit

Permalink
[#198] improve junit4 tests and add tests for junit5
Browse files Browse the repository at this point in the history
  • Loading branch information
oomelianchuk committed Sep 11, 2024
1 parent 2853495 commit 675ed73
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.xceptance.neodymium.junit4.testclasses.webDriver;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

import org.junit.After;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.runner.RunWith;

import com.codeborne.selenide.Selenide;
Expand All @@ -18,31 +20,39 @@
@Browser("Chrome_with_args")
public class DriverArgumentsConfigTest
{
private File chromeLogFile = new File(DriverArgumentsTest.logFileNameChrome);

private File firefoxLogFile = new File(DriverArgumentsTest.logFileNameFirefox);

@Test
public void test()
public void test() throws IOException
{
Selenide.open("https://www.xceptance.com/en/");
System.out.println(Neodymium.getBrowserName());
if (Neodymium.getBrowserName().equals("chrome"))
{
Assert.assertTrue("No log file found for chrome", new File(DriverArgumentsTest.logFileNameChrome).exists());
Assertions.assertTrue(chromeLogFile.exists(), "No log file found for chrome");
Assertions.assertTrue(Files.readString(chromeLogFile.toPath()).contains(DriverArgumentsTest.chromePort), "No log file found for chrome");
}
else
{
Assert.assertTrue("No log file found for firefox", new File(DriverArgumentsTest.logFileNameFirefox).exists());
Assertions.assertTrue(new File(DriverArgumentsTest.logFileNameFirefox).exists(), "No log file found for firefox");
Assertions.assertTrue(Files.readString(firefoxLogFile.toPath()).contains(DriverArgumentsTest.firefoxPort), "Port not found in firefox log");
Assertions.assertTrue(Files.readString(firefoxLogFile.toPath()).contains(DriverArgumentsTest.firefoxWebsocketPort),
"Websocket port not found in firefox log");
}
}

@After
public void cleanup()
{
if (Neodymium.getBrowserName().contains("Chrome"))
if (chromeLogFile.exists())
{
new File(DriverArgumentsTest.logFileNameChrome).delete();
chromeLogFile.delete();
}
else

if (firefoxLogFile.exists())
{
new File(DriverArgumentsTest.logFileNameFirefox).delete();
firefoxLogFile.delete();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@

public class DriverArgumentsTest extends NeodymiumTest
{
public static String logFileNameChrome = "target/" + UUID.randomUUID().toString() + "chrome.log";
public static String logFileNameChrome = "target/" + UUID.randomUUID().toString() + "_chrome.log";

public static String logFileNameFirefox = "target/" + UUID.randomUUID().toString() + "firefox.log";
public static String logFileNameFirefox = "target/" + UUID.randomUUID().toString() + "_firefox.log";

public static String chromePort = "7100";

public static String firefoxPort = "8525";

public static String firefoxWebsocketPort = "8785";

@BeforeClass
public static void createSettings()
Expand All @@ -28,15 +34,17 @@ public static void createSettings()
properties3.put("browserprofile.FF_with_args.browserResolution", "1024x768");
properties3.put("browserprofile.FF_with_args.browser", "firefox");
properties3.put("browserprofile.FF_with_args.driverArgs",
"--log ; info ;--allow-hosts; xceptance.com; google.com; --port=8525; --log-no-truncate ; --websocket-port=8785; --allow-origins; http://xceptance.com:8785 ; --log-path="
"--log ; info ;--allow-hosts; xceptance.com; google.com; --port=" + firefoxPort
+ "; --log-no-truncate ; --websocket-port=" + firefoxWebsocketPort
+ "; --allow-origins; http://xceptance.com:8785 ; --log-path="
+ logFileNameFirefox);

properties3.put("browserprofile.Chrome_with_args.name", "Chrome with args");
properties3.put("browserprofile.Chrome_with_args.headless", "true");
properties3.put("browserprofile.Chrome_with_args.browserResolution", "1024x768");
properties3.put("browserprofile.Chrome_with_args.browser", "chrome");
properties3.put("browserprofile.Chrome_with_args.driverArgs",
"--port=7100 ; --allowed-origins=localhost, xceptance.com; --log-level=INFO ; --log-path=" + logFileNameChrome);
"--port=" + chromePort + "; --allowed-origins=localhost, xceptance.com; --log-level=INFO ; --log-path=" + logFileNameChrome);
File tempConfigFile3 = new File("./config/dev-browser.properties");
writeMapToPropertiesFile(properties3, tempConfigFile3);
tempFiles.add(tempConfigFile3);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.xceptance.neodymium.junit5.testclasses.webDriver;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;

import com.codeborne.selenide.Selenide;
import com.xceptance.neodymium.common.browser.Browser;
import com.xceptance.neodymium.junit5.NeodymiumTest;
import com.xceptance.neodymium.junit5.tests.DriverArgumentsTest;
import com.xceptance.neodymium.util.Neodymium;

@Browser("FF_with_args")
@Browser("Chrome_with_args")
public class DriverArgumentsConfigTest
{
private File chromeLogFile = new File(DriverArgumentsTest.logFileNameChrome);

private File firefoxLogFile = new File(DriverArgumentsTest.logFileNameFirefox);

@NeodymiumTest
public void test() throws IOException
{
Selenide.open("https://www.xceptance.com/en/");
if (Neodymium.getBrowserName().equals("chrome"))
{
Assertions.assertTrue(chromeLogFile.exists(), "No log file found for chrome");
Assertions.assertTrue(Files.readString(chromeLogFile.toPath()).contains(DriverArgumentsTest.chromePort), "No log file found for chrome");
}
else
{
Assertions.assertTrue(new File(DriverArgumentsTest.logFileNameFirefox).exists(), "No log file found for firefox");
Assertions.assertTrue(Files.readString(firefoxLogFile.toPath()).contains(DriverArgumentsTest.firefoxPort), "Port not found in firefox log");
Assertions.assertTrue(Files.readString(firefoxLogFile.toPath()).contains(DriverArgumentsTest.firefoxWebsocketPort),
"Websocket port not found in firefox log");
}
}

@AfterEach
public void cleanup()
{
if (chromeLogFile.exists())
{
chromeLogFile.delete();
}

if (firefoxLogFile.exists())
{
firefoxLogFile.delete();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.xceptance.neodymium.junit5.tests;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import com.xceptance.neodymium.junit5.testclasses.webDriver.DriverArgumentsConfigTest;
import com.xceptance.neodymium.junit5.tests.utils.NeodymiumTestExecutionSummary;

public class DriverArgumentsTest extends AbstractNeodymiumTest
{
public static String logFileNameChrome = "target/" + UUID.randomUUID().toString() + "_chrome.log";

public static String logFileNameFirefox = "target/" + UUID.randomUUID().toString() + "_firefox.log";

public static String chromePort = "7100";

public static String firefoxPort = "8525";

public static String firefoxWebsocketPort = "8785";

@BeforeAll
public static void createSettings()
{
Map<String, String> properties3 = new HashMap<>();

properties3.put("browserprofile.FF_with_args.name", "FF with args");
properties3.put("browserprofile.FF_with_args.headless", "true");
properties3.put("browserprofile.FF_with_args.browserResolution", "1024x768");
properties3.put("browserprofile.FF_with_args.browser", "firefox");
properties3.put("browserprofile.FF_with_args.driverArgs",
"--log ; info ;--allow-hosts; xceptance.com; google.com; --port=" + firefoxPort
+ "; --log-no-truncate ; --websocket-port=" + firefoxWebsocketPort
+ "; --allow-origins; http://xceptance.com:8785 ; --log-path="
+ logFileNameFirefox);

properties3.put("browserprofile.Chrome_with_args.name", "Chrome with args");
properties3.put("browserprofile.Chrome_with_args.headless", "true");
properties3.put("browserprofile.Chrome_with_args.browserResolution", "1024x768");
properties3.put("browserprofile.Chrome_with_args.browser", "chrome");
properties3.put("browserprofile.Chrome_with_args.driverArgs",
"--port=" + chromePort + "; --allowed-origins=localhost, xceptance.com; --log-level=INFO ; --log-path=" + logFileNameChrome);
File tempConfigFile3 = new File("./config/dev-browser.properties");
writeMapToPropertiesFile(properties3, tempConfigFile3);
tempFiles.add(tempConfigFile3);
}

@Test
public void test()
{
NeodymiumTestExecutionSummary result = run(DriverArgumentsConfigTest.class);
checkPass(result, 2, 0);
}
}

0 comments on commit 675ed73

Please sign in to comment.