Skip to content

Commit 187f036

Browse files
Anastasiia SmirnovaIlia-Ilinykh-EPAM
authored andcommitted
Fix selenium (PlaytikaOSS#695)
* Fix selenium * light cleanup for tests for selenium * disable firefox test * custom image for chrome
1 parent 8aa2e6d commit 187f036

File tree

10 files changed

+88
-174
lines changed

10 files changed

+88
-174
lines changed

embedded-couchbase/src/test/java/com/playtika/test/couchbase/CouchbaseJavaClientTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
import com.couchbase.client.core.env.SeedNode;
2727
import com.couchbase.client.core.env.TimeoutConfig;
28+
import com.couchbase.client.core.retry.BestEffortRetryStrategy;
29+
import com.couchbase.client.core.retry.RetryStrategy;
2830
import com.couchbase.client.java.Bucket;
2931
import com.couchbase.client.java.Cluster;
3032
import com.couchbase.client.java.ClusterOptions;
@@ -75,6 +77,8 @@ void plainJavaClientShouldWork() {
7577
Optional.of(mappedHttpPort))));
7678

7779
ClusterEnvironment env = ClusterEnvironment.builder()
80+
.retryStrategy(BestEffortRetryStrategy.withExponentialBackoff(Duration.ofMillis(50), Duration.ofMillis(500), 2))
81+
.maxNumRequestsInRetry(5)
7882
.timeoutConfig(TimeoutConfig.kvTimeout(Duration.ofSeconds(20)))
7983
.build();
8084

embedded-selenium/src/main/java/com/playtika/test/selenium/EmbeddedSeleniumBootstrapConfiguration.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,24 @@
4747
import org.testcontainers.containers.DefaultRecordingFileFactory;
4848
import org.testcontainers.containers.GenericContainer;
4949
import org.testcontainers.containers.RecordingFileFactory;
50+
import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy;
51+
import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy;
52+
import org.testcontainers.containers.wait.strategy.WaitAllStrategy;
53+
import org.testcontainers.containers.wait.strategy.WaitStrategy;
5054

5155

5256
import java.io.File;
5357
import java.io.IOException;
5458
import java.net.URI;
5559
import java.net.URL;
5660
import java.nio.file.Files;
61+
import java.time.Duration;
5762
import java.util.LinkedHashMap;
5863
import java.util.Locale;
5964
import java.util.Map;
6065

6166
import static com.playtika.test.selenium.SeleniumProperties.BEAN_NAME_EMBEDDED_SELENIUM;
67+
import static java.time.temporal.ChronoUnit.SECONDS;
6268

6369

6470
@Slf4j
@@ -108,6 +114,7 @@ public BrowserWebDriverContainer selenium(
108114
? new BrowserWebDriverContainer<>(imageName)
109115
: new BrowserWebDriverContainer<>();
110116

117+
container.setWaitStrategy(getWaitStrategy());
111118
container.withCapabilities(capabilities);
112119
container.withRecordingFileFactory(getRecordingFileFactory());
113120

@@ -126,6 +133,19 @@ public BrowserWebDriverContainer selenium(
126133
return container;
127134
}
128135

136+
//See: https://github.com/testcontainers/testcontainers-java/pull/4357
137+
@Deprecated
138+
private WaitStrategy getWaitStrategy() {
139+
WaitStrategy logWaitStrategy = new LogMessageWaitStrategy()
140+
.withRegEx(".*(RemoteWebDriver instances should connect to|Selenium Server is up and running).*\n")
141+
.withStartupTimeout(Duration.of(60, SECONDS));
142+
143+
return new WaitAllStrategy()
144+
.withStrategy(logWaitStrategy)
145+
.withStrategy(new HostPortWaitStrategy())
146+
.withStartupTimeout(Duration.of(60, SECONDS));
147+
}
148+
129149
/**
130150
* Testcontainers does not expose its default vnc dir when it is not
131151
* defined, so we recreate this implementation here.
Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,48 @@
11
/*
2-
* The MIT License (MIT)
3-
*
4-
*
5-
* Permission is hereby granted, free of charge, to any person obtaining a copy
6-
* of this software and associated documentation files (the "Software"), to deal
7-
* in the Software without restriction, including without limitation the rights
8-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
* copies of the Software, and to permit persons to whom the Software is
10-
* furnished to do so, subject to the following conditions:
11-
*
12-
* The above copyright notice and this permission notice shall be included in all
13-
* copies or substantial portions of the Software.
14-
*
15-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
* SOFTWARE.
2+
* The MIT License (MIT)
3+
*
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in all
13+
* copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
* SOFTWARE.
2222
*/
2323
package com.playtika.test.selenium;
2424

25-
import lombok.extern.slf4j.Slf4j;
2625
import org.junit.jupiter.api.Test;
27-
import org.springframework.beans.factory.BeanFactoryUtils;
28-
import org.springframework.beans.factory.annotation.Autowired;
29-
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
30-
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
31-
import org.springframework.boot.test.context.SpringBootTest;
32-
import org.springframework.context.annotation.Configuration;
33-
import org.testcontainers.containers.GenericContainer;
26+
import org.springframework.boot.autoconfigure.AutoConfigurations;
27+
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
28+
import org.testcontainers.containers.Container;
3429

3530
import static org.assertj.core.api.Assertions.assertThat;
3631

37-
@Slf4j
38-
@SpringBootTest(classes = DisableSeleniumTest.TestConfiguration.class,
39-
properties = "embedded.selenium.enabled=false")
4032
public class DisableSeleniumTest {
4133

42-
@Autowired
43-
ConfigurableListableBeanFactory beanFactory;
34+
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
35+
.withConfiguration(AutoConfigurations.of(
36+
EmbeddedSeleniumBootstrapConfiguration.class));
4437

4538
@Test
4639
public void contextLoads() {
47-
String[] containers = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory, GenericContainer.class);
48-
49-
assertThat(containers).isEmpty();
50-
}
51-
52-
@EnableAutoConfiguration
53-
@Configuration
54-
static class TestConfiguration {
40+
contextRunner
41+
.withPropertyValues(
42+
"embedded.selenium.enabled=false"
43+
)
44+
.run((context) -> assertThat(context)
45+
.hasNotFailed()
46+
.doesNotHaveBean(Container.class));
5547
}
5648
}

