iainrose / page-objects

A basic framework for running automated tests using WebDriver w Java, TestNG & Gradle
29 stars 27 forks source link

Only runs on Firefox #1

Closed lidiam closed 12 years ago

lidiam commented 12 years ago

Hi

Thank you for posting this sample! Runs great on Windows out of the box, however I cannot get it to run on any other browser.

I tried running on Chrome and IE, but no matter what browser I specify on the command line, it always executed on Firefox. E.g. tried:

gradle.bat -d clean test -DBROWSER=chrome and gradle.bat -d clean test -DBROWSER=internetExplorer

When I removed "firefox" from Browser property in BaseTest.java, as in:

protected static final String BROWSER = System.getProperty("BROWSER");

and tried with internetExplorer, I got null pointer exception:

java.lang.NullPointerException at BaseTest.suiteSetup(BaseTest.java:42) at org.gradle.api.internal.tasks.testing.testng.TestNGTestClassProcessor.stop(TestNGTestClassProcessor.java:103) at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:58)

The exception is on this line:

    } else if (BROWSER.equals("firefox")) {

Looks like BROWSER is null, so the property was not passed to BaseTest from command line.

On a somewhat related note, I tried adding System.out.println statements in ExampleTest.java to see what browser it would print, but my print statements were lost, i.e. never show up on command line. I used testng Reporter to print the message, but am just wondering how to print messages on command line in your setup.

Thanks Lidia

iainrose commented 12 years ago

Hi there,

Thanks for the interest in this project. Sorry you've had some problems.

I think I know what the issue is, I have a solution but it's a bit of a hack. If you know of a cleaner way please let me know.

The problem seems to be related to how you tell gradle which system parameters can be overwritten from the command line. So if we don't set a default value for BROWSER in build.gradle, we cannot override that property. What's worse is that I cannot seem to do this and make it apply to all tasks so I need to add a default value for this system property for every task. This seems like a huge duplication to me and I'm still searching for a solution.

In the meantime, try updating the build.gradle file with the following ...

Before:

test { useTestNG() maxParallelForks = 20 }

After:

test { useTestNG() maxParallelForks = 20 systemProperties = [ BROWSER: System.getProperty('BROWSER', 'firefox') ] }

Like I said, it's a hack and I hate having this duplicated but until I find an alternative it will get you moving

iainrose commented 12 years ago

I just pushed an update that should fix the problem. Please let me know if if fixes the issue for you and / or if you can see a cleaner way to fix it

lidiam commented 12 years ago

While not ideal - it works. :-)

iainrose commented 12 years ago

@lidiam I've found a better solution for this

Take a look at this question on the gradle forums and the updated build.gradle file in this repo

http://forums.gradle.org/gradle/topics/how_should_i_be_handling_passing_system_properties_from_gradle_to_my_tests

lidiam commented 12 years ago

Thanks for the follow up! Btw, I had to use the following dependencies to get reportng working:

dependencies { compile "org.seleniumhq.selenium:selenium-java:2.21.0" compile "org.testng:testng:6.3.1" // dependency needed by reportng compile group: 'com.google.inject', name: 'guice', version: '3.0' compile ("org.uncommons:reportng:1.1.2") { exclude group: "org.testng", module: "testng" } }

Also at http://stackoverflow.com/questions/10219436/using-selenium-testng-and-reportng-with-gradle/10523602

Lidia

On Wed, May 9, 2012 at 10:09 AM, Iain Rose < reply@reply.github.com

wrote:

I've found a better solution for this.

See this question on the gradle forums and the updated build.gradle file in this repo

http://forums.gradle.org/gradle/topics/how_should_i_be_handling_passing_system_properties_from_gradle_to_my_tests


Reply to this email directly or view it on GitHub: https://github.com/iainrose/page-objects/issues/1#issuecomment-5605565

iainrose commented 12 years ago

Very cool, I struggled with that myself and gave up a few weeks ago. I've updated build.gradle and pushed again