开发Appium Plugin时console.log无法输出至终端的问题
Appium插件开发日志输出问题
问题概述
我正在开发一款Appium插件,开发过程中尝试调用console.log(),期望传入的字符串能显示在加载该插件的Appium Server启动终端窗口中,但实际这些字符串并未出现在服务器日志里。我认为自己遗漏了某个简单配置,目前没有相关文档说明,而日志输出对开发至关重要。
相关代码
插件代码
import BasePlugin from '@appium/base-plugin'; import type { BaseDriver } from 'appium/driver'; type NextHandler = () => Promise<string>; export declare function customLogger(message: string): void; export declare class MyApp extends BasePlugin { getPageSource(next: NextHandler, driver: BaseDriver<any>): Promise<import("my-app").Results>; } export {};
import BasePlugin from '@appium/base-plugin' import type { BaseDriver } from 'appium/driver' import myPlugin from '@my-plugin/appium-engine' import axios from 'axios' import * as fs from 'fs'; import * as path from 'path'; type NextHandler = () => Promise<string> export class MyApp extends BasePlugin { public async getPageSource(next: NextHandler, driver: BaseDriver<any>) { // 这是我们在capabilities中设置的API密钥 const apiKey = driver.caps.key const originalSource = await next() console.log("My console log") const results = myPlugin(originalSource) // 将数据发送到服务器 const { data } = await axios.post( 'http://localhost:3001/api/scans', { scan: results }, { headers: { 'Content-Type': 'application/json', 'x-auth-token': apiKey } } ) return results } }
客户端代码
from appium import webdriver from appium.options.ios import XCUITestOptions from appium.webdriver.appium_connection import AppiumConnection class CustomAppiumConnection(AppiumConnection): # 可为自定义类添加方法 pass custom_executor = CustomAppiumConnection(remote_server_addr='http://0.0.0.1:1234') options = XCUITestOptions().load_capabilities({ 'platformVersion': '16.2', 'deviceName': 'iPhone 14', 'udid': '450B76CF-CF54-4DBC-90E5-FC4E567EF52C', 'key': 'value' }) driver = webdriver.Remote(custom_executor, options=options) pageSource = driver.page_source
启动服务器命令
appium --use-plugins @my-plugin/appium-plugin --log-level debug
WebDriver文档参考
@property def page_source(self) -> str: """获取当前页面的源码 使用示例: :: driver.page_source """ return self.execute(Command.GET_PAGE_SOURCE)["value"]
GET_PAGE_SOURCE: str = "getPageSource"
已尝试的解决方法
- 重新构建项目
- 尝试将日志写入文件(已引入
import * as fs from 'fs';等相关模块)
内容的提问来源于stack exchange,提问作者Tristan Newman
相关产品推荐
相关产品推荐

