java – 在play框架中使用带有selenium webdriver的黄瓜时调试日志

我正在尝试将cucumber-jvm与selenium webdriver(firefox)集成,但是在我现在运行我的测试后,我看到很多来自selenium的调试日志.

这是我目前的结构.

《java – 在play框架中使用带有selenium webdriver的黄瓜时调试日志》

我的build.sbt依赖项添加了:

  "info.cukes" % "cucumber-java" % "1.2.4",
  "info.cukes" % "cucumber-junit" % "1.2.4",
  "info.cukes" % "cucumber-picocontainer" % "1.2.4",
  "org.seleniumhq.selenium" % "selenium-java" % "2.48.2"

软件代表:

Centos 6 64bit.
Firefox "Mozilla Firefox 31.3.0"
Java java version "1.8.0_45" (build 1.8.0_45-b13)

FirefoxDriver实例化:

@Before
public void setUp() throws Exception {
    if (driver == null) {
        driver = new FirefoxDriver();
        driver.navigate().to(base_url);
        driver.manage().deleteAllCookies();
   }
}

Junit Runner:

@RunWith(Cucumber.class)
@CucumberOptions(
    features="test/acceptance/features",
    glue={"context"},
    plugin={"html:cucumberReport"}
)
public class CucumberRunnerTest {
}

我如何运行测试:

./activator clean compile test

我得到的日志类型:

