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

@BeforeMethod and @Page issue with TestNG #283

Closed
Forc3ment opened this Issue Aug 2, 2016 · 3 comments

Comments

Projects
None yet
3 participants
@Forc3ment

Forc3ment commented Aug 2, 2016

Hello, I have some trouble with TestNG.
I worked with JUnit and all went fine but i would like to go with TestNg and it seems that I have some trouble with the initialization of my page.

public class MyTest extends FluentTestNg {

        private WebDriver driver;

        @Page
        private CustomercareAMEA_Login page_Login;

        @BeforeMethod
        public void setUp() throws Exception {
                driver = new FirefoxDriver();

                driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
                logger = report.startTest("VerifyBlogTitle");
                connection();
        }
        @Test
        public void someTest() throws Exception {
                testSomething();
        }
        public void connection() throws InterruptedException {
                goTo(page_Login);

                page_Login.nameForm.text(id);
                page_Login.passwordForm.text(password);
                page_Login.submit.click();
        }
}

Then when i run my test I get :

java.lang.NullPointerException
at org.fluentlenium.core.Fluent.goTo(Fluent.java:325)
at org.fluentlenium.core.FluentPage.go(FluentPage.java:48)
at org.fluentlenium.core.Fluent.goTo(Fluent.java:305)
at selenium.MyTest.connection(MyTest.java:299)
...
In Fluent.java exception in goTo method declaration on line "getDriver().get(url);".

I tried to initialize the driver in different place and either I got this error or the driver was initialize outside the setup method and run once but was quit() after and so i can't run multiple test.

I don't understand why my page are not initialized with testNg when I initialize a new driver in the setUp method.

Do you have any idea on how to fix this ?

Ps: sorry fo my english, i tried my best but I don't speak English fluently.

@Toilal

This comment has been minimized.

Show comment
Hide comment
@Toilal

Toilal Aug 3, 2016

Member

Could you try to override getDefaultDriver() to create new FirefoxDriver() inside this, and then use getDriver() to retrieve the driver instance ?

Member

Toilal commented Aug 3, 2016

Could you try to override getDefaultDriver() to create new FirefoxDriver() inside this, and then use getDriver() to retrieve the driver instance ?

@Forc3ment

This comment has been minimized.

Show comment
Hide comment
@Forc3ment

Forc3ment Aug 3, 2016

I just tried and it worked ! Thanks you !!

Forc3ment commented Aug 3, 2016

I just tried and it worked ! Thanks you !!

@Forc3ment Forc3ment closed this Aug 3, 2016

@johncam1

This comment has been minimized.

Show comment
Hide comment
@johncam1

johncam1 Aug 21, 2016

Hi, I have a simular issue.

Without using test groups, solution propose by Toilal work indeed.
But if test methods are annotated with groups, the override getDefaultDriver() is not invoked.

So why ?

How can I get Driver when using testng groups ?

Thx u in advance

johncam1 commented Aug 21, 2016

Hi, I have a simular issue.

Without using test groups, solution propose by Toilal work indeed.
But if test methods are annotated with groups, the override getDefaultDriver() is not invoked.

So why ?

How can I get Driver when using testng groups ?

Thx u in advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment