jeudi 18 mai 2017

Robot framework, Open Browser with command line flag to save browser log

I'm trying to save browser (chrome) log messages (React logs, js errors etc.) into a file in a robot framework test run. Apparently this is more difficult than it should be, as I couldn't find convenient API in robot framework to achieve this.

I figured out chrome could be started with --enable-logging --v=1 flag to direct log messages into a file. But how could I pass this flag via Open Browser keyword in robot framework? To be more precise, I'm actually using robotframework-maven-plugin to run the tests with headless browser on the remote server.

This is how test is currently started on the remote server from jenkins via execute remote shell task

rm -rf tests
git clone git@*****/tests.git && cd tests
Xvfb :99 -ac -screen 0 1280x1024x24 &
export DISPLAY=:99
mvn -DforceOpenJpaExecution=true -Dbrowser=chrome -Dserver=***** -DchromeDriverPath=/usr/local/bin/chromedriver clean verify

Here is the pom.xml of the test project

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://ift.tt/IH78KX"
         xmlns:xsi="http://ift.tt/ra1lAU"
         xsi:schemaLocation="http://ift.tt/IH78KX http://ift.tt/VE5zRx">
    <modelVersion>4.0.0</modelVersion>
    <groupId>*****</groupId>
    <artifactId>tests</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>tests</name>

    <dependencies>
        <dependency>
            <groupId>com.github.markusbernhardt</groupId>
            <artifactId>robotframework-selenium2library-java</artifactId>
            <version>1.4.0.8</version>
        </dependency>
    </dependencies>

    <build>
        <defaultGoal>verify</defaultGoal>        

        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>properties-maven-plugin</artifactId>
            <version>1.0-alpha-2</version>
            <executions>
                <execution>
                    <id>setPropertyChromeDriver</id>
                    <phase>integration-test</phase>
                    <goals>
                        <goal>set-system-properties</goal>
                    </goals>
                    <configuration>
                        <properties>
                            <property>
                              <name>webdriver.chrome.driver</name>
                              <value>${chromeDriverPath}</value>
                            </property>
                        </properties>
                    </configuration>
                </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.robotframework</groupId>
            <artifactId>robotframework-maven-plugin</artifactId>
            <version>${robotframework-maven-plugin.version}</version>
            <executions>
              <execution>
                <id>robotTest</id>  
                <phase>integration-test</phase>
                <goals>
                  <goal>run</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
    </build>

</project> 

And here is the excerpt from resource.robot

    Open the web application
        Open Browser    %{server}/App    %{browser}
        Maximize Browser Window
        Wait Until Page Contains        Login

Now, how could I pass the --enable-logging --v=1 to chrome driver, or is there more convenient way to dumb browser log to a file or test results?

Aucun commentaire:

Enregistrer un commentaire