kazurayam / selenium-webdriver-java

Examples of the O'Reilly book "Hands-On Selenium WebDriver with Java"
https://oreil.ly/1E7CX
Apache License 2.0
0 stars 0 forks source link

TestNG makes `System.getProperty("user.dir")` to return the parent project's root directory, which is wrong. #22

Open kazurayam opened 10 months ago

kazurayam commented 10 months ago

I made a tag issue22 to reproduce this problem. You can checkout the issue22 tag and see on your machine.


I ran:

:~/github/selenium-webdriver-java ((issue22) +)
$ ./gradlew -q :selenium-webdriver-testng:test --tests="*ch05.cdp.FullPageScreenshot*"

I expected that a file fullpage-screenshot-chrome.png will be written into the subproject's root directory. So I exected find a file

However, in fact, I found the fullpage-screenshot-chrome.png file is written into the parent project's root directory, as shown in the following tree.

$ tree -L 1
.
├── LICENSE
├── README.md
├── alternatives
├── build
├── docs
├── fullpage-screenshot-chrome.png    <==== why this file is written here ?!
├── fullpage-screenshot-firefox.png   <==== why this file is written here ?!
├── gradle
├── gradlew
├── gradlew.bat
├── pom.xml
├── selenium-ide
├── selenium-webdriver-junit4
├── selenium-webdriver-junit5
├── selenium-webdriver-junit5-seljup
├── selenium-webdriver-testng
└── settings.gradle

10 directories, 8 files

I don't think I can solve this problem. It's too weired. I have no clue.

kazurayam commented 10 months ago

A related topic in the Gradle Frorums:

https://discuss.gradle.org/t/how-do-i-set-the-working-directory-for-testng-in-a-multi-project-gradle-build/7379

kazurayam commented 10 months ago

I have developed the following library:

unittest-helper project

It contains the com.kazurayam.unittest.TestOutputOrganizer class which can resolve the project directory via the classpath on which the test class is found upon.