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

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 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
c356ecb
update locators for new website and minor fixes
RobertAvemarg Jan 28, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import java.lang.reflect.InvocationTargetException;
import java.util.Date;

import org.openqa.selenium.NoSuchSessionException;
import org.openqa.selenium.NoSuchWindowException;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.UnreachableBrowserException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -96,7 +98,7 @@ public synchronized void run()
file.delete();

}
catch (NoSuchWindowException e)
catch (NoSuchWindowException | NoSuchSessionException | UnreachableBrowserException e)
{
// catching the exception prevents the video from failing
}
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
@@ -1,7 +1,6 @@
package com.xceptance.neodymium.junit4.testclasses.multibrowser;

import static com.codeborne.selenide.CollectionCondition.sizeGreaterThan;
import static com.codeborne.selenide.Condition.exist;
import static com.codeborne.selenide.Condition.matchText;
import static com.codeborne.selenide.Condition.visible;
import static com.codeborne.selenide.Selenide.$;
Expand Down Expand Up @@ -30,10 +29,10 @@ public void testVisitingHomepage()
Assert.assertTrue(Selenide.executeJavaScript("return navigator.userAgent.indexOf(\"Safari\")>-1;"));

// short validation to check that the correct page was opened, should be moved to OpenHomePageFlow
$("#service-areas").should(exist);

// basic validation
// Verifies the company Logo and name are visible.
$("#navigation .navbar-brand a[title=Home]").shouldBe(visible);
$("#navigation .navbar-brand a").shouldBe(visible);

// Verifies the Navigation bar is visible
$("#navigation .navbar-header ul.nav").shouldBe(visible);
Expand All @@ -42,16 +41,13 @@ public void testVisitingHomepage()
$$("#navigation .navbar-header ul.nav > li > a").shouldHave(sizeGreaterThan(0));

// Asserts the first headline is there.
$("#service-areas .landing-intro > h1").shouldBe(matchText("[A-Z].{3,}"));

// Asserts the animated carousel is there.
$("#myCarousel").shouldBe(visible);
$("#main h1").shouldBe(matchText("[A-Z].{3,}"));

// Verifies the "services" section is there.
// Asserts there's at least 1 item in the list.
$$("#service-areas .container .thumbnail").shouldHave(sizeGreaterThan(0));
$$("#main .row.strip a").shouldHave(sizeGreaterThan(0));

// Verifies the company button is there.
$$("#xlt-background .container p.lead > a.btn-primary").shouldHave(sizeGreaterThan(0));
$$("p.lead > a").shouldHave(sizeGreaterThan(0));
}
}
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
@@ -1,7 +1,6 @@
package com.xceptance.neodymium.junit5.testclasses.multibrowser;

import static com.codeborne.selenide.CollectionCondition.sizeGreaterThan;
import static com.codeborne.selenide.Condition.exist;
import static com.codeborne.selenide.Condition.matchText;
import static com.codeborne.selenide.Condition.visible;
import static com.codeborne.selenide.Selenide.$;
Expand All @@ -27,10 +26,10 @@ public void testVisitingHomepage()
Assertions.assertTrue(() -> Selenide.executeJavaScript("return navigator.userAgent.indexOf(\"Safari\")>-1;"));

// short validation to check that the correct page was opened, should be moved to OpenHomePageFlow
$("#service-areas").should(exist);

// basic validation
// Verifies the company Logo and name are visible.
$("#navigation .navbar-brand a[title=Home]").shouldBe(visible);
$("#navigation .navbar-brand a").shouldBe(visible);

// Verifies the Navigation bar is visible
$("#navigation .navbar-header ul.nav").shouldBe(visible);
Expand All @@ -39,16 +38,13 @@ public void testVisitingHomepage()
$$("#navigation .navbar-header ul.nav > li > a").shouldHave(sizeGreaterThan(0));

// Asserts the first headline is there.
$("#service-areas .landing-intro > h1").shouldBe(matchText("[A-Z].{3,}"));

// Asserts the animated carousel is there.
$("#myCarousel").shouldBe(visible);
$("#main h1").shouldBe(matchText("[A-Z].{3,}"));

// Verifies the "services" section is there.
// Asserts there's at least 1 item in the list.
$$("#service-areas .container .thumbnail").shouldHave(sizeGreaterThan(0));
$$("#main .row.strip a").shouldHave(sizeGreaterThan(0));

// Verifies the company button is there.
$$("#xlt-background .container p.lead > a.btn-primary").shouldHave(sizeGreaterThan(0));
$$("p.lead > a").shouldHave(sizeGreaterThan(0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.xceptance.neodymium.junit5.NeodymiumTest;

@Browser("Chrome_headless")
public class AutomaticRecordingTest
public class CustomRecordingTest
{
public static String uuid;

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
Loading