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

@BrowserConfiguration not working with JUnit 5 @Nested annotation #1770

Open
mcollovati opened this issue Mar 13, 2024 · 0 comments
Open

@BrowserConfiguration not working with JUnit 5 @Nested annotation #1770

mcollovati opened this issue Mar 13, 2024 · 0 comments
Labels

Comments

@mcollovati
Copy link
Contributor

Currently, Testbench @BrowserConfiguration does not work correctly with JUnit @Nested annotation that is meant to work with not-static inner classes.

The problem is that when BrowserExtension.evaluateExecutionCondition evaluates whether the test should run or not, it tries to compute the requested capabilities; if the test class has a method annotated with @BrowserConfiguration, that method is supposed to be invoked to get the list of capabilities.
However, when BrowserExtension.evaluateExecutionCondition is called, the JUnit test context does not yet have a reference to the test class instance (e.g. ExtensionContext.getTestInstance()), so Testbench tries to create a new instance by reflection calling the default no-args constructor, but it fails because it does not exist (inner classes always take the enclosing class instance as parameter).

To reproduce run the following test, that will fail because the @BrowserConfiguration gets not called

public class MyTest {

    @Nested
    class MyNested extends BrowserTestBase {

        private boolean browserConfigInvoked;

        @BrowserConfiguration
        public List<DesiredCapabilities> getBrowserConfiguration() {
            browserConfigInvoked = true;
            return List.of(BrowserUtil.chrome());
        }

        @BrowserTest
        void simpleTest() {
            Assertions.assertTrue(browserConfigInvoked,
                    "Expecting getBrowserConfiguration() to be invoked");
        }
    }
}

If you do the same on a top-level class, it works

public class MyTest extends BrowserTestBase  {

    private boolean browserConfigInvoked;

    @BrowserConfiguration
    public List<DesiredCapabilities> getBrowserConfiguration() {
        browserConfigInvoked = true;
        return List.of(BrowserUtil.chrome());
    }

    @BrowserTest
    void simpleTest() {
        Assertions.assertTrue(browserConfigInvoked,
                "Expecting getBrowserConfiguration() to be invoked");
    }
}
@mcollovati mcollovati added the bug label Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: 🔖 Normal Priority (P2)
Development

No branches or pull requests

1 participant