16:11:54.212 [Forwarding newSession on session null to remote] DEBUG o.a.h.c.protocol.RequestAddCookies - CookieSpec selected: default
16:11:54.213 [Forwarding newSession on session null to remote] DEBUG o.a.h.c.protocol.RequestAuthCache - Auth cache not set in the context
16:11:54.213 [Forwarding newSession on session null to remote] DEBUG o.a.h.i.c.PoolingHttpClientConnectionManager - Connection request: [route: {}->http://127.0.0.1:7056][total kept alive: 0; route allocated: 0 of 2000; total allocated: 0 of 2000]
16:11:54.213 [Forwarding newSession on session null to remote] DEBUG o.a.h.i.c.PoolingHttpClientConnectionManager - Connection leased: [id: 16][route: {}->http://127.0.0.1:7056][total kept alive: 0; route allocated: 1 of 2000; total allocated: 1 of 2000]
16:11:54.213 [Forwarding newSession on session null to remote] DEBUG o.a.h.impl.execchain.MainClientExec - Opening connection {}->http://127.0.0.1:7056
16:11:54.213 [Forwarding newSession on session null to remote] DEBUG o.a.h.i.c.DefaultHttpClientConnectionOperator - Connecting to /127.0.0.1:7056
16:11:54.214 [Forwarding newSession on session null to remote] DEBUG o.a.h.i.c.DefaultHttpClientConnectionOperator - Connection established 127.0.0.1:39264<->127.0.0.1:7056
16:11:54.214 [Forwarding newSession on session null to remote] DEBUG o.a.h.i.c.DefaultManagedHttpClientConnection - http-outgoing-16: set socket timeout to 10800000
16:11:54.214 [Forwarding newSession on session null to remote] DEBUG o.a.h.impl.execchain.MainClientExec - Executing request POST /hub/session HTTP/1.1
16:11:54.214 [Forwarding newSession on session null to remote] DEBUG o.a.h.impl.execchain.MainClientExec - Target auth state: UNCHALLENGED
16:11:54.214 [Forwarding newSession on session null to remote] DEBUG o.a.h.impl.execchain.MainClientExec - Proxy auth state: UNCHALLENGED
16:11:54.215 [Forwarding newSession on session null to remote] DEBUG org.apache.http.headers - http-outgoing-16 >> POST /hub/session HTTP/1.1
16:11:54.215 [Forwarding newSession on session null to remote] DEBUG org.apache.http.headers - http-outgoing-16 >> Content-Type: application/json; charset=utf-8
16:11:54.215 [Forwarding newSession on session null to remote] DEBUG org.apache.http.headers - http-outgoing-16 >> Content-Length: 105
16:11:54.215 [Forwarding newSession on session null to remote] DEBUG org.apache.http.headers - http-outgoing-16 >> Host: 127.0.0.1:7056
16:11:54.215 [Forwarding newSession on session null to remote] DEBUG org.apache.http.headers - http-outgoing-16 >> Connection: Keep-Alive
16:11:54.215 [Forwarding newSession on session null to remote] DEBUG org.apache.http.headers - http-outgoing-16 >> User-Agent: Apache-HttpClient/4.5.1 (Java/1.8.0_45)
16:11:54.215 [Forwarding newSession on session null to remote] DEBUG org.apache.http.headers - http-outgoing-16 >> Accept-Encoding: gzip,deflate
16:11:54.215 [Forwarding newSession on session null to remote] DEBUG org.apache.http.wire - http-outgoing-16 >> "POST /hub/session HTTP/1.1[\r][\n]"
16:11:54.215 [Forwarding newSession on session null to remote] DEBUG org.apache.http.wire - http-outgoing-16 >> "Content-Type: application/json; charset=utf-8[\r][\n]"
16:11:54.215 [Forwarding newSession on session null to remote] DEBUG org.apache.http.wire - http-outgoing-16 >> "Content-Length: 105[\r][\n]"
16:11:54.215 [Forwarding newSession on session null to remote] DEBUG org.apache.http.wire - http-outgoing-16 >> "Host: 127.0.0.1:7056[\r][\n]"
16:11:54.215 [Forwarding newSession on session null to remote] DEBUG org.apache.http.wire - http-outgoing-16 >> "Connection: Keep-Alive[\r][\n]"
16:11:54.215 [Forwarding newSession on session null to remote] DEBUG org.apache.http.wire - http-outgoing-16 >> "User-Agent: Apache-HttpClient/4.5.1 (Java/1.8.0_45)[\r][\n]"
16:11:54.215 [Forwarding newSession on session null to remote] DEBUG org.apache.http.wire - http-outgoing-16 >> "Accept-Encoding: gzip,deflate[\r][\n]"
16:11:54.215 [Forwarding newSession on session null to remote] DEBUG org.apache.http.wire - http-outgoing-16 >> "[\r][\n]"
16:11:54.216 [Forwarding newSession on session null to remote] DEBUG org.apache.http.wire - http-outgoing-16 >> "{"desiredCapabilities":{"browserName":"firefox","version":"","platform":"ANY"},"requiredCapabilities":{}}"
16:11:54.307 [Forwarding newSession on session null to remote] DEBUG org.apache.http.wire - http-outgoing-16 << "HTTP/1.1 200 OK[\r][\n]"
16:11:54.307 [Forwarding newSession on session null to remote] DEBUG org.apache.http.wire - http-outgoing-16 << "content-type: application/json; charset=UTF-8[\r][\n]"
16:11:54.307 [Forwarding newSession on session null to remote] DEBUG org.apache.http.wire - http-outgoing-16 << "connection: close[\r][\n]"
16:11:54.308 [Forwarding newSession on session null to remote] DEBUG org.apache.http.wire - http-outgoing-16 << "content-length: 421[\r][\n]"
16:11:54.308 [Forwarding newSession on session null to remote] DEBUG org.apache.http.wire - http-outgoing-16 << "server: httpd.js[\r][\n]"
16:11:54.308 [Forwarding newSession on session null to remote] DEBUG org.apache.http.wire - http-outgoing-16 << "date: Thu, 10 Dec 2015 16:11:54 GMT[\r][\n]"
16:11:54.308 [Forwarding newSession on session null to remote] DEBUG org.apache.http.wire - http-outgoing-16 << "[\r][\n]"
16:11:54.308 [Forwarding newSession on session null to remote] DEBUG org.apache.http.headers - http-outgoing-16 << HTTP/1.1 200 OK
16:11:54.308 [Forwarding newSession on session null to remote] DEBUG org.apache.http.headers - http-outgoing-16 << content-type: application/json; charset=UTF-8
16:11:54.308 [Forwarding newSession on session null to remote] DEBUG org.apache.http.headers - http-outgoing-16 << connection: close
16:11:54.308 [Forwarding newSession on session null to remote] DEBUG org.apache.http.headers - http-outgoing-16 << content-length: 421
16:11:54.308 [Forwarding newSession on session null to remote] DEBUG org.apache.http.headers - http-outgoing-16 << server: httpd.js
16:11:54.308 [Forwarding newSession on session null to remote] DEBUG org.apache.http.headers - http-outgoing-16 << date: Thu, 10 Dec 2015 16:11:54 GMT
16:11:54.310 [Forwarding newSession on session null to remote] DEBUG org.apache.http.wire - http-outgoing-16 << "{"name":"newSession","sessionId":"d1aa222a-0c82-46a6-a0dd-80942dc13274","status":0,"value":{"cssSelectorsEnabled":true,"browserName":"firefox","handlesAlerts":true,"javascriptEnabled":true,"nativeEvents":false,"platform":"Linux","rotatable":false,"takesScreenshot":true,"version":"31.3.0","webStorageEnabled":true,"applicationCacheEnabled":true,"databaseEnabled":true,"locationContextEnabled":true,"acceptSslCerts":true}}"
16:11:54.310 [Forwarding newSession on session null to remote] DEBUG o.a.h.i.c.DefaultManagedHttpClientConnection - http-outgoing-16: Close connection
16:11:54.310 [Forwarding newSession on session null to remote] DEBUG o.a.h.impl.execchain.MainClientExec - Connection discarded
16:11:54.310 [Forwarding newSession on session null to remote] DEBUG o.a.h.i.c.PoolingHttpClientConnectionManager - Connection released: [id: 16][route: {}->http://127.0.0.1:7056][total kept alive: 0; route allocated: 0 of 2000; total allocated: 0 of 2000]

我是jvm-cucumber的新手,请玩,如果有人可以帮助我,我会很高兴:)
如果我有新的东西,我会告诉你.

更新:

我不知道为什么,但“Before”和“Given”子句不打印任何调试日志.任何其他做.

最佳答案 对于我的带有黄瓜和webdriver的Maven项目,解决方案是将文件添加到“/resources/logback.xml”,其内容与如下相同.

所以它应该能够为playframework做同样的事情.使用内容创建“conf / resources / logback.xml”:

<configuration debug="false">
  <!-- definition of appender STDOUT -->
  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%-4relative [%thread] %-5level %logger{35} - %msg %n</pattern>
    </encoder>
  </appender>

  <root level="ERROR">
    <!-- appender referenced after it is defined -->
    <appender-ref ref="STDOUT"/>
  </root> 
</configuration>

(来源:https://stackoverflow.com/a/8936580/2827420)

点赞