Marco
Marco

Reputation: 508

WebDriverManager for PhantomJSDriver not working

I cannot get WebDriverManager to work. I would like to use PhantomJSDriver without having to set a system property like this:

System.setProperty("phantomjs.binary.path", "E:/phantomjs-2.1.1-windows/bin/phantomjs.exe");

I have these dependencies in my pom.xml:

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-server</artifactId>
    <version>3.0.1</version>
    </dependency>
<dependency>
    <groupId>io.github.bonigarcia</groupId>
    <artifactId>webdrivermanager</artifactId>
    <version>1.5.1</version>
</dependency>

This is my code/test:

import static org.junit.Assert.assertEquals;
import org.junit.Test;

public class TestA {

    WebDriver driver;

    @BeforeClass
    public static void setupClass() {
        PhantomJsDriverManager.getInstance().setup();
    }

    @Before
    public void setUp() {
        driver = new PhantomJSDriver();
    }

    @Test
    public void test() {
        driver.get("https://www.google.de/");
        System.out.println(driver.getTitle());
        assertEquals("Google", driver.getTitle());
    }
}

The test fails:

org.junit.ComparisonFailure: expected:<[Google]> but was:<[]>

Does anybody know what I am doing wrong? Thanks in advance!


UPDATE: Now I have another problem. Before using the webdrivermanager I had this:

DesiredCapabilities dc = DesiredCapabilities.phantomjs();
dc.setJavascriptEnabled(true);
dc.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS,
                new String[] { "--web-security=no", "--ignore-ssl-errors=yes" });

System.setProperty("phantomjs.binary.path", "E:/phantomjs-2.1.1-windows/bin/phantomjs.exe");
WebDriver driver = new PhantomJSDriver(dc);

Now, when I delete the line with System.setProperty(...), it is not working anymore. Thanks for helping.

Upvotes: 0

Views: 554

Answers (1)

Cathal
Cathal

Reputation: 1338

Looks like your making the assertion to early, so the page is not loaded when you call getTitle() on it. What does your println print out?

Try adding a wait to to your test, if you know the page title should be "Google" then why not wait for that to be true before doing any further assertions? When the page title is equal to what your expecting you can be reasonably confident the page is loaded. Try this:

public Boolean waitForPageIsLoaded(String title) {
    return new WebDriverWait(driver, 10).until(ExpectedConditions.titleIs(title));
}

Upvotes: 3

Related Questions