总结
我正在构建一个 Appium 插件。
在构建我的插件时,我尝试调用
console.log()
。我希望 String 参数出现在终端窗口中,我使用我的插件启动 Appium 服务器。
尽管在服务器日志中,传递给
console.log()
的字符串丢失了。
我认为我错过了一些简单的东西,因为最近没有任何关于此的文章,而且能够开发似乎是一件大事。
我的代码
我的插件
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 AxeDevToolsMobile extends BasePlugin {
public async getPageSource(next: NextHandler, driver: BaseDriver<any>) {
// this is the API key that we set in the capabilities
const apiKey = driver.caps.key
const originalSource = await next()
console.log("My console log")
const results = myPlugin(originalSource)
// this sends data to the server
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):
# Can add your own methods for the custom class
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
我尝试过的
import * as fs from 'fs';
,等等您是否尝试过登录插件的构造函数?我认为原来的 getPageSource 本身没有被运行,因此你的 console.log() 也没有被执行。