0

I have two cucumber features. Only one of them is tagged by tag @maximize which maximizes the browser window. I have also the hooks class which contains one @Before hook which should run only for tag @maximize.

But as I see this hook runs always regardless of tag definition in @Before annotation. If I remove the hook problem is gone. Here is the code of the hooks class:

package hooks;


import com.codeborne.selenide.Configuration;
import com.codeborne.selenide.WebDriverRunner;
import io.cucumber.java.After;
import io.cucumber.java.Before;
import org.openqa.selenium.WebDriver;


public class BaseHook
{

    @Before(order = 1)
    public void setup()
    {
        System.out.println("setup done");
    }


    // Also tried @Before(value="@maximize", order=2)
    @Before("@maximize", order=2)
    public void maximize()
    {
        Configuration.startMaximized = true;
    }


    @After
    public void tearDown()
    {
        WebDriver driver = WebDriverRunner.getWebDriver();
        driver.close();
        driver.quit();
    }

}
Čamo
  • 3,863
  • 13
  • 62
  • 114

1 Answers1

1

So the problem was not in the hook but in Configuration.startMaximized setting which persists in browser settings. It has to be removed in @After hook.

// Conf. has to be removed in @After otherwise it persists in browser settings.
@Before("@maximize")
public void maximizeOn()
{
    Configuration.startMaximized = true;
}


@After("@maximize")
public void maximizeOff()
{
    Configuration.startMaximized = false;
}
Čamo
  • 3,863
  • 13
  • 62
  • 114