embedded-selenium/src/test/java/com/playtika/test/selenium/EnableSeleniumTest.java

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,39 @@
11
/*
2-
* The MIT License (MIT)
3-
*
4-
*
5-
* Permission is hereby granted, free of charge, to any person obtaining a copy
6-
* of this software and associated documentation files (the "Software"), to deal
7-
* in the Software without restriction, including without limitation the rights
8-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
* copies of the Software, and to permit persons to whom the Software is
10-
* furnished to do so, subject to the following conditions:
11-
*
12-
* The above copyright notice and this permission notice shall be included in all
13-
* copies or substantial portions of the Software.
14-
*
15-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
* SOFTWARE.
2+
* The MIT License (MIT)
3+
*
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in all
13+
* copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
* SOFTWARE.
2222
*/
2323
package com.playtika.test.selenium;
2424

25-
import lombok.extern.slf4j.Slf4j;
25+
import com.playtika.test.selenium.drivers.BaseEmbeddedSeleniumTest;
2626
import org.junit.jupiter.api.Test;
2727
import org.springframework.beans.factory.BeanFactoryUtils;
2828
import org.springframework.beans.factory.annotation.Autowired;
2929
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
3030
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
31-
import org.springframework.boot.test.context.SpringBootTest;
3231
import org.springframework.context.annotation.Configuration;
3332
import org.testcontainers.containers.GenericContainer;
3433

3534
import static org.assertj.core.api.Assertions.assertThat;
3635

37-
@Slf4j
38-
@SpringBootTest(classes = EnableSeleniumTest.TestConfiguration.class,
39-
properties = "embedded.selenium.enabled=true")
40-
public class EnableSeleniumTest {
36+
public class EnableSeleniumTest extends BaseEmbeddedSeleniumTest {
4137

4238
@Autowired
4339
ConfigurableListableBeanFactory beanFactory;

embedded-selenium/src/test/java/com/playtika/test/selenium/drivers/BaseEmbeddedSeleniumTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import static org.assertj.core.api.Assertions.assertThat;
4040

4141
@Slf4j
42-
@ExtendWith(SpringExtension.class)
4342
@SpringBootTest(
4443
classes = TestApplication.class,
4544
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT

embedded-selenium/src/test/java/com/playtika/test/selenium/drivers/EmbeddedChromiumSeleniumTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,9 @@ public void testThatOptionIsSet() {
5555
List<String> args = (List<String>)capabilities.get("args");
5656
assertThat(args).contains("start-maximized");
5757
}
58+
59+
@Test
60+
public void vncModeIsSkipByDefault() {
61+
assertThat(environment.getProperty("embedded.selenium.vnc.mode")).isEqualTo("SKIP");
62+
}
5863
}

embedded-selenium/src/test/java/com/playtika/test/selenium/drivers/EmbeddedFirefoxSeleniumBeanConfigurationTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525

2626
import com.playtika.test.selenium.SeleniumProperties;
27+
import org.junit.jupiter.api.Disabled;
2728
import org.junit.jupiter.api.Test;
2829
import org.openqa.selenium.firefox.FirefoxOptions;
2930
import org.openqa.selenium.remote.CapabilityType;
@@ -32,6 +33,7 @@
3233
import org.springframework.boot.test.context.TestConfiguration;
3334
import org.springframework.context.annotation.Bean;
3435
import org.springframework.context.annotation.Import;
36+
import org.springframework.test.annotation.DirtiesContext;
3537

3638
import java.util.List;
3739
import java.util.Map;
@@ -43,10 +45,7 @@
4345
*
4446
* {@link FirefoxOptions}
4547
*/
46-
@SpringBootTest(
47-
classes = TestApplication.class,
48-
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT
49-
)
48+
@Disabled
5049
@Import(EmbeddedFirefoxSeleniumBeanConfigurationTest.LocalTestConfiguration.class)
5150
public class EmbeddedFirefoxSeleniumBeanConfigurationTest extends BaseEmbeddedSeleniumTest {
5251

embedded-selenium/src/test/java/com/playtika/test/selenium/drivers/EmbeddedFirefoxSeleniumTest.java

Lines changed: 0 additions & 43 deletions
This file was deleted.

embedded-selenium/src/test/java/com/playtika/test/selenium/drivers/VncRecordingSkipTest.java

Lines changed: 0 additions & 59 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
embedded.selenium.image-name=selenium/standalone-chrome-debug:3.141.59-mercury

0 commit comments

Comments
 (0)