1

the documentation (https://devexpress.github.io/testcafe/documentation/test-api/test-code-structure.html#test-hooks) states that:
"If test.before or test.after is specified, it overrides the corresponding fixture.beforeEach and fixture.afterEach hook, so that the latter are not executed."

This doesn't make logical sense. Shouldn't feature.beforeEach execute first?

My code uses the the feature.beforeEach hook to Maximise the browser. The website I'm working on has different DOM Elements depending on the page size - Mobile, Tablet, Desktop etc.

When TestCafe opens the browser it is always at a small size. If I want to work on desktop elements, I have to wait for the browser to be maximised first. I cannot use the test.before hooks because it will try to access elements that don't exist and fail straight away.

Suggestion: Can we make the feature.beforeEach hook to always execute first? This can be similar to the "Background" command in Cucumber that runs before each Scenario in a Feature?

Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47
faisalk
  • 129
  • 1
  • 14
  • 1
    The `test.before` hook might access elements only if there are actions (and `maximizeWindow` is not one of them) that try to access elements. What actions are in your `test.before` hook? – aleks-pro Nov 25 '19 at 13:24

1 Answers1

1

I would not mix tests of different domains like Desktop and mobile in one suite, but if so:

I would recommend to build a Gherkin-Sentence to set up the environmental settings depending on what test is up to come.

The business logic inside the gherkin must be more flexible then and the java-code must correspond to different Web-Elements depending on that switch you set before.

You can either bild a gherkin-step-definition that covers all the domains (mobile, desktop), depending on a parameter given through the DSL gherkin or build own Sentences for each domain, e.g.:

Either (parameter driven):
Open the Startpage on the <domain> interface

OR:
Open the Startpage on the mobile interface
AND
Open the Startpage on the desktop interface

Method for parameter-driven:

@When ("^Open the Startpage on the (.*) interface$")
public void OpenTheStartpageOnTheInterface(String domain){
if(domain.equals("desktop"){
  driver.get("desktop.url");
}else if (domain.equals("mobile")){
  driver.get("mobile.url");
}

So i would either complexify the java methods to react to different domains or divide the testsuite in different vocabulary or even different projects.

slowlert
  • 21
  • 3