Getting wait timeout exception for page.navigate("someURLWhichIsAccessableFromPod") method within the docker pod

867 Views Asked by At

I have written one test case using playwright, which will open one web page using page.navigate() method and once it is loaded it will do further testing on opened web page.

Here the issue i am getting is on "page.navigate()" method where it is not able to load the webpage url and getting waiting timeout exception.

As a base image here i am using "<base.docker.image>mcr.microsoft.com/playwright/java:v1.34.0-jammy</base.docker.image>"

Note, below things I have tried :

  1. The URL which the test case is trying to open, that URL is accessible within the docker pod checked it using "curl" command.
  2. Also tried to increase the default wait timeout till 5 minutes.
  3. On my local machine the same test case is running successfully, this issue is specific to only docker pod.
import com.microsoft.playwright.Browser;
import com.microsoft.playwright.BrowserContext;
import com.microsoft.playwright.BrowserType;
import com.microsoft.playwright.Page;
import com.microsoft.playwright.Playwright;

import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;


public class PlayWrightTestSetup {

   
    // Shared between all tests in the class.
    public static Playwright playwright;
    public static Browser browser;

    // New instance for each test method.
    public static BrowserContext context;
    public static Page page;

    
    @BeforeSuite()
    public void setUpTestSuite() {
        playwright = Playwright.create();
        browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setHeadless(Boolean.TRUE));
        
    }

    @AfterSuite()
    public void testSuitePostStep() {
            playwright.close();
    }

}
import com.microsoft.playwright.Browser;
import com.microsoft.playwright.Page;

import org.apache.commons.lang3.StringUtils;

import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;


public class TestClass extends PlayWrightTestSetup {

    @BeforeMethod()
    public void createContextAndPage() {
      
        context = browser.newContext(new Browser.NewContextOptions().setIgnoreHTTPSErrors(true));
        context.setDefaultNavigationTimeout(90000);
        
    }

    @AfterMethod()
    public void closeContext() {
       context.close();
    }
    
    @Test()
    public void testUI(){
        Page someUIPage = context.newPage();
        LOGGER.info("Opening web page...");
        someUIPage.navigate("www.testexample.com",new Page.NavigateOptions().setWaitUntil(WaitUntilState.LOAD));
        LOGGER.info("Successfully loaded web page");
    }
    
}

Error :

navigating to "https://www.testexample.com/", waiting until "load"
============================================================   name='TimeoutError   stack='TimeoutError: Timeout 90000ms exceeded.
=========================== logs =========================== navigating to "https://www.testexample.com/", waiting until "load"
============================================================
    at ProgressController.run (/tmp/playwright-java-1873968284753476751/package/lib/server/progress.js:88:26)
    at Frame.goto (/tmp/playwright-java-1873968284753476751/package/lib/server/frames.js:521:23)
    at FrameDispatcher.goto (/tmp/playwright-java-1873968284753476751/package/lib/server/dispatchers/frameDispatcher.js:75:121)
    at DispatcherConnection.dispatch (/tmp/playwright-java-1873968284753476751/package/lib/server/dispatchers/dispatcher.js:312:46)
2

There are 2 best solutions below

2
Vishal Aggarwal On

Wait for navigation

I think it's sync issue as it works in local.

Playwright being very fast after navigation it immediately expects for load to complete.

Modern web applications perform numerous activities after the load event was fired. They fetch data lazily, populate UI, load expensive resources, scripts and styles after the load event was fired. It's hard to tell actually when the page load is complete.

So please explicitly wait for an element after navigation which only becomes visible once page load is fully complete. You may do this visually by observing the page load and identify an element which loads at the last:

page.navigate("https://example.com");

assertThat(page.getByText("Welcome")).isVisible();
0
Jeff On

trace-viewer help me to check network calls , where i found one external call which is not accessible within pod @VishalAggarwal Thank you :)