Why does ChromeDriver keep logging to console? - selenium

I have a Java project that uses selenium and ChromeDriver to automate testing on my website. I have log4j2 and slf4j configured for my logging files. The driver however refuses to log into my files and uses the console instead:
Starting ChromeDriver 2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41) on port 41019
Only local connections are allowed.
log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Apr 20, 2018 12:31:42 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
What do I have to tweak in my logging settings so that the web driver logs into my logging files and not to console? My knowledge about logging is limited, sorry. An explanation what I did wrong would be appreciated.
I tried the following appenders in my log4j2.xml:
<logger name="org.openqa.selenium" level="all">
<AppenderRef ref="selenium"/>
</logger>
<logger name="webdriver.chrome" level="all">
<AppenderRef ref="webdriverChrome"/>
</logger>
<logger name="org.apache.http.client.protocol.RequestAddCookies" level="all">
<AppenderRef ref="webdriverChrome"/>
</logger>
<logger name="org.seleniumhq.selenium.selenium-chrome-driver" level="all">
<AppenderRef ref="webdriverChrome"/>
</logger>
My maven pom.xml:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.22</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.22</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>htmlunit-driver</artifactId>
<version>2.24</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-chrome-driver -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>3.4.0</version>
</dependency>

I found this half baked solution. Use this code when you initialize the web/chrome driver:
Properties log4jProp = new Properties();
log4jProp.setProperty("log4j.rootLogger", "WARN");
PropertyConfigurator.configure(log4jProp);
System.setProperty("webdriver.chrome.logFile", ".//log//webdriverChrome_1.log");
System.setProperty("webdriver.chrome.driver", ".\\path\\to\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(waitInMilliseconds, TimeUnit.MILLISECONDS);
It only removes the warning for the logging framework. I am satisfied to a degree. If anyone knows the answer to get the rest of the console message into a logger would be appreciated.
The result so far:
Starting ChromeDriver 2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41) on port 41019
Only local connections are allowed.
Apr 20, 2018 12:31:42 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS

Related

How can I implement log4j2 (2.14.0) 'JSON Template Layout' in a mule application?

Log4j2 has implemented a 'JSON Template Layout'. I have been able to implemented this in a standard maven java application, however I am not able to implement it in a Mule 4.3 application. I have added the log4j2 (2.14.0) dependencies to my POM:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.14.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.14.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-layout-template-json</artifactId>
<version>2.14.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.12.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.12.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.12.1</version>
</dependency>
Log4j2 Appender Config
<Appenders>
<Console name="CONSOLE" target="SYSTEM_OUT">
<JsonTemplateLayout />
</Console>
</Appenders>
And I see that they are loaded in the log, but I get an error:
2021-02-06 07:17:39,175 WrapperListener_start_runner DEBUG Building Plugin[name=layout, class=org.apache.logging.log4j.layout.template.json.JsonTemplateLayout].
2021-02-06 07:17:39,179 WrapperListener_start_runner ERROR Could not create plugin of type class org.apache.logging.log4j.layout.template.json.JsonTemplateLayout for element JsonTemplateLayout: java.util.UnknownFormatConversionException: Conversion = 'interface org.apache.logging.log4j.layout.template.json.util.RecyclerFactory' java.util.UnknownFormatConversionException: Conversion = 'interface org.apache.logging.log4j.layout.template.json.util.RecyclerFactory'
at org.apache.logging.log4j.core.config.plugins.convert.TypeConverterRegistry.findCompatibleConverter(TypeConverterRegistry.java:103)
at org.apache.logging.log4j.core.config.plugins.convert.TypeConverters.convert(TypeConverters.java:412)
at org.apache.logging.log4j.core.config.plugins.visitors.AbstractPluginVisitor.convert(AbstractPluginVisitor.java:151)
Is Mule somehow dynamically loading an older version of log4j2 that does not implement the 'JSON Template Layout'?
Mule 4 provides log4j2 to applications. It is one of few libraries that actually may override application's libraries in Mule 4. You should use what is provided. Do not try to change any provided libraries with different versions, that is not supported.

