Get screenshots window via node js on Windows 10 - node.js

I understand that node js for making screenshots in Windows is not the best way, but I have such a special task. The task is, so that I can make a screenshot of a specific window, even if it is not active.
I have installed ImageMagick from the official site(ImageMagick-7.0.5-9-Q16-x64-dll.exe) and tried enter into the PowerShell:
magick import my_screenshot.jpg
but I get this error:
import: delegate library support not built-in '' (X11) # error/import.c/ImportImageCommand/1294.
This means that there is not any delegate library, but that's just how I can install it, I did not find it.
What can I do to make ImageMagick work?
You can also offer your solutions for the make screenshot.
On the advice of #emcconville, I tried so magick convert screenshot: my_screenshot.jpg, but that's what happened:enter image description here

If you are using node.js you could use a package to take a screenshot.
screenshot-node works for me on windows 10 with no other dependencies.
This takes a fullscreen screenshot.
const screenshot = require('screenshot-node');
screenshot.saveScreenshot(0, 0, 0, 0, "image.png", (err) => {
if(err) console.log(err);
}

Related

why i cant use gm(GraphicsMagick) in node project by shell module, but in cmd i can do it

shell.exec(`gm convert ${filePath}[0] ${imagePath}`, (code) => {
if (!code) {
console.log("success");
}
});
i just want to get a .JPG file according to the first page of .pdf file
throw error below
Error: Command failed: /bin/sh: gm: command not found
but in cmd gm that's ok
like this
[root#VM-8-4-centos ~]# gm
GraphicsMagick 1.3.35 2020-02-23 Q8 http://www.GraphicsMagick.org/
Copyright (C) 2002-2020 GraphicsMagick Group.
Additional copyrights and licenses apply to this software.
See http://www.GraphicsMagick.org/www/Copyright.html for details.
Usage: gm command [options ...]
Where commands include:
animate - animate a sequence of images
batch - issue multiple commands in interactive or batch mode
benchmark - benchmark one of the other commands
compare - compare two images
composite - composite images together
conjure - execute a Magick Scripting Language (MSL) XML script
convert - convert an image or sequence of images
display - display an image on a workstation running X
help - obtain usage message for named command
identify - describe an image or image sequence
import - capture an application or X server screen
mogrify - transform an image or sequence of images
montage - create a composite image (in a grid) from separate images
time - time one of the other commands
version - obtain release version
OS:CentOS
how can i work out this error
thank you for your help!
This question is not really node.js related and more about linux in general, but let me explain what happens here.
When you type a command like gm, what linux does is it looks into all directories listed in the PATH environment variable and searches for a binary with the given name - 'gm' in this example. When running it in your shell the path variable seems to set correctly including the directory in which gm is present. In your node.js program that is not the case.
To fix this what i would recommend is to run which gm in your terminal. This will give you the full path to the gm binary and then in your node.js program reference the full path instead of just gm.
Hope that helps.

pywinuto - click_input() function clicks on random node of tree view

I'm trying to automate the mmc (snap in console) type desktop app. Where I need to expand the tree.
Try 1 -
But when I do use expand() function it generates error popup which says that "the child nodes does not exists". After this script simply stops with no error message on console unless ok button is clicked on error popup. This I suspect because when tree node expanded it triggers some event which brings child nodes under it and somehow pywinauto is not getting Childs of this node. Please note that this error popup does not come up when the step is done manually.
Try 2 -
When I tried with select() then too same behavior observed as above. It generated same error popup.
Try 3 -
I tried click() and click_input() functions and it clicks on random tree node but not on the tree node on which it is called.
The all above trials are of my application which is not public.
For reproducing this issue I have tried it on common application available on windows OS. And we can see that the 3rd is still reproducible.
Reference code -
import time
from pywinauto.application import Application
from pywinauto import Desktop
app = Application().start(r'cmd.exe /c "C:\Windows\system32\perfmon.msc"', wait_for_idle=False)
app = Application(backend="win32").connect(title='Performance Monitor', timeout=10)
main_wind = app.window(best_match='MMCMainFrame', top_level_only=False)
console_wind = main_wind.child_window(best_match="MDIClients").child_window(best_match='MMCChildFrm').child_window(class_name="MMCViewWindow")
tree = console_wind.TreeView # print_control_identifiers()
children = tree.get_item(["Performance","Data Collector Sets"]).expand().get_child("System").expand().get_child('System Diagnostics')
print(children.text())
# below line will select the System Diagnostics
children.select()
time.sleep(4)
# Below line should click on System Diagnostics but it does NOT and same happens for click() function
children.click_input()
Any help will be really helpful in knowing why this click() and click_input() clicks on random tree node and Why expand() and select() method generates the non functional error popup?
Please mention if there is concrete workaround to this.
versions -
Windows OS 10, build 20H2
Python 3.10.4
comtypes 1.1.11
pip 22.0.4
pywin32 303
pywinauto 0.6.8
setuptools 61.2.0
six 1.16.0
wheel 0.37.1
TIA..
I have referenced some stack overflow and github issue tracker as for this problem as below but nothing works.
Treeview problem
select() for TreeView items (and similar) leads error if this selection calls other dialogs etc
Python: Click by coordinate inside a window
This was all because of incorrect backend API used for snap in control application. Unfortunately my POC I did on win32 API where it worked because I was doing some initial steps manually hence the problem I was facing(explained in try1) was not there and everything was working perfectly fine.
As soon as I switched the backend to UIA it gave me different identifiers for the controls that I used previously. Now I used this identifiers and started using UIA documentation and everything started working smoothly.
Also in my investigation there is no proper way to identify the backend API for the desktop application unless you try both and figure out which works for you.
Suggestion to readers - If you are using win32 API as backend there are different api methods available for that in the documentation. and for UIA backend different. read documentation carefully.
You can try the uispy tool and find that perfmon.msc can be automated with uia

CR2 Preview generation with Node.JS/Electron

I want to build a Node.JS/Electron ApplicationCache, that can show Previews for the following filetypes: DNG, CR2, JGP, TIFF.
I have accomplished all of that using an external library. Except for CR2.
I cant find anything (free) that can generate a preview image for CR2-Files and does not require installing exiftools or imagemagick on the machine. Does anybody have an idea waht it can use?
The solution to this problem is: dcraw

How do I resize an open window in WebdriverIO?

I am using WebdriverIO for automation and am required to resize an open window to check the display of various UI elements compared to a maximized display.
I've tried each of the following separately with no success:
browser.setViewportSize({width:1200,height:662})
browser.windowHandleSize(1200, 662);
I also have checks to make sure the window has been properly resized:
expect(browser.getViewportSize('width')).to.be.lessThan(1300);
expect(browser.getViewportSize('width')).to.be.greaterThan(1000);
Unfortunately, nothing happens visually and the expects fail, as expected. I'm not sure if I'm not understanding how to use setViewportSize or windowHandleSize properly (maybe they're only intended to be used to resize new windows rather than existing ones?), or if this functionality exists in WebdriverIO at all.
I've used the following command in my WebdriverIO Config in setup hooks, but also just tested it in the middle of a test that's already running to both resize it smaller and then back to larger. Hope it helps!
browser.windowHandleSize({width:700, height:500});
browser.windowHandleSize({width:1280, height:870});
http://webdriver.io/api/protocol/windowHandleSize.html
Just to note as there have been several updates, please make sure your browser drivers, WebdriverIO, and Selenium Server are the latest versions!
In case someone else comes here and is confused, the API call is setWindowSize, with the arguments (width, height):
browser.setWindowSize( 700, 500 );
See: https://webdriver.io/docs/api/browser/setWindowSize.html
Note that the above command resizes the window but not the content. The setWindowRect command from the default WebDriver interface sets an absolute content size:
browser.setWindowRect( 0, 0, 700, 500 );
See: https://webdriver.io/docs/api/webdriver.html#setwindowrect

WebStorm React d3 library force()

I have a really strange problem with my libraries in WebStorm. I have been trying to find out why this does not work, but nobody seem to have the exact problem I am having, maybe because I search bad, but I have really tried.
I have followed the WebStorm support, and from their perspective it should work by now! I do not get any fault when installing the libraries with npm.
I also tried installing external libraries:
However, I am trying to use react-d3-library because I am doing a relational graph with d3. I can see that is available in my node modules in my project, the folder was gray and the others orange? Did not really know why... did some research and found something about "Right click on the directory and go to 'Mark Directory as' and select 'Resource Root'" but does not seem to work for me?
When I run this in my browser I get when pressing F12
Uncaught TypeError: Cannot read property 'force' of undefined
at App.componentDidMount (App.js:311)
at ReactCompositeComponent.js:265
at measureLifeCyclePerf (ReactCompositeComponent.js:75)
at ReactCompositeComponent.js:264
at CallbackQueue.notifyAll (CallbackQueue.js:76)
at ReactReconcileTransaction.close (ReactReconcileTransaction.js:80)
at ReactReconcileTransaction.closeAll (Transaction.js:206)
at ReactReconcileTransaction.perform (Transaction.js:153)
at batchedMountComponentIntoNode (ReactMount.js:126)
at ReactDefaultBatchingStrategyTransaction.perform (Transaction.js:140)
Code:
import d3 from 'react-d3-library';
//var d3 = require('react-d3-library);// tried this...
const force = d3.layout.force() // (App.js:311)
.charge(-120)
.linkDistance(50)
.size([width, height])
.nodes(data.nodes)
.links(data.links);
I would really like some help with this... I really do not get why it does not work? It is probably something easy but I have been fighting this the last 3 days...
P.S. Code is here on my github: https://github.com/Thelin90/react-d3.git and i have also checked this before Cannot read property 'force' of undefined (Simple D3 Network graph) This did not help me to solve the actual problem.
As far as I can see it, you are using typings of two different version of d3.js which are not compatible. In v3 there was a layout d3.layout.force in v4 this was changed to d3.forceSimulation with a way difference signature. So depending on what version you use, your code will return a TypeError with v4 but would work with v3.
Ok, I checked your package.json and you are using v4, hence this example will not run.
Ok I tried to translate your example to v4
const force = d3.layout.force()
.charge(-120)
.linkDistance(50)
.size([width, height])
.nodes(data.nodes)
.links(data.links);
const force = d3.forceSimulation(data.nodes)
.force("link", d3.forceLink(data.links).distance(50))
.force("charge", d3.forceManyBody().strength(-120))
.force('center', d3.forceCenter(width / 2, height / 2));

Resources