22
33import 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 ;
59import hudson .model .Result ;
610import io .jenkins .plugins .pipelinegraphview .utils .TestUtils ;
7- import org . htmlunit . html . HtmlPage ;
11+ import java . io . IOException ;
812import org .jenkinsci .plugins .workflow .job .WorkflowRun ;
913import org .junit .jupiter .api .Test ;
1014import 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