serenity-bdd / serenity-core

Serenity BDD is a test automation library designed to make writing automated acceptance tests easier, and more fun.
http://serenity-bdd.info
Other
720 stars 518 forks source link

Using a custom WebDriver with Serenity #370

Closed RazvanB2 closed 8 years ago

RazvanB2 commented 8 years ago

Hi guys,

 I have a problem with using a custom InternetExplorerDriver in Serenity-Cucumber. The thing is that I need to set a couple of capabilities to true: 

capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true); capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

and I simply cannot make Serenity use this config at all. I've tried with serenity.properties; creating an @Managed custom driver but nothing seems to work. I really need some help. If there is anything unclear I can add more info. Thank you, Razvan

serenity.properties webdriver.driver = iexplorer webdriver.ie.driver=.\libs\IEDriverServer.exe serenity.driver.capabilities=INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS:true serenity.driver.capabilities=ACCEPT_SSL_CERTS:true

pom.xml `<?xml version="1.0" encoding="UTF-8"?> <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
<parent>
    <artifactId>serenity-archetypes</artifactId>
    <groupId>net.serenity-bdd</groupId>
    <version>1.1.19-SNAPSHOT</version>
</parent>
<groupId>SerenityAndCucumber</groupId>
<artifactId>SerenityAndCucumberProj</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Sample Serenity project using Cucumber and WebDriver</name>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <webdriver.driver>iexplorer</webdriver.driver>
    <webdriver.ie.driver>.\libs\IEDriverServer.exe</webdriver.ie.driver>
    <serenity.version>1.1.28</serenity.version>
    <serenity.cucumber.version>1.1.8</serenity.cucumber.version>
    <logback.version>1.1.3</logback.version>
    <serenity.properties>.\SerenityAndCucumberProj\serenity.properties</serenity.properties>
</properties>

<dependencies>
    <dependency>
        <groupId>net.serenity-bdd</groupId>
        <artifactId>serenity-core</artifactId>
        <version>1.1.26</version>
    </dependency>
    <dependency>
        <groupId>net.serenity-bdd</groupId>
        <artifactId>serenity-cucumber</artifactId>
        <version>1.1.5</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.assertj</groupId>
        <artifactId>assertj-core</artifactId>
        <version>1.7.0</version>
    </dependency>
    <dependency>
        <groupId>com.googlecode.lambdaj</groupId>
        <artifactId>lambdaj</artifactId>
        <version>2.3.3</version>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>${logback.version}</version>
    </dependency>
    <dependency>
        <groupId>net.serenity-bdd</groupId>
        <artifactId>serenity-jira-plugin</artifactId>
        <version>1.1.1</version>
    </dependency>
    <dependency>
        <groupId>net.serenity-bdd</groupId>
        <artifactId>serenity-jira-requirements-provider</artifactId>
        <version>1.1.1</version>
    </dependency>
    <!-- <dependency> <groupId>net.serenity-bdd.maven.plugins</groupId> <artifactId>serenity-maven-plugin</artifactId> 
        <version>1.1.28</version> </dependency> -->
</dependencies>
<build>
    <plugins>
        <!-- <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> 
            <version>2.18.1</version> <configuration> <skip>true</skip> </configuration> 
            </plugin> -->
        <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.18.1</version>
            <configuration>
                <includes>
                    <include>**/*.java</include>
                    <include>**/serenity.properties</include>
                </includes>
                <argLine>-Xmx512m</argLine>
                <threadCount>1</threadCount>
                <forkMode>none</forkMode>
                <systemPropertyVariables>
                    <!-- <webdriver.driver>${webdriver.driver}</webdriver.driver> -->
                    <webdriver.ie.driver>${webdriver.ie.driver}</webdriver.ie.driver>
                </systemPropertyVariables>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.2</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>net.serenity-bdd.maven.plugins</groupId>
            <artifactId>serenity-maven-plugin</artifactId>
            <version>1.1.28</version>

            <executions>
                <execution>
                    <id>serenity-reports</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>aggregate</goal>
                    </goals>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>net.serenity-bdd</groupId>
                    <artifactId>serenity-jira-plugin</artifactId>
                    <version>1.1.1</version>
                </dependency>

            </dependencies>
        </plugin>
    </plugins>
</build>

`

