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

await ctx.eval(() => location.reload(true)); doesn't refresh the page from fixture #3502

Closed
jiteshsojitra opened this issue Feb 28, 2019 · 8 comments
Labels
STATE: Auto-locked An issue has been automatically locked by the Lock bot. TYPE: question The issue contains a question that won't be addressed.

Comments

@jiteshsojitra
Copy link

jiteshsojitra commented Feb 28, 2019

How can we refresh the page/URL from fixture? Tried await ctx.eval(() => location.reload(true)); but it doesn't work, the same code works fine from the test but not from fixture (.after).

What is your Test Scenario?

fixture `Create Mail fixture`
  .page(process.env.SERVER_HOST_URL)
  .before(async ctx => {
	await common.configuration(__filename, ctx);
  })
  .beforeEach(async t => {
	try {
		await common.createAccount(t);
	} catch (error) {
		console.log(error);
		throw new Error('Error occured in fixture beforeEach method');
	}
  })
  .after(async ctx => {
	await ctx.eval(() => location.reload(true));
});

Error:

1) - Error in fixture.after hook -
    TypeError: ctx.eval is not a function

What is the Current behavior?

  • Page doesn't refresh.

What is the Expected behavior?

  • Page should be refreshed

Your Environment details:

  • testcafe version:
    v1.0.1
  • node.js version:
    v8.12.0
@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Feb 28, 2019
@miherlosev
Copy link
Collaborator

Hi @jiteshsojitra

Fixtures before and after hooks does not have access to the tested page (see the corresponding help topic).

You can refresh the tested page in the afterEach hook:

fixture `Create Mail fixture`
  .page(process.env.SERVER_HOST_URL)
  ....
  .beforeEach(async t => {})
  .afterEach(async t => {
	await t.eval(() => location.reload(true));
        or
        await t.navigateTo(process.env.SERVER_HOST_URL)
});

@miherlosev miherlosev added the TYPE: question The issue contains a question that won't be addressed. label Feb 28, 2019
@need-response-app need-response-app bot removed STATE: Need response An issue that requires a response or attention from the team. labels Feb 28, 2019
@jiteshsojitra
Copy link
Author

jiteshsojitra commented Mar 1, 2019

Sorry but as mentioned in the question, i don't want to refresh the page after each tests but would like to refresh the page after fixture to save the time and free occupied resources. Please reopen the question.

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Mar 1, 2019
@Farfurix
Copy link
Contributor

Farfurix commented Mar 1, 2019

@jiteshsojitra.

Could you please clarify what resources you are going to release and how this will help you save time?

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label Mar 1, 2019
@jiteshsojitra
Copy link
Author

Our application occupies some memory which it releases on refreshing browser but we don't want to reload browser on each tests but once per fixture only. If we reload the browser on each test then it will obviously will take more time because application waits till it loads fine.

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Mar 1, 2019
@Farfurix
Copy link
Contributor

Farfurix commented Mar 4, 2019

@jiteshsojitra.

In the following example, we have one specified Start Page and, as you can see in your browser, the page is reloaded twice after Test1 and Test2. This is the default behavior.

fixture `MyFixture`
    .page `http://devexpress.github.io/testcafe/example`;
 test('Test1', async t => {
    await t.wait(2000);
});
 test('Test2', async t => {
    await t.wait(2000);
});
 test('Test3', async t => {
    await t.wait(2000);
});

 
If you don't want to reload the page between tests, you need to use the --disable-page-reloads flag. Note that this flag is undocumented and experimental, so you will need to control all reload cleanups manually: clean cookie, storage, etc. Refer to the following issues for more information: #1770#2850.

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label Mar 4, 2019
@jiteshsojitra
Copy link
Author

@Farfurix, i think you didn't understand about the actual problem. I would like to refresh page from fixture using @after method.

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Mar 4, 2019
@miherlosev
Copy link
Collaborator

@jiteshsojitra You can not reload the tested page in fixture.after test hook.
There are two opened suggestions that suit your needs: Restart browser if it became unresponsive,
Implement per-test, not per-browser hooks

At present, I advise you to use the workaround from the #1345:

function once(fn) {
    var executed = false;

    return function() {
          if (!executed) {
               executed = true;
               return fn.apply(this, arguments);
          }
    };
}


fixture `My fixture`
     .afterEach(once(async t => {
             await ctx.eval(() => location.reload(true))
      }));

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label Mar 5, 2019
@lock
Copy link

lock bot commented Mar 27, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs or feature requests. For TestCafe API, usage and configuration inquiries, we recommend asking them on StackOverflow.

@lock lock bot added the STATE: Auto-locked An issue has been automatically locked by the Lock bot. label Mar 27, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Mar 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
STATE: Auto-locked An issue has been automatically locked by the Lock bot. TYPE: question The issue contains a question that won't be addressed.
Projects
None yet
Development

No branches or pull requests

3 participants