Headless testing with JavaFx and TestFx - unit-testing

I have a simple JavaFx application (Java 8) that has a unit test using TestFx. However, when the test is run, the application window starts up and the mouse is moved to do whatever action is in my test. Can these tests be run in a way where the application doesn't popup and I can still use my mouse for other things as the automated build and tests are running?

Update:
I found this blog post that provides the solution for me to this problem. As the author suggests, you need to add the following dependency to your build:
testRuntime 'org.testfx:openjfx-monocle:1.8.0_20'
Then you will need to include the following somewhere before you call registerPrimaryStage(), in my case in a method marked with #BeforeClass as I am using JUnit:
System.setProperty("testfx.robot", "glass");
System.setProperty("testfx.headless", "true");
System.setProperty("prism.order", "sw");
System.setProperty("prism.text", "t2k");
I would also add that its useful to include System.setProperty("java.awt.headless", "true") to ensure that you're not relying on anything from the AWT (in my case I had a call to get the size of the screen that was causing problems). I also followed the blog author's advice to add a switch to turn headless mode on and off. This gives the final method as follows:
#BeforeClass
public static void setupSpec() throws Exception {
if (Boolean.getBoolean("headless")) {
System.setProperty("testfx.robot", "glass");
System.setProperty("testfx.headless", "true");
System.setProperty("prism.order", "sw");
System.setProperty("prism.text", "t2k");
System.setProperty("java.awt.headless", "true");
}
registerPrimaryStage();
}
You can see the solution in context here
Original Answer:
If you're using Linux, you can use xvfb for this. On a Debian-based system you can install xvfb as follows:
$ sudo apt-get install xvfb
With xvfb installed, run the following before you run your tests:
$ Xvfb :99 &>/dev/null &
$ export DISPLAY=:99
If you launch your tests in the same console TestFX will use the frame buffer instead of your main display. Thus the tests will run but you won't be bothered with windows opening and the mouse pointer being moved around.

I would agree with KDK for using Monocle, since it does work as charm with Jenkins. I couldn't have reliable result from Xvfb on Jenkins. Below is the steps I took and works for me.
Prepare Monocle
You want to download Monocle from Monocle Github. It looks there is api change, so you would want to edit MonocleView.java with adding below method after download. I'm not sure what I should put in the method, but found it just works without implementing it.
#Override
protected int _getNativeFrameBuffer(long ptr) {
// TODO Auto-generated method stub
return 0;
}
Install Monocle
Build the Monocle jar and put the jar into your JRE (under jre/lib/ext path)
Run Monocle with Glass lib
Below is my maven command used in jenkins, you will have interest on java runtime option portion.
$ mvn clean install -Dtestfx.robot=glass -Dglass.platform=Monocle -Dmonocle.platform=Headless -Dprism.order=sw

Yes, it is possible to perform headless testing of JavaFx2 applications.
You will need Monocle(part of OpenJFX). More details here:
https://github.com/TestFX/Monocle

Related

QT installer framework - How to add a custom script after online update execution

Can I add some code after the maintance tool update execution(or after the final page)?
Basically I have an application that is already in use. It has a setuped QT Installer Framework autoupdates. And I need to execute a script right after a new update will be installed. But that script does not exist yet in the current installed version - it will be added by that update.
I have a class UpdateManager.cpp:
// ... Manually check for updates ...
// ...
arguments << "--script=installer-noninteractive.qs";
QProcess::startDetached("./uninstall", arguments);
// Quit the app
Where the installer-noninteractive.qs is done using this official guide
As I got the only entrypoint for me to interupt the end of update is this script. But when the maintaince tool is running it basically has an old version of script, because it will be downloaded after.

How to use a native node.js addon in React

