Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Page.setDefaultTimeout with timeout option #244

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

abrom
Copy link
Contributor

@abrom abrom commented Jun 27, 2024

The Page.setDefaultTimeout will apply the more general timeout option more generally 😄

Copy link

@jadehamel jadehamel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some test suggestions: to ensure that edge cases are covered and the global timeout interacts correctly with other options and operations. It includes scenarios where the global timeout interacts with specific options like waitForSelector or when performing multiple asynchronous operations.

describe 'Timeout handling with waitForSelector' do
  let(:url_or_html) do
    <<-HTML
      <html>
        <body></body>
        <script>
          setTimeout(function() {
            document.body.innerHTML = '<h1>Hey there</h1>';
          }, 200);
        </script>
      </html>
    HTML
  end

  let(:options) { basic_header_footer_options.merge('timeout' => timeout, 'waitForSelector' => 'h1') }

  context 'when the timeout is less than the page content load' do
    let(:timeout) { 100 }

    it_behaves_like 'raises navigation timeout error', timeout: 100
  end

  context 'when the timeout is greater than the page content load' do
    let(:timeout) { 2000 }

    it { is_expected.to start_with "%PDF-1.4\n" }
    it { expect(pdf_text_content).to eq "#{date} Hey there #{protocol}://www.example.net/foo/bar 1/1" }
  end
end

describe 'Handling multiple async operations within global timeout' do
  let(:timeout) { 3000 } # 3 seconds
  let(:options) { basic_header_footer_options.merge('timeout' => timeout) }

  let(:url_or_html) do
    <<-HTML
      <html>
        <body>
          <img src="large-image.jpg" />
          <script>
            setTimeout(function() {
              document.body.innerHTML += '<h1>Additional Content</h1>';
            }, 2000);  // 2 seconds delay
          </script>
        </body>
      </html>
    HTML
  end

  it 'completes all operations within the global timeout period' do
    expect(convert).to start_with "%PDF-1.4\n"
    expect(pdf_text_content).to include "Additional Content"
  end

  context 'when global timeout is exceeded by operations' do
    let(:timeout) { 1000 } # 1 second

    it_behaves_like 'raises global timeout error', timeout: 1000
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants