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

page loaded event #3758

Open
benmonro opened this issue Apr 28, 2019 · 3 comments

Comments

Projects
None yet
3 participants
@benmonro
Copy link

commented Apr 28, 2019

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

@AlexKamaev

This comment has been minimized.

Copy link
Collaborator

commented Apr 29, 2019

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

@benmonro

This comment has been minimized.

Copy link
Author

commented May 3, 2019

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?

@LavrovArtem

This comment has been minimized.

Copy link
Collaborator

commented May 6, 2019

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"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.