Testcafe: page loaded event

Created on 28 Apr 2019  ·  9Comments  ·  Source: DevExpress/testcafe

What is your Test Scenario?


For testcafe-testing-library, I'd like to support a use case for when navigation occurs (clicking a link, reloading, etc). In order to do this, I need to inject dom-testing-library into the DOM on each page-load

What are you suggesting?


I propose adding an event subscription which I can subscribe to in a test or hook.

await t
  .on("pageload", () => addTestcafeTestingLibrary(t))
  .click(getByText("link to other page")
  .click(getByText("link to yet another page")
  .expect(getByText("element on other page").exists)
  .ok();

What alternatives have you considered?


I have a work around, but it requires manually injecting after the link click, it works, but it's toothy and cumbersome. For example, in the example above, i have to do this:

await addTestCafeTestingLibrary(t);

await t.click(getByText("link to other page"));

await addTestcafeTestingLibrary(t);

await t.click(getByText("link to yet another page"));

await addTestcafeTestingLibrary(t);

await t
  .expect(getByText("element on other page").exists)
  .ok();



quite verbose as you can see. hence the desire to have an event I can subscribe to for whenever a page load occurs....

Additional context

Auto-locked enhancement

All 9 comments

Thank you for your proposal. We'll consider its implementation with the team if the idea becomes popular.

Hi @AlexKamaev Thank you. Are there any work arounds you know of that I can use in the meantime to allow me to inject scripts into the page whenever a navigation event occurs?

You can try to wrap the click action and use it for clicks that lead to the page reload. For example:

const clickThatLeadsToReload = async (t, selector) => {
    await t.click(selector);
    await addTestcafeTestingLibrary(t);
};

await clickThatLeadsToReload(t, getByText("link to other page"));

@alexkamaev I'd be happy to submit a PR of you could point me in the right direction... Like where does testcafe interact with hammer head?

found a solution using the testRun class.

Ah yes. Nice catch. Thanks

@benmonro No, thank _you_. Really excited to use these two tools together. 🙇‍♂️

This thread has been automatically locked since it is closed and there has not been any recent activity. Please open a new issue for related bugs or feature requests. We recommend you ask TestCafe API, usage and configuration inquiries on StackOverflow.

Was this page helpful?
0 / 5 - 0 ratings