Node Readline functionality in phantomjs / casperjs - phantomjs

Is there an easy way to have interactive user input in a PhantomJS / CasperJS application (arrow keys, command history, tab-completion, etc.)? NodeJS's Readline module (https://nodejs.org/api/readline.html) provides much of this functionality, but Casper does not allow importing standard Node modules...

PhantomJS supports blocking versions of stdin, stdout and stderr:
var system = require("system");
console.log("in: " + system.stdin.readLine());
phantom.exit();
You can write your own custom version of REPL with this function.

Related

Can TestCafe be configured with single file reporter

I have been working in TestCafe recently and I need a custom reporter. I was looking for something like mocha reporter. But all I could find is generating a plugin and publish it to npm. Is there a way to have a single file reporter?
Is there a way to have a single file reporter?
You can redirect the reporter's output to the file.
testcafe chrome test.js -r spec:result.txt
I was looking for something like mocha reporter.
TestCafe ships with 5 reporters: spec, list, minimal, xUnit, JSON. Also, many custom reporters can be find in npm: https://www.npmjs.com/search?q=testcafe-reporter.

How to get rid of the BrowserStack Local extension popup using ChromeDriver Chrome and Selenium

Am just new to automation and trying to automate browserstack. And i successfully logged to browserStack and passed the credentials and clicked on adding chrome extension . There comes the popup and am unable to get the selector for the buttons in the popup.Did any body face across this issue.
Am using an internal tool to automate,behind the scene i guess its using selenium.
Can anybody help me to find the selectors for the popup in browser stack.
Will attach the screenshot
Any help will be hihly helpful,since its a big blocker for me
If you want to Automate a local hosted URL or internal URL you will have to use BrowserStack Local testing feature. There is no need to add this extension.
There is one documentation on How to Perform local testing. All the steps are mentioned in the documents.
BrowserStack Automate Local Testing
If your usecase involves adding the BrowserStack Local or any other extension as a part of your Test Strategy you need to do it programatically.
You can find a couple od relevant discussions in:
How to install extension permanently in geckodriver
How to load extension within chrome driver in selenium with python
Alternative
As an alternative you can enable Enabling Local Testing either programatically through language bindings or through the command-line interface as follows:
Using language bindings:
Java:
import com.browserstack.local.Local;
# creates an instance of Local
Local bsLocal = new Local();
# replace <browserstack-accesskey> with your key. You can also set an environment variable - "BROWSERSTACK_ACCESS_KEY".
HashMap<String, String> bsLocalArgs = new HashMap<String, String>();
bsLocalArgs.put("key", "<browserstack-accesskey>");
# starts the Local instance with the required arguments
bsLocal.start(bsLocalArgs);
# check if BrowserStack local instance is running
System.out.println(bsLocal.isRunning());
#stop the Local instance
bsLocal.stop();
Steps for using command line:
Download the matching binary for your os: OS X / Linux 32 bit / Linux 64 bit / Windows
Untar/Unzip the binary to a folder/directory on your system.
Open your command-line interface and navigate to the folder containing the Local binary.
Run the binary using the following command:
//OS X/Linux
./BrowserStackLocal --key ACCESS_KEY
//Windows
BrowserStackLocal.exe --key ACCESS_KEY
Configure tests to run with Local Testing connection as follows:
caps.setCapability("browserstack.local", "true");

PhantomJS Hanging Because It Doesn't Find Existing Resources

I am running Flask(0.10.1), Python (2.7), Ubuntu(14.04) and PhantomJS(1.9).
I am using PhantomJS to capture a map image, but it hangs because it is not able to find local and remote resources(a local css file and JQuery from a CDN) that I am sure exist(I am able to get those resources using Firefox, curl and wget without any issue).
By the way I have noticed inexplicable behavior such as when running phantomjs directly from the terminal the capture fails,
phantomjs myscript.js
but as soon as I had strace it succeed.
strace phantomjs myscript.js
But then when I start phantomJS with strace through python subprocess it fails again.
subprocess.call(["/usr/bin/phantomjs", "myscript.js"])
Here is what strace display each time it fails:
select([4], [3], [], [], NULL)
My phantomjs script is simple. I am trying to capture a page and I have added wait time because sometime it allows phantomjs to find the resources(a local css file and JQuery from a CDN).
page.open('http://127.0.0.1:xxxx/get-report-map', function() {
window.setTimeout(function() {
page.render('~/github24.png');
phantom.exit();
}, 8000);
});
Has anybody faced similar issues and how did you solve it?

Setting up JS debugging with IntelliJ/WebStorm and PhantomJS/Casper

Can I get an interactive JS debugger working on PhantomJS and/or CasperJS?
I didn't solve this entirely, but I definitely reduced the pain.
PhantomJS provides a command line argument to enable webkit's remote debugger. AFAIK, PhantomJS launches a server and dumps the script into the <head> of a webpage with the familiar in-browser debugger. It's actually pretty nice, with breakpoints, etc. However, switching to manually digging around in the terminal for a random command line parameter and the path to your script is seriously irritating.
So, I used IntelliJ's "external tools" feature to launch a Bash script that kills any previous debugging session, launches PhantomJS, and then opens the page up in Chrome.
#!/bin/bash
lsof -i tcp#0.0.0.0:9000 #list anything bound to port 9000
if [ $? -eq 0 ] #if something was listed
then
killall 'phantomjs'
fi
/usr/local/Cellar/phantomjs/2.0.0/bin/phantomjs --remote-debugger-port=9000 $1 &
# --remote-debugger-autorun=yes <- use if you have added 'debugger;' break points
# replace $1 with full path if you don't pass it as a variable.
sleep 2; #give phantomJS time to get started
open -a /Applications/Google\ Chrome.app http://localhost:9000 & #linux has a different 'open' command
# alt URL if you want to skip the page listing
# http://localhost:9000/webkit/inspector/inspector.html?page=1
#see also
#github.com/ariya/phantomjs/wiki/Troubleshooting
The next few lines are settings for IntelliJ, although the above code works just as well on any platform/IDE.
program: $ProjectFileDir$/path/to/bash/script.sh
parameters: $FilePath$
working dir: $ProjectFileDir$
PhantomJS has a remote-debugger-port option you can use to debug your casper script in Chrome dev tools. To use it, simply execute your casper script with this argument:
casperjs test script.js --remote-debugger-port=9000
Then, open up http://localhost:9000 in Chrome and click on the about:blank link that presents itself. You should then find yourself in familiar Chrome dev tools territory.
Since this is a script and not a web page, in order to start debugging, you have to do one of two things before your script will execute:
In the Chrome dev tools page, open the console and execute __run() to actually start your script.
Insert a debugger; line in your code, and run your casper script with an additional --remote-debugger-autorun=yes argument. Doing so with the remote debug page open will run the script until it hits your debugger; line.
There's a great tutorial that explains this all very nicely.

Geb $ function not found when using Cucumber via Cuke4Duke

I'm using Cuke4Duke to run my Cucumber tests. I'm using Geb (Geb Manual) to control the browser.
Does anyone know how to configure Cucumber/Geb so that the $ function (Geb $ Function) is available to Cucumber tests?
browser.$() seems to work fine. would be nice not to have to type browser though.