Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement: Stabilize unit tests #330 #332

Open
wants to merge 27 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e759fb7
updated Allure Cucumber jvm
RobertAvemarg Dec 12, 2024
e2f55be
[#322] fix browser isn't started for after if test is in different class
oomelianchuk Dec 13, 2024
1d97081
[#322] add unit tests
oomelianchuk Dec 13, 2024
99666f4
[#330] Improvement: Stabilize unit tests
oomelianchuk Dec 17, 2024
19c6a57
Merge branch '322-bug-browser-is-not-started-for-after-method-if-its-…
oomelianchuk Dec 17, 2024
77e0cb2
Merge remote-tracking branch 'origin/#319_update_Allure_Cucumber_jvm'…
oomelianchuk Dec 17, 2024
1f5282b
[#322] fix for junit-4
oomelianchuk Dec 17, 2024
ea61ddb
Merge branch '322-bug-browser-is-not-started-for-after-method-if-its-…
oomelianchuk Dec 18, 2024
2079655
try to fix AllureAddonsTest
oomelianchuk Dec 18, 2024
682a040
[#330] fix AllureSelenideListenerTest
oomelianchuk Dec 18, 2024
495cd6c
[#330] try to stabilize DownloadFilesExecutorTest
oomelianchuk Dec 18, 2024
712b95f
[#330] improve stability of DownloadFilesExecutorTest
oomelianchuk Dec 18, 2024
2bd3f97
[#330] add sysouts to investigate failure of
oomelianchuk Dec 18, 2024
65ce070
[#322] improve code structure
oomelianchuk Dec 18, 2024
5acfe02
[#322] fix tests
oomelianchuk Dec 18, 2024
c723710
Merge branch '322-bug-browser-is-not-started-for-after-method-if-its-…
oomelianchuk Dec 18, 2024
ce41fe6
[#330] try to fix DownloadFilesInDifferentWays test
oomelianchuk Dec 18, 2024
452b5c8
[#330] fix DownloadFilesExecutorTest
oomelianchuk Dec 18, 2024
5a14f40
[#330] remove util tests for junit-5 as included and written in junit-4
oomelianchuk Dec 18, 2024
e13db35
[#330] open chrome downloads history
oomelianchuk Dec 19, 2024
61c52c4
[#330] improve test stability
oomelianchuk Dec 20, 2024
6a67149
[#330] try to stabilize DownloadFilesExecutorTest
oomelianchuk Dec 20, 2024
916ebfb
[#330] try to stabilize DownloadFilesExecutorTest for junit4
oomelianchuk Dec 20, 2024
f5c8d53
Revert "Merge branch '322-bug-browser-is-not-started-for-after-method…
oomelianchuk Dec 23, 2024
1d3948d
Revert "Merge branch '322-bug-browser-is-not-started-for-after-method…
oomelianchuk Dec 23, 2024
5cca259
Revert "Merge remote-tracking branch 'origin/#319_update_Allure_Cucum…
oomelianchuk Dec 23, 2024
fa68a51
Revert "Merge branch '322-bug-browser-is-not-started-for-after-method…
oomelianchuk Dec 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -204,17 +204,9 @@
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>
com/xceptance/neodymium/junit4/tests/**/*Test.java</include>
<include> com/xceptance/neodymium/junit4/tests/**/*Test.java</include>
<include> com/xceptance/neodymium/util/**/*Test.java</include>
</includes>
<includes>
<include>
com/xceptance/neodymium/util/**/*Test.java</include>
</includes>
<excludes>
<exclude>
com/xceptance/neodymium/junit4/tests/visual/**/*Test.java</exclude>
</excludes>
</configuration>
<dependencies>
<dependency>
Expand All @@ -238,8 +230,6 @@
<includes>
<include>
com/xceptance/neodymium/junit5/tests/**/*Test.java</include>
<include>
com/xceptance/neodymium/util/**/*Test.java</include>
</includes>
</configuration>
</plugin>
Expand Down
21 changes: 15 additions & 6 deletions src/main/java/com/xceptance/neodymium/util/AllureAddons.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.InputStream;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.nio.channels.OverlappingFileLockException;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.HashMap;
Expand Down Expand Up @@ -273,7 +274,14 @@ public static synchronized void addEnvironmentInformation(ImmutableMap<String, S
{
Selenide.sleep(100);
}
lock = FileChannel.open(Paths.get(getEnvFile().getAbsolutePath()), StandardOpenOption.APPEND).tryLock();
try
{
lock = FileChannel.open(Paths.get(getEnvFile().getAbsolutePath()), StandardOpenOption.APPEND).tryLock();
}
catch (OverlappingFileLockException e)
{
LOGGER.debug(getEnvFile() + " is already locked");
}
retries++;
}
while (retries < MAX_RETRY_COUNT && lock == null);
Expand Down Expand Up @@ -444,12 +452,13 @@ else if (key.equals(entry.getKey()))
{
LOGGER.warn("Could not acquire Filelock in time. Failed to add information about enviroment to Allure report");
}
}catch(ParserConfigurationException|TransformerException|SAXException|
}
catch (ParserConfigurationException | TransformerException | SAXException |

IOException e)
{
LOGGER.warn("Failed to add information about environment to Allure report", e);
}
IOException e)
{
LOGGER.warn("Failed to add information about environment to Allure report", e);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import com.xceptance.neodymium.junit4.NeodymiumRunner;
import com.xceptance.neodymium.util.Neodymium;

//@Browser("Chrome_1024x768")
//@Browser("Chrome_1500x1000")
@Browser("Chrome_1024x768")
@Browser("Chrome_1500x1000")
@Browser("FF_1024x768")
@Browser("FF_1500x1000")
@RandomBrowsers(2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@
import io.cucumber.junit.CucumberOptions;

@RunWith(NeodymiumCucumberRunner.class)
@CucumberOptions(features = "src/test/resources/com/xceptance/neodymium/junit4/testclasses/cucumber/CucumberValidateAllureSelenideListenerIsActive.feature", glue = "com/xceptance/neodymium/junit4/testclasses/cucumber", plugin = "null_summary")
@CucumberOptions(features = "src/test/resources/com/xceptance/neodymium/junit4/testclasses/cucumber/CucumberValidateAllureSelenideListenerIsActive.feature", glue = "com/xceptance/neodymium/junit4/testclasses/cucumber", plugin =
{
// Plugins for generating additional JSON and XML reports.
// Is equivalent to cucumber.plugin in cucumber.properties.
// The plugin for generating an html report is included in the cucumber.properties file for all test cases.
"json:target/cucumber-report/cucumber.json",
"junit:target/cucumber-report/cucumber.xml"
})
public class CucumberValidateAllureSelenideListenerIsActive
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static com.codeborne.selenide.Condition.attribute;
import static com.codeborne.selenide.Condition.enabled;
import static com.codeborne.selenide.Condition.exactText;
import static com.codeborne.selenide.Condition.exist;
import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.$$;

Expand All @@ -14,6 +15,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;

import com.codeborne.selenide.ClickOptions;
import com.codeborne.selenide.Selectors;
import com.codeborne.selenide.Selenide;
import com.xceptance.neodymium.common.browser.Browser;
Expand Down Expand Up @@ -57,7 +59,7 @@ public void downloadOnFormSubmission()
$(".fc-cta-consent").click();
$("#fileSelector").uploadFile(new File("src/test/resources/2020-in-one-picture.png"));
$("button[aria-label='COMBINED']").shouldBe(enabled, Duration.ofMillis(9000));
$("button[aria-label='COMBINED']").scrollIntoView(true).click();
$("button[aria-label='COMBINED']").click(ClickOptions.usingJavaScript());
waitForFileDownloading();
validateFilePresentInDownloadHistory();
}
Expand Down Expand Up @@ -92,7 +94,8 @@ private void validateFilePresentInDownloadHistory()
if (Neodymium.getBrowserName().contains("chrome"))
{
Selenide.open("chrome://downloads/");
$$(Selectors.shadowCss("#title-area", "downloads-manager", "#downloadsList downloads-item")).findBy(exactText(fileName.getName())).parent()
$$(Selectors.shadowCss("#title-area", "downloads-manager", "#downloadsList downloads-item")).findBy(exactText(fileName.getName()))
.should(exist, Duration.ofMillis(9000)).parent()
.find(".description[role='gridcell']")
.shouldHave(attribute("hidden"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;

import com.xceptance.neodymium.common.browser.configuration.MultibrowserConfiguration;
import com.xceptance.neodymium.junit4.testclasses.multibrowser.BrowserstackHomePageTest;
import com.xceptance.neodymium.util.TestConfiguration;

Expand Down Expand Up @@ -42,9 +43,13 @@ public static void beforeClass() throws IOException
properties2.put("browserprofile.Safari_Browserstack.browserName", "Safari");
properties2.put("browserprofile.Safari_Browserstack.version", "14.0");
properties2.put("browserprofile.Safari_Browserstack.testEnvironment", "browserstack");
File tempConfigFile2 = new File("./config/dev-browser.properties");
File tempConfigFile2 = File.createTempFile("BrowserstackProxyErrorTest", "", new File("./config/"));
writeMapToPropertiesFile(properties2, tempConfigFile2);
tempFiles.add(tempConfigFile2);

// this line is important as we initialize the config from the temporary file we created above
MultibrowserConfiguration.clearAllInstances();
MultibrowserConfiguration.getInstance(tempConfigFile2.getPath());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;

import com.xceptance.neodymium.common.browser.configuration.MultibrowserConfiguration;
import com.xceptance.neodymium.junit4.testclasses.multibrowser.BrowserstackHomePageTest;
import com.xceptance.neodymium.util.TestConfiguration;

Expand Down Expand Up @@ -42,9 +43,13 @@ public static void beforeClass() throws IOException
properties2.put("browserprofile.Safari_Browserstack.browserName", "Safari");
properties2.put("browserprofile.Safari_Browserstack.version", "14.0");
properties2.put("browserprofile.Safari_Browserstack.testEnvironment", "browserstack");
File tempConfigFile2 = new File("./config/dev-browser.properties");
File tempConfigFile2 = File.createTempFile("BrowserstackProxyTest", "", new File("./config/"));
writeMapToPropertiesFile(properties2, tempConfigFile2);
tempFiles.add(tempConfigFile2);

// this line is important as we initialize the config from the temporary file we created above
MultibrowserConfiguration.clearAllInstances();
MultibrowserConfiguration.getInstance(tempConfigFile2.getPath());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;

import com.xceptance.neodymium.common.browser.configuration.MultibrowserConfiguration;
import com.xceptance.neodymium.junit4.testclasses.multibrowser.BrowserstackHomePageTest;
import com.xceptance.neodymium.util.TestConfiguration;

Expand All @@ -36,9 +37,13 @@ public static void beforeClass() throws IOException
properties2.put("browserprofile.Safari_Browserstack.browserName", "Safari");
properties2.put("browserprofile.Safari_Browserstack.version", "14.0");
properties2.put("browserprofile.Safari_Browserstack.testEnvironment", "browserstack");
File tempConfigFile2 = new File("./config/dev-browser.properties");
File tempConfigFile2 = File.createTempFile("BrowserstackTest", "", new File("./config/"));
writeMapToPropertiesFile(properties2, tempConfigFile2);
tempFiles.add(tempConfigFile2);

// this line is important as we initialize the config from the temporary file we created above
MultibrowserConfiguration.clearAllInstances();
MultibrowserConfiguration.getInstance(tempConfigFile2.getPath());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import org.junit.jupiter.api.AfterEach;

import com.codeborne.selenide.ClickOptions;
import com.codeborne.selenide.Selectors;
import com.codeborne.selenide.Selenide;
import com.xceptance.neodymium.common.browser.Browser;
Expand Down Expand Up @@ -54,7 +55,7 @@ public void downloadOnFormSubmission()
$(".fc-cta-consent").click();
$("#fileSelector").uploadFile(new File("src/test/resources/2020-in-one-picture.png"));
$("button[aria-label='COMBINED']").shouldBe(enabled);
$("button[aria-label='COMBINED']").scrollIntoView(true).click();
$("button[aria-label='COMBINED']").click(ClickOptions.usingJavaScript());
waitForFileDownloading();
validateFilePresentInDownloadHistory();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import com.xceptance.neodymium.common.browser.configuration.MultibrowserConfiguration;
import com.xceptance.neodymium.junit5.testclasses.multibrowser.BrowserstackHomePageTest;
import com.xceptance.neodymium.junit5.tests.utils.NeodymiumTestExecutionSummary;
import com.xceptance.neodymium.util.TestConfiguration;
Expand Down Expand Up @@ -41,9 +42,14 @@ public static void beforeClass() throws IOException
properties2.put("browserprofile.Safari_Browserstack.browserName", "Safari");
properties2.put("browserprofile.Safari_Browserstack.version", "14.0");
properties2.put("browserprofile.Safari_Browserstack.testEnvironment", "browserstack");
File tempConfigFile2 = new File("./config/dev-browser.properties");

File tempConfigFile2 = File.createTempFile("BrowserstackProxyErrorTest", "", new File("./config/"));
writeMapToPropertiesFile(properties2, tempConfigFile2);
tempFiles.add(tempConfigFile2);

// this line is important as we initialize the config from the temporary file we created above
MultibrowserConfiguration.clearAllInstances();
MultibrowserConfiguration.getInstance(tempConfigFile2.getPath());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import com.xceptance.neodymium.common.browser.configuration.MultibrowserConfiguration;
import com.xceptance.neodymium.junit5.testclasses.multibrowser.BrowserstackHomePageTest;
import com.xceptance.neodymium.junit5.tests.utils.NeodymiumTestExecutionSummary;
import com.xceptance.neodymium.util.TestConfiguration;
Expand Down Expand Up @@ -41,9 +42,13 @@ public static void beforeClass() throws IOException
properties2.put("browserprofile.Safari_Browserstack.browserName", "Safari");
properties2.put("browserprofile.Safari_Browserstack.version", "14.0");
properties2.put("browserprofile.Safari_Browserstack.testEnvironment", "browserstack");
File tempConfigFile2 = new File("./config/dev-browser.properties");
File tempConfigFile2 = File.createTempFile("BrowserstackProxyTest", "", new File("./config/"));
writeMapToPropertiesFile(properties2, tempConfigFile2);
tempFiles.add(tempConfigFile2);

// this line is important as we initialize the config from the temporary file we created above
MultibrowserConfiguration.clearAllInstances();
MultibrowserConfiguration.getInstance(tempConfigFile2.getPath());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import com.xceptance.neodymium.common.browser.configuration.MultibrowserConfiguration;
import com.xceptance.neodymium.junit5.testclasses.multibrowser.BrowserstackHomePageTest;
import com.xceptance.neodymium.junit5.tests.utils.NeodymiumTestExecutionSummary;
import com.xceptance.neodymium.util.TestConfiguration;
Expand All @@ -24,7 +25,7 @@ public static void beforeClass() throws IOException
properties1.put("browserprofile.testEnvironment.browserstack.url", "https://hub-cloud.browserstack.com/wd/hub");
properties1.put("browserprofile.testEnvironment.browserstack.username", CONFIGURATION.browserstackUsername());
properties1.put("browserprofile.testEnvironment.browserstack.password", CONFIGURATION.browserstackAccessKey());

File tempConfigFile1 = new File("./config/credentials.properties");
writeMapToPropertiesFile(properties1, tempConfigFile1);
tempFiles.add(tempConfigFile1);
Expand All @@ -36,9 +37,13 @@ public static void beforeClass() throws IOException
properties2.put("browserprofile.Safari_Browserstack.browserName", "Safari");
properties2.put("browserprofile.Safari_Browserstack.version", "14.0");
properties2.put("browserprofile.Safari_Browserstack.testEnvironment", "browserstack");
File tempConfigFile2 = new File("./config/dev-browser.properties");
File tempConfigFile2 = File.createTempFile("BrowserstackTest", "", new File("./config/"));
writeMapToPropertiesFile(properties2, tempConfigFile2);
tempFiles.add(tempConfigFile2);

// this line is important as we initialize the config from the temporary file we created above
MultibrowserConfiguration.clearAllInstances();
MultibrowserConfiguration.getInstance(tempConfigFile2.getPath());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@

import org.junit.Assert;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import com.google.common.collect.ImmutableMap;
import com.xceptance.neodymium.common.browser.SuppressBrowsers;
import com.xceptance.neodymium.junit4.NeodymiumRunner;
import com.xceptance.neodymium.util.AllureAddons.EnvironmentInfoMode;

@RunWith(NeodymiumRunner.class)
@SuppressBrowsers
public class AllureAddonsTest
{
@Test
Expand Down Expand Up @@ -108,7 +113,7 @@ public void TestAllureAddEnvironmentInformation() throws Exception

AllureAddons.addEnvironmentInformation(map6, EnvironmentInfoMode.ADD);
this.validateEnvironmentFile(expectedFileContentList);

// ignore value
ImmutableMap<String, String> map7 = ImmutableMap.<String, String> builder()
.put("d",
Expand Down Expand Up @@ -151,7 +156,7 @@ private void validateEnvironmentFile(List<Entry<String, String>> list) throws Ex
Document doc = docBuilder.parse(getEnvFile());

Node environment = doc.getDocumentElement();
Assert.assertEquals("Wrong root node name in environments.xml", "environment", environment.getNodeName());
Assert.assertEquals("Wrong root node name in environments-test.xml", "environment", environment.getNodeName());

NodeList childNodes = environment.getChildNodes();
Assert.assertEquals("Wrong number of params in environments.xml", list.size(), childNodes.getLength());
Expand Down
Loading