YamStranger commented 8 years ago

Thanks @Krusher21 for this issue and such detailed explanation.

YamStranger commented 8 years ago

Hello @Krusher21 It seems that you did not provide your capabilities in correct format: based on manual you should instead of:

serenity.driver.capabilities=INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS:true 
serenity.driver.capabilities=ACCEPT_SSL_CERTS:true

add next line to your property:

serenity.driver.capabilities=INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS:true;ACCEPT_SSL_CERTS:true

after processing capabilities they will be added to driver as:

capabilities.setCapability("INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS",true);
capabilities.setCapability("ACCEPT_SSL_CERTS",true);

How did you check what capabilities passed to you webdriver after initialization?

RazvanB2 commented 8 years ago

Hello @YamStranger,

Thank you for your quick reply; unfortunately the driver still seems to not load any property from serenity.properties file.

I've checked the capabilities that appear in the stack trace and more than that my goal is to make IE use websso and not ask for credentials every time I open a page.

Here is the loaded IE driver:

Command duration or timeout: 102 milliseconds Build info: version: '2.50.1', revision: 'd7fc91b29de65b790abb01f3ac5f7ea2191c88a7', time: '2016-01-29 11:11:26' System info: host: 'DEFRAVD825647', ip: '10.38.48.221', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_51' Driver info: org.openqa.selenium.ie.InternetExplorerDriver

