Wdio problem screenshot element


#1

I can’t take a screenshot from a element of the screen. Can someone help me?

Appium desktop version: 1.5.0 (I not using the last one, because I had another problem with this version).

Now my code:

    const wdio = require('webdriverio');


const opts = {
    port: 4723,
    desiredCapabilities: {
	  "platformName": "Android",
	  "platformVersion": "7.0",
	  "deviceName": "0023048519",
	  "automationName": "UiAutomator2",
	  "appPackage": "com.android.calculator2",
  	  "appActivity": "com.android.calculator2.Calculator",
	  "noReset": "true",
	  "full-reset": "false"
	
	}
};
 
const driver = wdio.remote(opts);

driver.init()	.click('//*[@resource-id="com.google.android.calculator:id/digit_2"]')		
		.elementIdScreenshot('//*[@resource-id="com.google.android.calculator:id/digit_2"]').saveScreenshot('./snapshot.png')
		.end();

When I run this code I have the follow log:

[ADB] 1 device(s) connected
[ADB] Running '/home/afonso/Android/Sdk/platform-tools/adb' with args: ["-P",5037,"-s","0023048519","shell","am","start","-W","-n","com.android.calculator2/com.android.calculator2.Calculator","-S"]
[Appium] New AndroidUiautomator2Driver session created successfully, session 94c34095-f311-411b-b8ca-210f337cdf50 added to master session list
[BaseDriver] Event 'newSessionStarted' logged at 1531096295684 (21:31:35 GMT-0300 (-03))
[MJSONWP] Responding to client with driver.createSession() result: {"javascriptEnabled":true,"locationContextEnabled":true,"handlesAlerts":true,"rotatable":true,"platformName":"Android","platformVersion":"7.0","deviceName":"0023048519","automationName":"UiAutomator2","appPackage":"com.android.calculator2","appActivity":"com.android.calculator2.Calculator","noReset":true,"full-reset":"false","requestOrigins":{"url":"http://webdriver.io","version":"4.12.0","name":"webdriverio"}}
[HTTP] <-- POST /wd/hub/session 200 27014 ms - 486 
[HTTP] --> POST /wd/hub/session/94c34095-f311-411b-b8ca-210f337cdf50/element {"using":"xpath","value":"//*[@resource-id=\"com.google.android.calculator:id/digit_2\"]"}
[MJSONWP] Calling AppiumDriver.findElement() with args: ["xpath","//*[@resource-id=\"com.google.android.calculator:id/digit_2\"]","94c34095-f311-411b-b8ca-210f337cdf50"]
[BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[BaseDriver] Waiting up to 0 ms for condition
[JSONWP Proxy] Proxying [POST /element] to [POST http://localhost:8202/wd/hub/session/98f8bee9-7272-486c-84e3-6111bb0fea12/element] with body: {"strategy":"xpath","selector":"//*[@resource-id=\"com.google.android.calculator:id/digit_2\"]","context":"","multiple":false}
[JSONWP Proxy] Got response with status 200: {"sessionId":"98f8bee9-7272-486c-84e3-6111bb0fea12","status":0,"value":{"ELEMENT":"3d068c0e-1f61-478d-b77b-e908ae43a3a3"}}
[MJSONWP] Responding to client with driver.findElement() result: {"ELEMENT":"3d068c0e-1f61-478d-b77b-e908ae43a3a3"}
[HTTP] <-- POST /wd/hub/session/94c34095-f311-411b-b8ca-210f337cdf50/element 200 889 ms - 122 
[HTTP] --> POST /wd/hub/session/94c34095-f311-411b-b8ca-210f337cdf50/element/3d068c0e-1f61-478d-b77b-e908ae43a3a3/click {}
[MJSONWP] Calling AppiumDriver.click() with args: ["3d068c0e-1f61-478d-b77b-e908ae43a3a3","94c34095-f311-411b-b8ca-210f337cdf50"]
[JSONWP Proxy] Proxying [POST /element/3d068c0e-1f61-478d-b77b-e908ae43a3a3/click] to [POST http://localhost:8202/wd/hub/session/98f8bee9-7272-486c-84e3-6111bb0fea12/element/3d068c0e-1f61-478d-b77b-e908ae43a3a3/click] with body: {"element":"3d068c0e-1f61-478d-b77b-e908ae43a3a3"}
[JSONWP Proxy] Got response with status 200: {"sessionId":"98f8bee9-7272-486c-84e3-6111bb0fea12","status":0,"value":true}
[MJSONWP] Responding to client with driver.click() result: true
[HTTP] <-- POST /wd/hub/session/94c34095-f311-411b-b8ca-210f337cdf50/element/3d068c0e-1f61-478d-b77b-e908ae43a3a3/click 200 48 ms - 76 
[HTTP] --> GET /wd/hub/session/94c34095-f311-411b-b8ca-210f337cdf50/element///*[@resource-id=%22com.google.android.calculator:id/digit_2%22]/screenshot {}
[HTTP] No route found. Setting content type to 'text/plain'
[HTTP] <-- GET /wd/hub/session/94c34095-f311-411b-b8ca-210f337cdf50/element///*[@resource-id=%22com.google.android.calculator:id/digit_2%22]/screenshot 404 5 ms - 178 
[BaseDriver] Shutting down because we waited 60 seconds for a command
[UiAutomator2] Deleting UiAutomator2 session
[Appium] Closing session, cause was 'New Command Timeout of 60 seconds expired. Try customizing the timeout using the 'newCommandTimeout' desired capability'
[Appium] Removing session 94c34095-f311-411b-b8ca-210f337cdf50 from our master session list
[UiAutomator2] Deleting UiAutomator2 server session
[JSONWP Proxy] Proxying [DELETE /] to [DELETE http://localhost:8202/wd/hub/session/98f8bee9-7272-486c-84e3-6111bb0fea12] with no body
[JSONWP Proxy] Got response with status 200: "{\"sessionId\":\"98f8bee9-7272-486c-84e3-6111bb0fea12\",\"status\":0,\"value\":\"Session deleted\"}"
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running '/home/afonso/Android/Sdk/platform-tools/adb' with args: ["-P",5037,"-s","0023048519","shell","am","force-stop","com.android.calculator2"]
[Logcat] Stopping logcat capture
[ADB] Removing forwarded port socket connection: 8202 
[ADB] Running '/home/afonso/Android/Sdk/platform-tools/adb' with args: ["-P",5037,"-s","0023048519","forward","--remove","tcp:8202"]
[UiAutomator2] [UIAutomator2] io.appium.uiautomator2.server.test.AppiumUiAutomator2Server:.
[UiAutomator2] [UIAutomator2] Time: 65,055
[UiAutomator2] [UIAutomator2] OK (1 test)

When a take the screenshot the next message is “No route found. Setting content type to ‘text/plain’”. The appium find the elements, but not save it.

I can take and save a screenshot from all screen, but I have this problem when I try to take it from a element.


#2

I don’t know what I’m doing wrong, every time I post no one help me.