launching firefox in silent mode - watir

How is it possible to launch Firefox in silent mode from the code (without running script by dropping -b parameter) ?
Or is there any other way to minimize Firefox so that tests can run normally without disturbing user if multiple browser windows open simultaneously ?

If you are on Linux:
require 'watir-webdriver'
require 'headless'
headless = Headless.new
headless.start
b = Watir::Browser.start 'www.google.com'
puts b.title
b.close
headless.destroy
You will have to install Xvfb.
More information: http://watirwebdriver.com/headless/

Related

Open localhost:3000 in kiosk mode after the Node.js server has finished spinning up

I'm working on a raspberry pi project that involves running a node server in kiosk mode.
I'm using BROWSER=none to suppress the default opening of the localhost upon the server being run.
I'm thinking I should be able to use wait-on to force the bash script that runs the kiosk mode to wait until the server is fully up. Would I use something like this?
"scripts": {
...
"kiosk": "concurrently -n \"npm start\" \"wait-on http://localhost:3000 & /home/pi/kiosk.sh\""
},
It gives me the following error(s) which I'm not quite able to decipher:
[npm start] server does not have extension for -dpms option
[npm start] libEGL warning: DRI2: failed to authenticate
[npm start] [1498:1498:1125/180040.467781:ERROR:gpu_init.cc(441)] Passthrough is not supported, GL is egl
[npm start] [1498:1498:1125/180040.786918:ERROR:viz_main_impl.cc(162)] Exiting GPU process due to errors during initialization
[npm start] [1558:1558:1125/180041.392714:ERROR:gpu_init.cc(441)] Passthrough is not supported, GL is swiftshader
[npm start] [1443:1590:1125/180042.359030:ERROR:object_proxy.cc(622)] Failed to call method: org.freedesktop.DBus.Properties.Get: object_path= /org/freedesktop/UPower: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.UPower was not provided by any .service files
[npm start] [1443:1590:1125/180042.364570:ERROR:object_proxy.cc(622)] Failed to call method: org.freedesktop.UPower.GetDisplayDevice: object_path= /org/freedesktop/UPower: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.UPower was not provided by any .service files
[npm start] [1443:1590:1125/180042.367155:ERROR:object_proxy.cc(622)] Failed to call method: org.freedesktop.UPower.EnumerateDevices: object_path= /org/freedesktop/UPower: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.UPower was not provided by any .service files
[npm start] Fontconfig error: Cannot load default config file: No such file: (null)
I'm now realizing the error in my code has more to do with kiosk.sh than it does with the npm commands. Here's the code to kiosk.sh:
#!/bin/bash
xset s noblank
xset s off
xset -dpms
unclutter -root &
sed -i 's/"exited_cleanly":false/"exited_cleanly":true/' /home/pi/.config/chromium/Default/Preferences
sed -i 's/"exit_type":"Crashed"/"exit_type":"Normal"/' /home/pi/.config/chromium/Default/Preferences
/usr/bin/chromium-browser --noerrdialogs --disable-infobars --kiosk http://localhost:3000/ &
& and && mean different things, && means AND, & means background process, run that service in the background and continue with the next.
I think what you're trying to do is wait-on service && example, not wait-on service & example.
What will happen with what you've done is it will run the wait-on, then immediately background process it, then immediately run the shell script without waiting for anything. Your script will run before the server is up.
That's not really your issue though, I believe your issue is with chromium itself. There's an open issue for it here: https://bugs.chromium.org/p/chromium/issues/detail?id=1221905&q=Passthrough%20is%20not%20supported%2C%20GL%20is%20swiftshader&can=1. That issue was last updated earlier this year and seems to still be unresolved.
There was also another answer for it here: Passthrough is not supported, GL is disabled.
I've seen quite a few people suggest that you use --headless and --disable-gpu and --disable-software-rasterizer. People have mentioned that some of those options are only required on windows and some have already been fixed, I don't know which of those are actually required.
This answer here: Force headless chromium/chrome to use actual gpu instead of Google SwiftShader, mentioned that you can force webgl using --enable-webgl to prevent it from loading swiftshader and use the gpu. You can do this if you need to force it in headless mode.
It seems to have something to do with webgl or hardware acceleration. Apparently it happens if you've disabled gpu acceleration and then it's forced to fallback on swiftloader.
I don't know which one of those is actually going to help you, you'll have to play around with it. However I have seen over 10 different chromium and other related issues all made during 2021 because of this bug in chromium.
What's more is that I'm not sure it's actually a critical error, some people mention it's just showing the error but can be just ignored. I don't know if that's the case.
I assume that you are using the package "wait-on" (https://www.npmjs.com/package/wait-on). The wait-on command is used without npm in front of it.
Try to use
wait-on http://localhost:3000 && /home/pi/kiosk.sh
You could use the "child_process" npm package to execute your bash script once the server is ready. Assuming you use Express.js in your backend, this should work with little modification
const exec = require('child_process');
//all your other codes and whatevers
app.listen(3000, () => {
var kiosk = exec('sh kiosk.sh',
(error, stdout, stderr) => {
if (error) {
console.log(`exec error: ${error}`);
}
});
});
wait-on waits until the process is closed. You are not closing chromium so it never continues. If you want to wait until the server is running. You can log the server's status to a text file and have your bash script read it in a loop until it contains the ready text you specify.
If you want to confirm beyond a reasonable doubt that the server is running as needed.
You can install the npm package puppetter. Then use the create and run a node script from bash using page.goto command to load the web page in an instance of chromium and use waitForSelector to check if the DOM element of your web page exists.
Then you use call process.exit() with whatever error codes you want to use to confirm that the page is live and running.

Can I make Node.js opn open the browser with maximized window when Node.js itself is started in a minimized console window ( Windows 10 )?

My problem is that it seems that on Windows 10 a desktop link (.lnk) that opens a console application in a minimized window makes all windows opened by this console application to be also minimized.
I would like to start Node.js in a minimized console window, but at the same time make Node.js opn open the browser in a maximized window ( this makes sense, since I'm not interested in the console output, rather I want the output in the browser window ).
opn("http://localhost:9000") // but hey, in maximized window!
Is there any way I can achieve this either by Node.js or by some Windows manipulation?
I made it. It is a Windows trick.
Based on this answer:
How do I minimize the command prompt from my bat file
if not DEFINED IS_MINIMIZED set IS_MINIMIZED=1 && start "" /min "%~dpnx0" %* && exit
... script logic here ...
exit
This a trick for a script to run itself in a minimized window. But somehow the property inherited from the .lnk remains maximized, so the browser window opened by the script running in its self minimized window opens the browser maximized.
There is a workaround, at least in my used case. But this just minimized the node console only. It will still appear in the taskbar.
I just created a shortcut with
Target: C:\WINDOWS\system32\cmd.exe /c start /min node < Your Application >
Start in: < Path to your application >
"Start in" is not required if you specify the full path to your application
Examples:
Target: C:\WINDOWS\system32\cmd.exe /c start /min node "C:\Users\jjyong\Documents\Programming\Node\PriceTracking\app.js"
Or
Target: C:\WINDOWS\system32\cmd.exe /c start /min node app.js
Start in: C:\Users\jjyong\Documents\Programming\Node\PriceTracking
Note:
I have only tested using NodeJS version 12.13.1 with PuppeteerJS running chromium with "headless: false"

Running protractor tests on IE 11

OK, so I have been searching a lot to get proper solution to the blocker I am facing right now. Let me give you a background of what I have done so far :
I want to run protractor tests (located on Linux machine) on IE 11 of Windows Server 2012 R2 (IP : 10.81.73.248). My protractorTest.conf.js has below :
exports.config = {
seleniumAddress: 'http://10.81.73.248:4444/wd/hub',
baseURL: 'http://10.81.78.137:80000/',
capabilities: {
browserName: 'internet explorer',
platform: 'ANY',
version: '11'
},
On my Windows Server 2012 R2 machine, I've downloaded IEDriverServer_Win32_2.47.0 and placed it under C:\Windows\System32, environment variable PATH has been updated with above location. Protected mode settings are same for all zones. Windows machine also has selenium-server-standalone-2.48.2.jar placed under C:\Users\Selenium.
On Windows machine, I am starting selenium server using below command :
java -jar selenium-server-standalone-2.48.2.jar -port 4444 -Dwebdriver.ie.driver="C:\Windows\System32\IEDriverServer_Win32_2.47.0\IEDriverServer.exe" , which starts selenium server fine.
With above settings, I run protractor tests from my Linux machine using grunt protractor_test, which launches IE browser on Windows machine, shows localhost:dynamic port and a message as : This is the initial page of webdriver server and within 2 seconds, closes the browser.
The exception I get on selenium server terminal is as below :
Session ID is null. Using WebDriver after calling quit() ?
This is where I am stuck at. I looked at various posts which describes similar issue (?) as mine along with the potential solution, but I am unable to resolve my issue here.
Is there anything I might be doing wrong to setup the connections ? or am I missing some steps to get me through ?
I would really appreciate if you guide me in resolving this long time pending blocker.
I think you are trying to run using old selenium version.It should be 2.53.x something.
Few basics things to check first regarding IE execution:
1).IE Setting for protractor(Selenium)
http://elgalu.github.io/2014/run-protractor-against-internet-explorer-vm/
2).Take IE driver of 32 bit(don't take 64 it has known slowness issues) and manually copy on the following path:
Root Folder\node_modules\protractor\node_modules\webdriver-manager\selenium\IEDriverServer_Win32_2.53.1
3). IE Driver can be downloaded from following path:
http://selenium-release.storage.googleapis.com/index.html?path=2.53/
**OR**
Please upgrade your protractor version to latest like 4.0.11 by changing the version in package.json file and do from command prompt(inside project root directory):
npm update
and then give update your selenium driver with following command from command prompt
webdriver-manager update --ie
it will update the selenium version of IE driver to latest and then try running your tests again.

Parallel-test Cucumber watir testing with phantomjs ECONREFUSED

I`m having issues with phantomjs with my parallel testing, firefox is running fine. I use parallel_tests, watir-webdriver, and Cucumber.
No connection could be made because the target machine actively refused it. - connect(2) for "127.0.0.1" port 8910 (Errno::ECONNREFUSED)
Tests are running via:
parallel_cucumber features/parallel_tests -n 3
After some debugging I figured the problem appears when first process is finished with testing, it somehow kills all phantomjs browser instances.
This is env.rb setup:
browser = Watir::Browser.new :phantomjs, args: %w(--ignore-ssl-errors=true)
Before do
#browser = browser
#browser.cookies.clear
end
at_exit do
browser.close
end
I also tried not closing browser at all, but with no luck, it is somehow done automatically.
I tried both Windows, and CentOS.
phantomjs -v
2.0.0
Using cucumber 1.3.19
Using selenium-webdriver 2.45.0
Using watir-webdriver 0.6.11
Using parallel 1.4.1
Using parallel_tests 1.3.9
I have a feeling it is a phantomjs/webdriver bug...
This is likely a race condition to port 8910 by your 3 phantom instances. Similar to this issue.
# env.rb
Before do
sleep ENV['TEST_ENV_NUMBER'].to_i
#browser = Watir::Browser.new :phantomjs, args: %w(--ignore-ssl-errors=true)
end
If I'm reading the ParallelTests source correctly, environment variable TEST_ENV_NUMBER is set to the process index for each process. So the first process has a TEST_ENV_NUMBER of 0. As long as that's the case, the Before hook above will sleep for that number of seconds before initializing Watir::Browser. That will stagger the the parallelization a bit, but it should remove the race condition.

Can I install an app as certified on my own phone? (Firefox OS)

Is there any way that I can develop an app for Firefox OS that uses a certified API and install it on my own phone?
Our specific need is for telephony data such as signal strength. We can do this on Android without any difficulty (indeed, we could put the app on Google Play if we wanted to). But we just need to install it on a small number of in-house phones.
It seems that Firefox OS considers it to be in some way a security risk to find out the signal strength of the cell tower, and similar telephony data. Am I correct in assuming that there is no way that Firefox OS will let a developer app read this data?
If you are using Firefox OS 1.2 > you should be able to push a certified app to a unlocked phone for testing purposes. I put in code like:
testconn.onclick = function () {
var cnx = navigator.mozMobileConnection;
if (cnx.voice.connected) {
console.log("The signal has a strength of " + (+cnx.voice.relSignalStrength) + "%");
} else {
console.log("The state of the connection is: " + cnx.voice.state);
}
};
and entered the following permission in the manifest:
"permissions": {
"mobileconnection":{}
},
"type": "certified"
You should be able to install your certified app on a real Firefox OS phone after performing these steps from MDN:
On your computer, enter the following command in Terminal/console to enter your device's filesystem via the shell:
adb shell
Your prompt should change to root#android.
Next, stop B2G running using the following command:
stop b2g
Navigate to the following directory:
cd /data/b2g/mozilla/*.default/
Here, update the prefs.js file with the following line:
echo 'user_pref("devtools.debugger.forbid-certified-apps", false);' >> prefs.js
After you've finished editing and saving the file, start B2G again using the following command:
start b2g
Exit the android filesystem using the exit command; this will return you to your normal terminal prompt.

Resources