Skip to content

Commit d6c6170

Browse files
committed
Swap test to playwright
1 parent 803d0fc commit d6c6170

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@
104104
<groupId>org.jenkinsci.plugins</groupId>
105105
<artifactId>pipeline-model-definition</artifactId>
106106
</dependency>
107+
<dependency>
108+
<groupId>com.microsoft.playwright</groupId>
109+
<artifactId>playwright</artifactId>
110+
<version>1.51.0</version>
111+
<scope>test</scope>
112+
</dependency>
107113
<dependency>
108114
<groupId>org.jenkins-ci.plugins</groupId>
109115
<artifactId>pipeline-build-step</artifactId>

src/test/java/io/jenkins/plugins/pipelinegraphview/PipelineGraphViewRebuildTest.java

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

33
import static org.junit.jupiter.api.Assertions.assertEquals;
44

5+
import com.microsoft.playwright.Browser;
6+
import com.microsoft.playwright.Page;
7+
import com.microsoft.playwright.Playwright;
8+
import com.microsoft.playwright.Response;
59
import hudson.model.Result;
610
import io.jenkins.plugins.pipelinegraphview.utils.TestUtils;
7-
import org.htmlunit.html.HtmlPage;
11+
import java.io.IOException;
812
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
913
import org.junit.jupiter.api.Test;
1014
import org.jvnet.hudson.test.Issue;
@@ -20,11 +24,7 @@ void rebuildButtonStartsNewBuild(JenkinsRule j) throws Exception {
2024
WorkflowRun run =
2125
TestUtils.createAndRunJob(j, "hello_world", "helloWorldScriptedPipeline.jenkinsfile", Result.SUCCESS);
2226

23-
try (JenkinsRule.WebClient webClient = j.createWebClient()) {
24-
HtmlPage page = webClient.getPage(run, new PipelineGraphViewAction(run).getUrlName());
25-
HtmlPage newPage = page.getElementById("pgv-rebuild").click();
26-
assertEquals(page.getBaseURL(), newPage.getBaseURL());
27-
}
27+
startBuildAndAssertPageIsTheSame(j, run);
2828
}
2929

3030
@Issue("GH#330")
@@ -33,14 +33,21 @@ void rebuildButtonRedirectsForParameterizedJob(JenkinsRule j) throws Exception {
3333
WorkflowRun run = TestUtils.createAndRunJob(
3434
j, "echo_parameterized", "gh330_parameterizedBuild.jenkinsfile", Result.SUCCESS);
3535

36-
try (JenkinsRule.WebClient webClient = j.createWebClient()) {
37-
// the build page is returned with a 405 Method Not Allowed status code, but the page
38-
// exists and can be worked with; we should not fail on this status code
39-
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
36+
startBuildAndAssertPageIsTheSame(j, run);
37+
}
38+
39+
private static void startBuildAndAssertPageIsTheSame(JenkinsRule j, WorkflowRun run) throws IOException {
40+
try (Playwright playwright = Playwright.create();
41+
Browser browser = playwright.chromium().launch()) {
42+
Page page = browser.newPage();
43+
String urlName = new PipelineGraphViewAction(run).getUrlName();
44+
Response navigate = page.navigate(j.getURL() + run.getUrl() + urlName);
45+
String currentUrl = navigate.url();
46+
47+
page.click("#pgv-rebuild");
48+
String newUrl = page.url();
4049

41-
HtmlPage page = webClient.getPage(run, new PipelineGraphViewAction(run).getUrlName());
42-
HtmlPage newPage = page.getElementById("pgv-rebuild").click();
43-
assertEquals(page.getBaseURL(), newPage.getBaseURL());
50+
assertEquals(currentUrl, newUrl);
4451
}
4552
}
4653
}

0 commit comments

Comments
 (0)