appium-boneyard / appium-plugins

Officially-maintained plugins for the Appium server
Apache License 2.0
32 stars 7 forks source link

Client demo for fake plugin #23

Closed phamnhuvu-dev closed 3 years ago

phamnhuvu-dev commented 3 years ago

I am using webdriverio for the client side.

I don't know how to make the right client call to the plugin.

    const client = await wdio.remote(opts);
    client.addCommand('getFakeSessionData', command('GET', '/session/:sessionId/fake_data', {
      command: 'getFakeSessionData',
      parameters: [{
      }]
    }))

    console.log('test', await client.getFakeSessionData());

Client logs:

2021-09-16T03:46:11.207Z INFO webdriver: Initiate new session using the WebDriver protocol 2021-09-16T03:46:11.264Z INFO webdriver: [POST] http://0.0.0.0:4723/wd/hub/session 2021-09-16T03:46:11.264Z INFO webdriver: DATA { capabilities: { alwaysMatch: { platformName: 'Android', deviceName: 'Android 11', app: '/Users/phamnhuvu/Documents/test/ApiDemos-debug.apk', automationName: 'UiAutomator2' }, firstMatch: [ {} ] }, desiredCapabilities: { platformName: 'Android', deviceName: 'Android 11', app: '/Users/phamnhuvu/Documents/test/ApiDemos-debug.apk', automationName: 'UiAutomator2' } } 2021-09-16T03:46:16.659Z INFO webdriver: COMMAND getFakeSessionData() 2021-09-16T03:46:16.660Z INFO webdriver: COMMAND getFakeSessionData() 2021-09-16T03:46:16.660Z INFO webdriver: [GET] http://0.0.0.0:4723/wd/hub/session/0fb6825f-86a4-4b90-9afd-5dc14c6af3a6/fake_data 2021-09-16T03:46:16.694Z WARN webdriver: Request failed with status 404 due to The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource 2021-09-16T03:46:16.695Z INFO webdriver: Retrying 1/3 2021-09-16T03:46:16.695Z INFO webdriver: [GET] http://0.0.0.0:4723/wd/hub/session/0fb6825f-86a4-4b90-9afd-5dc14c6af3a6/fake_data 2021-09-16T03:46:16.714Z WARN webdriver: Request failed with status 404 due to The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource 2021-09-16T03:46:16.714Z INFO webdriver: Retrying 2/3 2021-09-16T03:46:16.714Z INFO webdriver: [GET] http://0.0.0.0:4723/wd/hub/session/0fb6825f-86a4-4b90-9afd-5dc14c6af3a6/fake_data 2021-09-16T03:46:16.740Z WARN webdriver: Request failed with status 404 due to The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource 2021-09-16T03:46:16.740Z INFO webdriver: Retrying 3/3 2021-09-16T03:46:16.740Z INFO webdriver: [GET] http://0.0.0.0:4723/wd/hub/session/0fb6825f-86a4-4b90-9afd-5dc14c6af3a6/fake_data 2021-09-16T03:46:16.761Z ERROR webdriver: Request failed with status 404 due to unknown command: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource node:internal/process/promises:246 triggerUncaughtException(err, true / fromPromise /); ^ [io.appium.uiautomator2.common.exceptions.UnknownCommandException: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource at io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:75) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345) at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345) at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:435) at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267) at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:250) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345) at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:266) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1294) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:911) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:611) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:552) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:466) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:438) at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140) at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144) at java.lang.Thread.run(Thread.java:923) ] { name: 'unknown command' }

Server logs:

[debug] [W3C (0fb6825f)] Responding to client with driver.createSession() result: {"capabilities":{"platform":"LINUX","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"platformName":"Android","deviceName":"Android 11","app":"/Users/phamnhuvu/Documents/test/ApiDemos-debug.apk","automationName":"UiAutomator2"},"platformName":"Android","deviceName":"emulator-5554","app":"/Users/phamnhuvu/Documents/test/ApiDemos-debug.apk","automationName":"UiAutomator2","deviceUDID":"emulator-5554","appPackage":"io.appium.android.apis","deviceApiLevel":30,"platformVersion":"11","deviceScreenSize":"1080x1920","deviceScreenDensity":420,"deviceModel":"sdk_gphone_x86_64","deviceManufacturer":"Google","pixelRatio":2.625,"statBarHeight":63,"viewportRect":{"left":0,"top":63,"width":1080,"height":1731}}} [HTTP] <-- POST /wd/hub/session 200 5367 ms - 903 [HTTP] [HTTP] --> GET /wd/hub/session/0fb6825f-86a4-4b90-9afd-5dc14c6af3a6/fake_data [HTTP] {} [W3C (0fb6825f)] Driver proxy active, passing request on via HTTP proxy [debug] [WD Proxy] Proxying [GET /wd/hub/session/0fb6825f-86a4-4b90-9afd-5dc14c6af3a6/fake_data] to [GET http://127.0.0.1:8201/wd/hub/session/da57e178-c7b4-4fa7-aa06-d43cc92ead19/fake_data] with no body [WD Proxy] Got response with status 404: {"sessionId":null,"value":{"error":"unknown command","message":"The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource","stacktrace":"io.appium.uiautomator2.common.exceptions.UnknownCommandException: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:75)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)\n\tat io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandler... [debug] [W3C] Matched W3C error code 'unknown command' to UnknownCommandError [HTTP] <-- GET /wd/hub/session/0fb6825f-86a4-4b90-9afd-5dc14c6af3a6/fake_data 404 31 ms - 3529 [HTTP] [HTTP] --> GET /wd/hub/session/0fb6825f-86a4-4b90-9afd-5dc14c6af3a6/fake_data [HTTP] {} [W3C (0fb6825f)] Driver proxy active, passing request on via HTTP proxy [debug] [WD Proxy] Proxying [GET /wd/hub/session/0fb6825f-86a4-4b90-9afd-5dc14c6af3a6/fake_data] to [GET http://127.0.0.1:8201/wd/hub/session/da57e178-c7b4-4fa7-aa06-d43cc92ead19/fake_data] with no body [WD Proxy] Got response with status 404: {"sessionId":null,"value":{"error":"unknown command","message":"The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource","stacktrace":"io.appium.uiautomator2.common.exceptions.UnknownCommandException: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:75)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)\n\tat io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandler... [debug] [W3C] Matched W3C error code 'unknown command' to UnknownCommandError

jlipps commented 3 years ago

There is no client side plugin yet implemented for the fake-plugin. But here is how you could implement one yourself in webdriverio: https://webdriver.io/docs/customcommands#add-more-webdriver-commands

e.g. something like (I have not tested this)

import { command } from 'webdriver'

driver.addCommand('getFakeSessionData', command('GET', '/session/:sessionId/fake_data', {
    command: 'getFakeSessionData',
    description: 'command from the fake plugin',
    ref: '',
    variables: [],
    parameters: []
}))

then you can use it in your test code:

await driver.getFakeSessionData()
jlipps commented 3 years ago

Oh, sorry I misunderstood your question. Basically there is a bug that will be fixed in https://github.com/appium/appium-plugins/pull/24

KazuCocoa commented 3 years ago

yea, the error seems the proxy related.