Change default logging implementation in Helidon

I would like to use log4j with Helidon. Is there any way to change default logging implementation?
In Helidon, we have decided to use to use Java Util Logging (JUL), to allow our users to choose any logging implementation.
There are bridges for most implementations for JUL. For log4j, you can have a look at this page:
http://people.apache.org/~psmith/logging.apache.org/sandbox/jul-log4j-bridge/examples.html
With Helidon 2.0 you will need:
Add dependency log4j2
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.13.3</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.13.3</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jul</artifactId>
<version>2.13.3</version>
</dependency>
when start your application, add this variables using external configuration log4j:
-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager
-Dlog4j.configurationFile=file:/conf/log4j2.xml
java -Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager
-Dlog4j.configurationFile=file:/conf/log4j2.xml -jar target/your-app.jar
Or when your log4j2.xml is inside src/main/resources/log4j2.xml
-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager
java -Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager -jar target/your-app.jar
Example log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="info">
<Appenders>
<Console name="LogToConsole" target="SYSTEM_OUT">
<PatternLayout>
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %p %c{1.} %m%n</Pattern>
</PatternLayout>
</Console>
</Appenders>
<Loggers>
<Logger name="io.helidon" level="info" additivity="false">
<AppenderRef ref="LogToConsole" />
</Logger>
<Root level="info" additivity="false">
<AppenderRef ref="LogToConsole" />
</Root>
</Loggers>
</Configuration>

Arquillian + ear + wildfly in remote container = NoSuchMethodError

I have an ear created with ShrinkWrap. I'm trying to run AQ tests on remote (dockered) wildfly 12 container. WF is deployed properly, necessary ports are opened and available. While trying to run tests I get:
16:05:42,922 TRACE [listener] Invoking listener org.jboss.remoting3.remote.RemoteConnection$RemoteWriteListener#56babcc2 on channel org.xnio.conduits.ConduitStreamSinkChannel#34dcf94b
16:05:42,924 ERROR [listener] XNIO001007: A channel event listener threw an exception
java.lang.NoSuchMethodError: org.jboss.remoting3._private.Messages.tracef(Ljava/lang/String;J)V
at org.jboss.remoting3.remote.RemoteConnection$RemoteWriteListener.handleEvent(RemoteConnection.java:275)
at org.jboss.remoting3.remote.RemoteConnection$RemoteWriteListener.handleEvent(RemoteConnection.java:243)
at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)
at org.xnio.conduits.WriteReadyHandler$ChannelListenerHandler.writeReady(WriteReadyHandler.java:65)
at org.xnio.nio.NioSocketConduit.handleReady(NioSocketConduit.java:94)
at org.xnio.nio.WorkerThread.run(WorkerThread.java:571)
and have no clue how to deal with it.
I'm using:
<dependency>
<groupId>org.wildfly.arquillian</groupId>
<artifactId>wildfly-arquillian-container-remote</artifactId>
<version>2.1.0.Final</version>
<scope>test</scope>
</dependency>
...
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.4.1.Final</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
Any clues?

Splunk log4j2 plugin not working in mule application

