Skip to content

Commit f807f0e

Browse files
committed
Fix codesmell in tests
1 parent 26af42e commit f807f0e

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

src/test/java/tests/visualization/ImageComparatorTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ public void testGetPercentageDifferenceForDifferentElementsWithFullThreshold() {
6969
}
7070

7171
@Test
72-
public void testGetPercentageDifferenceForSimilarElements() throws InterruptedException {
72+
public void testGetPercentageDifferenceForSimilarElements() {
7373
startLoading();
7474
Image firstImage = getLoadingImage();
75-
Thread.sleep(300);
75+
DynamicLoadingForm.waitUntilLoaderChanged(firstImage.getHeight(null));
7676
Image secondImage = getLoadingImage();
7777

7878
Assert.assertTrue(imageComparator.percentageDifference(firstImage, secondImage, 0) != 0,

src/test/java/tests/visualization/VisualStateProviderTests.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
import aquality.selenium.core.visualization.IVisualStateProvider;
44
import aquality.selenium.core.visualization.ImageFunctions;
5-
import aquality.selenium.core.waitings.IConditionalWait;
65
import org.testng.Assert;
76
import org.testng.annotations.BeforeMethod;
87
import org.testng.annotations.Test;
9-
import tests.applications.browser.AqualityServices;
108
import tests.applications.browser.ITheInternetPageTest;
119
import theinternet.DynamicLoadingForm;
1210
import theinternet.TheInternetPage;
@@ -80,11 +78,10 @@ public void testGetPercentageDifferenceForDifferentElementsWithFullThreshold() {
8078
}
8179

8280
@Test
83-
public void testGetPercentageDifferenceForSimilarElements() throws InterruptedException {
81+
public void testGetPercentageDifferenceForSimilarElements() {
8482
startLoading();
8583
Image firstImage = getLoadingVisual().getImage();
86-
AqualityServices.get(IConditionalWait.class).waitFor(
87-
() -> firstImage.getHeight(null) < getLoadingVisual().getSize().getHeight());
84+
DynamicLoadingForm.waitUntilLoaderChanged(firstImage.getHeight(null));
8885
Assert.assertNotEquals(getLoadingVisual().getDifference(firstImage, 0), 0);
8986
Assert.assertTrue(getLoadingVisual().getDifference(firstImage, 0.2f) <= 0.3);
9087
Assert.assertTrue(getLoadingVisual().getDifference(firstImage, 0.4f) <= 0.2);

src/test/java/theinternet/DynamicLoadingForm.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import aquality.selenium.core.applications.IApplication;
44
import aquality.selenium.core.elements.ElementState;
55
import aquality.selenium.core.elements.interfaces.IElementStateProvider;
6+
import aquality.selenium.core.waitings.IConditionalWait;
67
import org.openqa.selenium.By;
8+
import tests.applications.browser.AqualityServices;
79
import tests.applications.browser.CachedLabel;
810

911
import java.time.Duration;
@@ -48,4 +50,9 @@ public IElementStateProvider loaderState() {
4850
public IElementStateProvider startButtonState() {
4951
return state(START_BUTTON_LOCATOR);
5052
}
53+
54+
public static void waitUntilLoaderChanged(int oldHeight) {
55+
AqualityServices.get(IConditionalWait.class).waitFor(
56+
() -> oldHeight < getLoadingLabel().visual().getSize().getHeight());
57+
}
5158
}

0 commit comments

Comments
 (0)