0

I'm trying to set up a UI testing framework on a project using Selenium in JUnit tests inside of Testcontainers, using IntelliJ IDE to develop. I am using OpenJDK 12.0.1

I have the most basic test that I can think of, but I keep getting Null Pointer Exceptions when trying to get ANY website (wikipedia, google, etc.)

Am I missing something crucial here?

Here is the test that I have set up:

public class SimpleTest {

 @Rule
 public BrowserWebDriverContainer chrome = new BrowserWebDriverContainer()
  .withCapabilities(new ChromeOptions());

 @Test
 public void simplePlainSeleniumTest() {
  RemoteWebDriver driver = chrome.getWebDriver();

  driver.get("https://google.com");

  assertTrue("This should always pass", true);
 }

}

In my gradle file I am importing the following:

compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.141.59'
compile group: 'org.seleniumhq.selenium', name: 'selenium-remote-driver', version: '3.141.59'
testCompile group: 'org.testcontainers', name: 'selenium', version: '1.11.3'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.2.0'
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.2.0'
test {
    useJUnitPlatform()
}

I have no special settings in my testcontainers.properties file

If I am understanding all of the examples I have seen, this should be:

  1. Opening the test inside a docker container via testcontainers.
  2. Creating a driver for Chrome inside of that container.
  3. Navigating to the given website (in the example above, google.com)
  4. Passing, because true = true

But I run into the following error no matter what I am changing code-wise:

selenium.SimpleTest > simplePlainSeleniumTest() FAILED
    java.lang.NullPointerException at SimpleTest.java:34

Line 34 is: driver.get("https://google.com");

Tenusha Guruge
  • 2,147
  • 3
  • 18
  • 38
phillter
  • 3
  • 1
  • can you share the full stack trace? – Adi Ohana Jun 14 '19 at 05:06
  • How are you building the project? It looks like the rule isn't firing to set chrom, so maybe this is relevant: https://stackoverflow.com/questions/18364859/junit-rule-not-being-executed-when-test-fails – racraman Jun 14 '19 at 05:14

1 Answers1

1

You're using JUnit Jupiter which does not support rules. There is a separate Jupiter support in Testcontainers, see the following page: https://www.testcontainers.org/test_framework_integration/junit_5/

Basically, you need to add org.testcontainers:junit-jupiter:1.11.3 dependency, annotate your test class with @Testcontainers and replace @Rule with @Container.

bsideup
  • 2,845
  • 17
  • 21