How do I resize an open window in WebdriverIO? - browser

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

Related

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

Is it possible to run unit tests with wxWidgets with just the console and no UI?

I am trying to run some unit tests for code that makes use of wxWidgets windows. In the process, windows are created, but never displayed. This works fine under Linux where a display is available, but not on build systems that don't have X or any other UI/display.
The error I get is: "Unable to initialize GTK+, is DISPLAY set properly?"
Is it possible to unit test wxWidgets without a display? I'm hoping there is some way to just have a stub or "null" display that doesn't really exist, but would allow the unit tests to execute.
As mentioned, I don't need to actually display any window, but from the working tests on a system with a UI, I do need to initialize the app, and create a top level window, like so:
wxEntryStart(argc, argv);
wxTheApp->OnInit();
wxFrame frame(nullptr, wxID_ANY, "Test Frame");
wxTheApp->SetTopWindow(&frame);
You can set up an Xvfb server (or perhaps an Xvnc server), and use it as your dummy display.

Get screenshots window via node js on Windows 10

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);
}

MAC OS X difference between "open APP.app" and "APP.app/content/MacOs/APP" shell scripts

Somehow I get a problem, if I call an application twice or several times but only one instance should be running (which is desired).
First some (probably necessary) background information:
working on MAC OS X El Capitan (10.11.6)
I've got an Application made by node.js, electron and build by "npm build -m" (let's call it APP.app)
I installed the application App.app into program-folder by opening the built dmg-file and move it into the program-folder
Then I start the application App.app by click on the App.app-icon in program-folder
The application starts with a visible Window and also has an hidden background process running
If I close the visible Window, the App.app-Icon remains in the dock (which is okay, since the background-process is still running)
Now (and this is the difference to the windows build and running in windows), if I click again on the App.app-Icon in the program-folder, I only get a focus on the already running application INSTEAD of opening the window and close the old application (I can see te focus switch/activation by the switching menu name beside the apple-logo on top of the screen; it becomes "App")
the closing of the previous running instance is defined in electron code in the init-method as follows:
var shouldQuit = app.makeSingleInstance(function (commandLine, workingDirectory) {
console.info('starting new instance');
initInternal(commandLine);
// Someone tried to run a second instance, we should focus our window.
var windows = options.closeWindowsOnRestart ? Browser.getAllWindows() : appWindows.slice();
windows.forEach(function (val, index) {
val.close();
});
readyCallback();
});
So, I did some homework and could figure out following:
my App.app-icon-click should look something like open /Applications/App.app
with this, I get the same problem as descriped above if I call it again (it only focusses the already opened window)
Now comes the funny part. If I open the application by calling directly /Applications/App.app/content/MacOS/App.app the old application-instance is closed and new App.app-application is started
I read through open-manual and could figure out, that if I use the -n-flag, the application starts succesful a new instance, too. (open /Applications/App.app -n)
I was wondering WHY? Do you have any clues? What is the difference between open and directly call of the application?
I suggest that the info.pklist in App.app-package is making the open-call different to the direct call of App.app.
BTW:
Unfortunately I already tried to add try-catch-blocks to debug the problem, but open does not give an output to terminal, it just opens the call whereas the direct call does not throw an error and everything works fine.
Anyway, I believe it's more a MAC OS X problem than an App.app-problem.
Hopefully there's somebody with same problems and a solution for me
Don't hesitate to ask for more details, if needed.
Short Version:
open starts the application with the LaunchService (and possible
added launch-parameters in info.plist)
whereas direct call of the
application just starts the application iself without any other
launch-options
*Long Version *
I read through the open manual (man open; Source: https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/open.1.html) and could figure out, that "the default application as determined via LaunchServices is used to open the specified files" if you click on an item.
So I read through the LaunchService-documentation and could figure out following:
"Opening Items by File-System Reference [...] default way:
If the designated item is an application: [...]
If the application is already running, it is activated (brought to the front of the screen) and sent an 'rapp' (“reopen
application”) Apple event."
(Source: https://developer.apple.com/library/content/documentation/Carbon/Conceptual/LaunchServicesConcepts/LSCTasks/LSCTasks.html#//apple_ref/doc/uid/TP30000999-CH203-TP9)
This reflects exactly my watching that if I click on the icon the second time, the app is just focussed/activated.
Thus I need the possibility to tell the application to open a new instance (oapp-event) instead of activating the already opened application (rapp-event)
Further reading lead me to following informations:
"Launch Options When opening an application (whether by itself or to
open one or more documents or URLs), you can specify various launch
options to control the manner in which it is launched or activated.
These can include: [...] Whether to launch a new instance of the
application, even if another instance is already running"
(Source: https://developer.apple.com/library/content/documentation/Carbon/Conceptual/LaunchServicesConcepts/LSCConcepts/LSCConcepts.html#//apple_ref/doc/uid/TP30000999-CH202-BABBJHID)
Thus I only need to add the "launch option" to define, that a new instance should be created instead of activating the existing one. But there's not written what the launch-option for it is and how they will be applied to the application (I suggest it belongs into info.plist-file).
So at least this is the answer to my original question, so I posted it here.
open - starts the application with the Launch-Service (and the defined option-parameters in info.plist)
whereas direct call of the application just starts the application iself without any other launch-options

wx.TextDropTarget not working in Linux

I have a desktop application developed with wxPython. The applications runs fine under Windows and OSX (same codebase, no platform specific code). Everything works on Linux except drag and drop. I can drag just fine, but DoDragDrop always returns wx.DragCancel. I can however, drag from my application or to another app/desktop which excepts text and DoDragDrop returns wx.DragCopy.
It seems to me like the DropTargets aren't getting called. I've added debug statements to OnData, etc and they are never activated.
Has anyone seen this and know of a workaround?
Found a known issue in wxWidgets that was considered fixed, http://trac.wxwidgets.org/ticket/2763, I am able to recreate this issue on linux. I reopened the ticket.
In the meantime you can swap your StaticBoxSizers or BoxSizers. or...
This works....
parent = DropTargetCtrn.GetParent()
boxes = [x for x in parent.GetChildren() if type(x)==wx.StaticBox]
tmpParent = wx.Panel(parent)
for box in boxes:
box.Reparent(tmpParent)
box.Reparent(parent)
parent.Destroy()
This solution seems to lower the StaticBox in the window hierarchy so it don't interfere with drop events. Note, box.Lower() does not work.

Resources