Skip to content

Commit 22e4c85

Browse files
committed
testing fix for web tests
1 parent 0c6a486 commit 22e4c85

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

Jenkinsfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,13 @@ pipeline {
3838
}
3939
// not working on cloud run
4040
stage('Web Test'){
41-
agent {
42-
docker { image 'selenium/standalone-chrome:latest' }
43-
}
41+
// agent {
42+
// docker { image 'selenium/standalone-chrome:latest' }
43+
// }
4444
steps {
4545
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
4646
dir("${env.WORKSPACE}") {
47+
sh "docker run -d -p 4444:4444 -v /dev/shm:/dev/shm selenium/standalone-chrome:latest"
4748
echo "Running Web Tests...."
4849
sh "pwd"
4950
sh "curl http://localhost:4444/wd/hub"

src/test/java/com/example/JavaSpringBoot/WebTests.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
import org.openqa.selenium.WebDriver;
99
import org.openqa.selenium.chrome.ChromeDriver;
1010
import org.openqa.selenium.chrome.ChromeOptions;
11+
import org.openqa.selenium.remote.RemoteWebDriver;
1112
import org.springframework.boot.test.context.SpringBootTest;
1213
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
1314
import org.springframework.boot.web.server.LocalServerPort;
1415

16+
import java.net.MalformedURLException;
17+
import java.net.URL;
1518
import java.util.concurrent.TimeUnit;
1619

1720
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -56,7 +59,7 @@ void newpage() {
5659
}
5760

5861
@Test
59-
public void user_is_on_application_homepage() throws InterruptedException {
62+
public void user_is_on_application_homepage() throws InterruptedException, MalformedURLException {
6063

6164

6265
System.out.println("Opening Browser...");
@@ -68,12 +71,16 @@ public void user_is_on_application_homepage() throws InterruptedException {
6871
}
6972
else {
7073
// use the chrome driver in docker instance
71-
WebDriverManager.chromedriver().setup();
74+
// testing remote webdriver - us this to launch docker run -d -p 4444:4444 -v /dev/shm:/dev/shm selenium/standalone-chrome:latest
75+
System.out.println("Connecting to Hub");
76+
String nodeURL;
77+
nodeURL = "http://localhost:4444/wd/hub";
7278
ChromeOptions options = new ChromeOptions();
7379
options.addArguments("--no-sandbox");
7480
options.addArguments("--headless");
75-
options.addArguments("--disable-dev-shm-usage");
76-
options.addArguments("--disable-gpu");
81+
driver = new RemoteWebDriver(new URL(nodeURL), options);
82+
System.out.println("Hub connection is good!");
83+
7784
driver = new ChromeDriver(options);
7885
}
7986
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

0 commit comments

Comments
 (0)