AppiumDriverLocalService 启动appium控制台不显示日志以及把日志保存到本地
Posted 等那片花海
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了AppiumDriverLocalService 启动appium控制台不显示日志以及把日志保存到本地相关的知识,希望对你有一定的参考价值。
import java.io.File; import java.io.OutputStream; import java.lang.reflect.Field; import java.util.ArrayList; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.DesiredCapabilities; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import cn.lebo.appium.base.androidCapabilityType; import io.appium.java_client.android.AndroidDriver; import io.appium.java_client.service.local.AppiumDriverLocalService; import io.appium.java_client.service.local.AppiumServiceBuilder; public class NewTest { AppiumDriverLocalService service = null; AndroidDriver<WebElement> driver = null; @SuppressWarnings("unchecked") @BeforeClass public void beforClass() { Field streamField = null; Field streamsField = null; service = AppiumDriverLocalService .buildService(new AppiumServiceBuilder().usingPort(4723).withLogFile(new File("d:\\44555554.txt"))); try { streamField = AppiumDriverLocalService.class.getDeclaredField("stream"); streamField.setAccessible(true); streamsField = Class.forName("io.appium.java_client.service.local.ListOutputStream") .getDeclaredField("streams"); streamsField.setAccessible(true); } catch (ClassNotFoundException | NoSuchFieldException e) { e.printStackTrace(); } try { ((ArrayList<OutputStream>) streamsField.get(streamField.get(service))).clear(); // remove System.out logging } catch (IllegalAccessException e) { e.printStackTrace(); } service.start(); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(AndroidCapabilityType.DEVICE_NAME, "android"); capabilities.setCapability(AndroidCapabilityType.APP_PACKAGE, "com.hpplay.sdk.source.test"); capabilities.setCapability(AndroidCapabilityType.APP_ACTIVITY, "com.hpplay.sdk.source.test.MainActivity"); driver = new AndroidDriver<>(service, capabilities); } @Test public void demo1() { System.out.println("执行test"); driver.openNotifications(); System.out.println("执行" + driver.toString()); // driver.manage().logs().get("logcat"); } @AfterClass public void AfterClass() { service.stop(); System.out.println("停止test"); } }
以上是关于AppiumDriverLocalService 启动appium控制台不显示日志以及把日志保存到本地的主要内容,如果未能解决你的问题,请参考以下文章