Class AppiumDriverLocalService
- java.lang.Object
-
- org.openqa.selenium.remote.service.DriverService
-
- io.appium.java_client.service.local.AppiumDriverLocalService
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public final class AppiumDriverLocalService extends org.openqa.selenium.remote.service.DriverService
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addLogMessageConsumer(java.util.function.Consumer<java.lang.String> consumer)
When a complete log message is available (from server output data), the specifiedConsumer
is invoked with that log message.void
addOutPutStream(java.io.OutputStream outputStream)
Adds other output stream which should accept server output data.void
addOutPutStreams(java.util.List<java.io.OutputStream> outputStreams)
Adds other output streams which should accept server output data.void
addSlf4jLogMessageConsumer(java.util.function.BiConsumer<java.lang.String,Slf4jLogMessageContext> slf4jLogMessageConsumer)
When a complete log message is available (from server output data) that message is parsed for its slf4j context (logger name, logger level etc.) and the specifiedBiConsumer
is invoked with the log message and slf4j context.static AppiumDriverLocalService
buildDefaultService()
static AppiumDriverLocalService
buildService(AppiumServiceBuilder builder)
boolean
clearOutPutStreams()
Remove all existing server output streams.void
enableDefaultSlf4jLoggingOfOutputData()
Enables server output data logging through SLF4J loggers.java.lang.String
getBasePath()
java.lang.String
getStdOut()
Logs as string.java.net.URL
getUrl()
Base URL.boolean
isRunning()
java.util.Optional<java.io.OutputStream>
removeOutPutStream(java.io.OutputStream outputStream)
Remove the outputStream which is receiving server output data.void
start()
Starts the defined appium server.void
stop()
Stops this service is it is currently running.AppiumDriverLocalService
withBasePath(java.lang.String basePath)
-
Methods inherited from class org.openqa.selenium.remote.service.DriverService
close, getArgs, getDefaultDriverOptions, getDriverExecutable, getDriverName, getDriverProperty, getEnvironment, getExecutable, getOutputStream, getTimeout, getUrl, hasShutdownEndpoint, sendOutputTo, setExecutable, waitUntilAvailable
-
-
-
-
Method Detail
-
buildDefaultService
public static AppiumDriverLocalService buildDefaultService()
-
buildService
public static AppiumDriverLocalService buildService(AppiumServiceBuilder builder)
-
withBasePath
public AppiumDriverLocalService withBasePath(java.lang.String basePath)
-
getBasePath
public java.lang.String getBasePath()
-
getUrl
public java.net.URL getUrl()
Base URL.- Overrides:
getUrl
in classorg.openqa.selenium.remote.service.DriverService
- Returns:
- The base URL for the managed appium server.
-
isRunning
public boolean isRunning()
- Overrides:
isRunning
in classorg.openqa.selenium.remote.service.DriverService
-
start
public void start() throws AppiumServerHasNotBeenStartedLocallyException
Starts the defined appium server.- Overrides:
start
in classorg.openqa.selenium.remote.service.DriverService
- Throws:
AppiumServerHasNotBeenStartedLocallyException
- If an error occurs while spawning the child process.- See Also:
stop()
-
stop
public void stop()
Stops this service is it is currently running. This method will attempt to block until the server has been fully shutdown.- Overrides:
stop
in classorg.openqa.selenium.remote.service.DriverService
- See Also:
start()
-
getStdOut
@Nullable public java.lang.String getStdOut()
Logs as string.- Returns:
- String logs if the server has been run. Null is returned otherwise.
-
addOutPutStream
public void addOutPutStream(java.io.OutputStream outputStream)
Adds other output stream which should accept server output data.- Parameters:
outputStream
- is an instance ofOutputStream
that is ready to accept server output
-
addOutPutStreams
public void addOutPutStreams(java.util.List<java.io.OutputStream> outputStreams)
Adds other output streams which should accept server output data.- Parameters:
outputStreams
- is a list of additionalOutputStream
that are ready to accept server output
-
removeOutPutStream
public java.util.Optional<java.io.OutputStream> removeOutPutStream(java.io.OutputStream outputStream)
Remove the outputStream which is receiving server output data.- Returns:
- the outputStream has been removed if it is present
-
clearOutPutStreams
public boolean clearOutPutStreams()
Remove all existing server output streams.- Returns:
- true if at least one output stream has been cleared
-
enableDefaultSlf4jLoggingOfOutputData
public void enableDefaultSlf4jLoggingOfOutputData()
Enables server output data logging through SLF4J loggers. This allow server output data to be configured with your preferred logging frameworks (e.g. java.util.logging, logback, log4j).NOTE1: You might want to call method
clearOutPutStreams()
before calling this method.
NOTE2: it is required that--log-timestamp
server flag isfalse
.By default log messages are:
- logged at
INFO
level, unless log message is pre-fixed by[debug]
then logged atDEBUG
level. - logged by a SLF4J logger instance with a name corresponding to the appium sub module as prefixed in log message (logger name is transformed to lower case, no spaces and prefixed with "appium.service.").
appium.service.adb
at levelINFO
.
Example log-message: "[debug] [XCUITest] Xcode version set to 'x.y.z' " is logged by loggerappium.service.xcuitest
at levelDEBUG
.- See Also:
addSlf4jLogMessageConsumer(BiConsumer)
- logged at
-
addSlf4jLogMessageConsumer
public void addSlf4jLogMessageConsumer(java.util.function.BiConsumer<java.lang.String,Slf4jLogMessageContext> slf4jLogMessageConsumer)
When a complete log message is available (from server output data) that message is parsed for its slf4j context (logger name, logger level etc.) and the specifiedBiConsumer
is invoked with the log message and slf4j context.Use this method only if you want a behavior that differentiates from the default behavior as enabled by method
enableDefaultSlf4jLoggingOfOutputData()
.NOTE: You might want to call method
clearOutPutStreams()
before calling this method.implementation detail:
- if log message begins with
[debug]
then log level is set toDEBUG
, otherwise log level isINFO
. - the appium sub module name is parsed from the log message and used as logger name (prefixed with "appium.service.", all lower case, spaces removed). If no appium sub module is detected then "appium.service" is used as logger name.
appium.service.adb
at levelINFO
Example log-message: "[debug] [XCUITest] Xcode version set to 'x.y.z' " is logged byappium.service.xcuitest
at levelDEBUG
- Parameters:
slf4jLogMessageConsumer
- BiConsumer block to be executed when a log message is available.
- if log message begins with
-
addLogMessageConsumer
public void addLogMessageConsumer(java.util.function.Consumer<java.lang.String> consumer)
When a complete log message is available (from server output data), the specifiedConsumer
is invoked with that log message.NOTE: You might want to call method
clearOutPutStreams()
before calling this method.If the Consumer fails and throws an exception the exception is logged (at WARN level) and execution continues.
- Parameters:
consumer
- Consumer block to be executed when a log message is available.
-
-