Capabilities [{browserAttachTimeout=0, ie.enableFullPageScreenshot=true, enablePersistentHover=true, ie.forceCreateProcessApi=false, ie.forceShellWindowsApi=false, pageLoadStrategy=normal, ignoreZoomSetting=false, ie.fileUploadDialogTimeout=3000, version=11, platform=WINDOWS, proxy={proxyType=}, nativeEvents=true, ie.ensureCleanSession=false, elementScrollBehavior=0, ie.browserCommandLineSwitches=, requireWindowFocus=false, browserName=internet explorer, initialBrowserUrl=http://localhost:45391/, javascriptEnabled=true, ignoreProtectedModeSettings=false, enableElementCacheCleanup=true, unexpectedAlertBehaviour=dismiss}]

`

This how I'm figuring that the serenity.properties file is read by the framework:

09:22:12.378 [main] DEBUG n.thucydides.core.steps.StepEventBus - Test suite started for story net.thucydides.core.model.Story@e32d1ee5 09:22:12.409 [main] INFO n.t.c.u.PropertiesFileLocalPreferences - LOADING LOCAL PROPERTIES FROM C:\Users\boteraz\Serenity\serenity-maven-archetypes-master\SerenityAndCucumberProj\serenity.properties 09:22:12.417 [main] INFO n.t.c.u.PropertiesFileLocalPreferences - LOADING LOCAL PROPERTIES FROM C:\Users\boteraz\Serenity\serenity-maven-archetypes-master\SerenityAndCucumberProj\serenity.properties 09:22:12.417 [main] INFO n.t.c.u.PropertiesFileLocalPreferences - LOADING LOCAL PROPERTIES FROM C:\Users\boteraz\Serenity\serenity-maven-archetypes-master\SerenityAndCucumberProj\serenity.properties 09:22:12.456 [main] INFO n.t.c.u.PropertiesFileLocalPreferences - LOADING LOCAL PROPERTIES FROM C:\Users\boteraz\Serenity\serenity-maven-archetypes-master\SerenityAndCucumberProj\serenity.properties 09:22:12.456 [main] INFO n.t.c.u.PropertiesFileLocalPreferences - LOADING LOCAL PROPERTIES FROM C:\Users\boteraz\Serenity\serenity-maven-archetypes-master\SerenityAndCucumberProj\serenity.properties 09:22:12.456 [main] INFO n.t.c.u.PropertiesFileLocalPreferences - LOADING LOCAL PROPERTIES FROM C:\Users\boteraz\Serenity\serenity-maven-archetypes-master\SerenityAndCucumberProj\serenity.properties 09:22:12.456 [main] INFO n.t.c.u.PropertiesFileLocalPreferences - webdriver.driver=iexplorer 09:22:12.456 [main] INFO n.t.c.u.PropertiesFileLocalPreferences - serenity.driver.capabilities=INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS:true;ACCEPT_SSL_CERTS:true 09:22:12.456 [main] INFO n.t.c.u.PropertiesFileLocalPreferences - serenity.project.name=Demo Project using Serenity and Cucumber 09:22:12.456 [main] INFO n.t.c.u.PropertiesFileLocalPreferences - serenity.requirement.types=epic, feature 09:22:12.729 [main] INFO n.t.c.u.PropertiesFileLocalPreferences - LOADING LOCAL PROPERTIES FROM C:\Users\boteraz\Serenity\serenity-maven-archetypes-master\SerenityAndCucumberProj\serenity.properties 09:22:12.729 [main] INFO n.t.c.u.PropertiesFileLocalPreferences - LOADING LOCAL PROPERTIES FROM C:\Users\boteraz\Serenity\serenity-maven-archetypes-master\SerenityAndCucumberProj\serenity.properties 09:22:12.729 [main] INFO n.t.c.u.PropertiesFileLocalPreferences - LOADING LOCAL PROPERTIES FROM C:\Users\boteraz\Serenity\serenity-maven-archetypes-master\SerenityAndCucumberProj\serenity.properties 09:22:13.130 [main] DEBUG n.s.plugins.jira.JiraListener - JIRA LISTENER STATUS 09:22:13.130 [main] DEBUG n.s.plugins.jira.JiraListener - JIRA URL: null 09:22:13.130 [main] DEBUG n.s.plugins.jira.JiraListener - REPORT URL: null 09:22:13.130 [main] DEBUG n.s.plugins.jira.JiraListener - WORKFLOW ACTIVE: false 09:22:13.130 [main] INFO n.thucydides.core.steps.StepEventBus - Registering custom listener net.serenitybdd.plugins.jira.JiraListener@1a8898 09:22:13.130 [main] INFO net.serenitybdd.core.Serenity - Test Suite Started: Reflected Cross Site Scripting 09:22:13.193 [main] INFO net.serenitybdd.core.Serenity - `

--Razvan

YamStranger commented 8 years ago

@Krusher21 When you call in your code lines:

capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);

actually they processed like

capabilities.setCapability("ignoreProtectedModeSettings", true);

so, if you will use correct string values IE will accept them, otherwise IE will ignore them.

Please try to use string representation of your capabilities:

Here is how they look like: INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS ACCEPT_SSL_CERTS

Thanks!

YamStranger commented 8 years ago

It seems that this issue already fixed or not an issue any more.

ashishgodani commented 8 years ago

Infact I am also facing the same issue - I am using IE8

Is there an update to which version was it fixed in or any other workarounds ?

wakaleo commented 8 years ago

Could you explain what issue you are having exactly?

ashishgodani commented 8 years ago

Basically, even after adding the below line to serenity.properties: serenity.driver.capabilities=INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS:true;ACCEPT_SSL_CERTS:true

it still throws the SSL popup and gets stuck on that page.

For some a strange reason it doesnt even give an handle to accept the warnings by doing driver.navigate().to("javascript:document.getElementById('overridelink').click()");

wakaleo commented 8 years ago

Have you tried with native Selenium?

ashishgodani commented 8 years ago

well, we tried accepting SSL warning using vanilla cucumber and native selenium as well: driver.navigate().to("javascript:document.getElementById('overridelink').click()"); and it worked. Thats how we are working at the moment.