I have a requirement to send all mule logs to splunk, so for this i am using splunks Http Event collector mentioned here http://dev.splunk.com/view/event-collector/SP-CAAAE6M
for this i have configured appender in log4j2 xml file as
<Http name="SPLUNK"
url="https://localhost:8088"
token="4B916A8F-C41E-4DD3-80AC-778D3E24F45C" batch_size_bytes="0"
batch_size_count="0" batch_interval="0" disableCertificateValidation="true">
<PatternLayout pattern="%m" />
</Http>
<Logger name="splunk.log4j" level="INFO">
<AppenderRef ref="SPLUNK" />
</Logger>
i have added following libraries in pom file
<dependency>
<groupId>com.splunk.logging</groupId>
<artifactId>splunk-library-javalogging</artifactId>
<version>1.5.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
</dependency>
i know for this to work i need to add splunk jar in /lib/boot so i have copied following jars in /lib/boot
/lib/boot/splunk-1.5.0.0.jar
/lib/boot/splunk-library-javalogging-1.5.2.jar
but even after that when i deploy to standalone server i get following error but surprisingly it works fine in Studio and not in standalone server.
2017-12-11 14:26:12,771 WrapperListener_start_runner ERROR Unable to invoke factory method in class class com.splunk.logging.HttpEventCollectorLog4jAppender for element Http.
2017-12-11 14:26:12,771 WrapperListener_start_runner ERROR Null object returned for Http in Appenders.
2017-12-11 14:26:12,775 WrapperListener_start_runner ERROR Unable to locate appender "SPLUNK" for logger config "splunk.log4j"
does any one know why is this happening?
ERROR Unable to locate appender "SPLUNK" for logger config "splunk.log4j"
This means there is no Appender named "SPLUNK" configured. Make sure your log4j2.xml contains such configuration, for example to output log to console:
<Appenders>
<Console name="SPLUNK" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %c{1} - %msg%n"/>
</Console>
</Appenders>
See the Configuring Appenders and Appenders doc for details.

Using Arquillian Drone with Selenium Grid

I have created a suite of functional UI tests for my web based application using Arquillian Done which I would like to run on a Selenium Grid as opposed to running them locally.
The problem I've got that despite setting the host/port details for the Selenium hub server in the arquillian.xml file, the UI tests are executed locally rather than on one of the Selenium nodes. I've even tried entering the details for a host that doesn't exist but the tests are still run locally and there are no error messages generated. It appears as though Drone is ignoring the configuration in the arquillian.xml file.
Is there something wrong with my configuration in the arquillian.xml file, or is there something else I'm doing wrong? Unfortunately there seems to be very little documentation on using Arquillian Drone with Selenium Grid.
The content of the arquillian.xml file is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<arquillian xmlns="http://jboss.org/schema/arquillian"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
<extension qualifier="webdriver">
<property name="browser">${arquillian.browser}</property>
<property name="remoteAddress">http://selenium-hub:4444</property>
</extension>
<extension qualifier="selenium-server">
<property name="host">selenium-hub</property>
<property name="port">4444</property>
<property name="skip">true</property>
</extension>
<container qualifier="arquillian-glassfish-remote">
<configuration>
...
</configuration>
</container>
</arquillian>
My Maven pom.xml file contains the following dependency and dependencyManagement sections:
<dependencies>
<!-- Various Java EE and Internal Dependencies -->
<!-- Test Dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.graphene</groupId>
<artifactId>graphene-webdriver</artifactId>
<version>2.0.3.Final</version>
<type>pom</type>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.1.8.Final</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.selenium</groupId>
<artifactId>selenium-bom</artifactId>
<version>2.46.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.extension</groupId>
<artifactId>arquillian-drone-bom</artifactId>
<version>1.3.1.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
It appears there were two issues preventing the Arquillian Drone tests being executed against a Selenium Grid.
The first issue is that the webdriver section of the arquillian.xml file needs to include either <property name="remote">true</property> or <property name="remoteReusable">true</property> in addition to the remoteAddress property. Without either the remote or remoteReusable then the tests will be run locally.
The second issue was that the remoteAddress did not contain the full URL for the Selenium Grid hub server. The property should be set to <property name="remoteAddress">http://selenium-hub:4444/wd/hub</property>. Obviously selenium-hub needs to be set to the hostname of your Selenium hub server. What through me was accessing this URL via a browser returned a NullPointerException however this appears to be normal behaviour as there are other parameters set when the URL is accessed correctly.
In addition the selenium-server section of the arquillian.xml file appears to be unnecessary.