I have a react project in which I would like to use this native node.js addon, which is a wrapper for a C++ SDK.
I've successfully used this module in the past within an Electron project, and can run the sample successfully with node as well.
My question is how I would be able to use this in React, or write my own React friendly solution using the C++ SDK.
I've tried to clone the module and place it under a lib folder in my react project, I ran npm install within that folder to install it's dependencies and tried to run the included example directly with node. This went fine. But using the sample directly from within my React app fails with the following error code ts3client.on is not a function.
So it passes the line were the library is required with var ts3client = require('../../lib/node-ts3sdk-client/api.js'); but that's the furthest I managed to get. I could play around a little bit more, but would like to get some opinions on what might be the best approach here.
Edit
As requested I have added a small example to reproduce the issue I am facing.
Create a simple react app
npm init react-app so-node-addon-react
Clone this repository under src/lib/
git clone https://github.com/svenpaulsen/node-ts3sdk-client.git
Install the module's dependencies
cd node-ts3sdk-client
npm install
Expose some part of the client example by wrapping the try-catch block starting from line 160 in an exported function like so
export function connect() {
try { ... }
catch { ... }
}
Call the function from your project's App.tsx
import { connect } from './lib/node-ts3sdk-client/examples/client_minimal'
...
connect()
Run the project
npm start
This should result in the following error: ts3client.on is not a function

AndroidStudio 3.2 test configuration does not work

After migrating to AS 3.2 android JUnit test run configuration does not work, all types "All in directory",
"All in package" etc.
I mean it does work, but always claims that:
0 test classes found in package '<default package>'
Process finished with exit code 254
Empty test suite.
using ./gradlew test triggers every test
and every single test can be run by AS using that green play button inside editor (for class or single method)
but not for package, module etc.
How to fix that ?
many thanks
Wojtek
Declare your test classes as public
Fixed in Android Studio 3.2.1
So just update AS to newest version and the problem disappears

Running Calabash Android from Rubymine

Can someone post some help. I have tried different config but can't run Calabash Android tests from within Rubymine. Works on Terminal though.
Finally found the solution after some trial and error. Here is what you need to do on Rubymine:
EDIT Runner Options and add: APP_PATH= "" and TEST_APP_PATH="" and run the feature file. This should do it.
Thanks,
Method, suggested by Manpreet Singh, uses cucumber as the test runner. Here you need to define APP_PATH and TEST_APP_PATH environmental variables:
APP_PATH will need to be reset if apk file or file name changes (e.g. uploaded a new version of the apk)
TEST_APP_PATH points to the test server file, which is generated by calabash when you try to connect calabash to your new apk for the first time (e.g. with "calabash-android run" or "calabash-android console"), or if previous test server file was deleted
This way it's easier to create a new test using "Right-click on a scenario or feature file > Create configuration" in RubyMine thanks to its robust cucumber support
Another method is, as pointed by Dave, to set up a calabash-android run as a gem executable - see this thread for details.
Need to set apk path only
This way, your execution is the same as in the command line and passing arguments (such as cucumber profile, output options etc) will work for sure. Also, such configuration is less fragile to the test_server change. However, it's a bit more cobersome to setup than as a cucumber run.
After all with the current architecture of calabash, I still prefer to code in IDE but run in the command line :) IDE becomes very useful, when you need to debug tests.
the setting above does not work for me
here is the setting worked. basically, in Run/Debug configureation, need to create a Gem command to execute calabash-android, and correct arguments, not a configure for Cucumber .
http://daedalus359.wordpress.com/2013/11/02/getting-calabash-to-play-nicely-with-rubymine/
-dave

Running unit tests in Pydev

I am trying to run unit tests in Pydev using IronPython.
When I try to run a test with Ctrl+F9 the following error message shows up in the Eclipse console window:
AttributeError: 'module' object has no attribute '_getframe'
I figured out that I have to invoke the IronPython interpreter with the '-X:Frames' argument.
Setting up the arguments in the 'Arguments' tab under 'Run->Run Configurations...' doesn't work. They seem to disappear everytime I run (Ctrl+F9) and choose another test.
Clicking 'Run->Run As->Iron Python unit-test' shows up more and more options to choose from.
Is Eclipse/Pydev creating new run configurations everytime I run a different set of tests? How can I permanently pass the '-X:Frames' argument, so my tests will run under IronPython?
(In Python the tests run without any problem.)
This shouldn't really be needed... I've just fixed the PyDev unittest runner so that it works properly (just pushed a new nightly build with that fix included -- if you're in Aptana Studio 3, a nightly is still not available, but you can patch your own version by applying the changes from the commit locally, as they're all changes in Python code: https://github.com/aptana/Pydev/commit/d5d262dbcd0c126ec0ec37e116ff79575c5dd6d8)