1
votes

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://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">
    <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?

I found this piece of code to set the flags, but I have no idea how to apply it in keyword based resource in my case

from selenium import webdriver
options = webdriver.ChromeOptions()
# set some options
# for example:
# options.add_argument('--disable-logging')
driver = webdriver.Remote(desired_capabilities=options.to_capabilities())
2

2 Answers

1
votes

When you need to pass options to webdriver with Selenium2Library you should use the keyword Create Webdriver (and later Go To url).

0
votes

In a previous SO question I provided an answer that should apply here as well

*** Settings ***
Library    Selenium2Library
*** Test Cases ***

Log Chrome Console
      ${c_opts} =  Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver
      Call Method     ${c_opts}   add_argument             enable-logging 
      Call Method     ${c_opts}   add_argument             v\=1
      Create Webdriver    Chrome    crm_alias    chrome_options=${c_opts}
      Go To    http://www.url.com
      [Teardown]  Close All Browsers

This adds the arguments to the command line of Chrome.