SeleniumHQ / htmlunit-driver

WebDriver compatible driver for HtmlUnit headless browser.
Apache License 2.0
255 stars 86 forks source link

HTML Unit driver is always defaulting to IE8 #86

Open arjunkapur95 opened 4 years ago

arjunkapur95 commented 4 years ago

Hi so irrespective of me mentioning the browser version upon creating a HtmlDriver instance the driver is always defaulting to IE8

My Pom File `<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0
<groupId>basic-web-appJenkins</groupId>
<artifactId>jenkins</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>jenkins</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.6.RELEASE</version>
    <relativePath />
</parent>
<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.applitools</groupId>
        <artifactId>eyes-selenium-java3</artifactId>
        <version>RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.141.59</version>
    </dependency>
    <dependency>
        <groupId>org.freemarker</groupId>
        <artifactId>freemarker</artifactId>
        <version>2.3.23</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.7.4</version>
        <exclusions>
            <exclusion>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-core</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-annotations</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.7.4</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>2.7.4</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>htmlunit-driver</artifactId>
        <version>2.20</version>
    </dependency>
</dependencies>

<repositories>
    <repository>
        <id>spring-snapshots</id>
        <name>Spring Snapshots</name>
        <url>http://repo.spring.io/libs-snapshot-local</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>http://repo.spring.io/libs-milestone-local</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>spring-releases</id>
        <name>Spring Releases</name>
        <url>http://repo.spring.io/libs-release-local</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

`

My Test Case `@Test public void testLoginCorrectCredentialsCorrect() throws Exception {

    WebDriver webDriver = new HtmlUnitDriver(BrowserVersion.CHROME, true) {
        @Override
        protected WebClient modifyWebClient(WebClient client) {
            final WebClient webClient = super.modifyWebClient(client);
            // you might customize the client here
            webClient.getOptions().setCssEnabled(false);

           return webClient;
        }
    };

    webDriver.get("https://reflectionsstaging.optisolbusiness.com");// step 2 web driver navigation

    //ReflectionHome webElements = new ReflectionHome(webDriver);

    if (webDriver.getTitle().equals("Reflection"))// step 3 locating an element
    {
        System.out.println(webDriver.getPageSource());

        WebDriverWait wait = new WebDriverWait(webDriver,30);
        wait.until(ExpectedConditions.elementToBeClickable(By.name("email")));
        webDriver.findElement(By.name("email")).sendKeys("yopmail.com"); // step 4,5 wait for return from the                                                           // browser
        webDriver.findElement(By.name("password")).sendKeys("123");

        // driver.findElement(By.linkText("Inventory Master")).click();
        // driver.findElement(webElements.inventoryListItem).click();
    } else {
        fail("tes failed");

    }
}`

My Imports: import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.htmlunit.HtmlUnitDriver; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.WebClient;

The output I get from page source where I verify that IE8 was called(obtained by using the getpagesource function)

image

If you notice in this output that I have shared IE8 is the browser that is being called. I opened IE Edge and emulated to see that my site does indeed throw the above error message in IE8 only. Would someone have a look at it and let me know how i can go about fixing this.

rbri commented 4 years ago

To work together with Selenium 3.141.59 you need at least HtmlUnitDriver 2.33.3. But of course you it will be the best to use the latest HtmlUnitDriver version (at the moment 2.39.0).

Have a look at https://github.com/SeleniumHQ/htmlunit-driver/releases for more.

arjunkapur95 commented 4 years ago

To work together with Selenium 3.141.59 you need at least HtmlUnitDriver 2.33.3. But of course you it will be the best to use the latest HtmlUnitDriver version (at the moment 2.39.0).

Have a look at https://github.com/SeleniumHQ/htmlunit-driver/releases for more.

Hey rbri,

As per your suggestion, i updated my POM to 2.39.0 but I still default to IE8 .

I am not sure If I am doing something wrong but to replicate this i opened the website using IE8 emulation and I am getting the same error as before. Sharing Image for your reference.

image

Additionally sharing the Url for you to confirm if this issue persists on your end when you open the URL through HtmlUnitDriver.

https://reflectionsstaging.optisolbusiness.com/#!/login

rbri commented 4 years ago

Sorry, now i got your point. In your case i guess HtmlUnit & the Driver are doing the right thing but the page has some kind of browser checking. This is usually done based on some js feature checks. Will have a look if i can find the reason for this.