Running Automation test in PhantomJS through Webdriver-IO - javascript

I have been trying to run my tests on phantomjs, directly through mocha, or wdio or gulp, But every time tests dies out with error of timeout. Though tests run perfectly on chrome and firefox, its just in phantomjs I get an error. I have installed phantom js globally and and in my project, but I am unable to get it work since last 2 days.
that's how I have done it the test
before( function (done) {
driver = webdriverio.remote({ desiredCapabilities: {
browserName: 'phantomjs'
} });
driver.init(done);
});
Link to my project : https://github.com/anarwal/asg...
NOTE: I run tests on windows, that is where the problem is, they work fine on MAC

When you use a headless browser you need a selenium server running.
There is an very well explained example using javascript Here.

You may find Chimp.js useful as it easily allows you to use Chrome or FF locally but PhantomJS on the server. See: http://chimpjs.com/
Chimp.js works by "seamlessly integrating CucumberJS / Mocha, Selenium, WebdriverIO and Chai / Jasmine Expect to work in unison. It's designed to take away all the pain that comes with setting up these tools to play nicely together..." - Read more at: https://chimp.readme.io/docs

Related

Open Cypress browser when running from Jenkins

I created in Jenkins a freestyle project in which I wanted to run Cypress.
In the command line I used this command line:
npx cypress run --browser chrome --headed --spec "cypress/integration/examples/actions.spec.js" --config pageLoadTimeout=10000
The issue that it runs silent mode, there is no browser that is open, and perform test actions.
What should I do so that the browser appears while executing the test? Thanks in advance.
CI tools like Jenkins aren't designed to open browser.
That is why Cypress offers two ways to run it:
For local dev/debug: cypress open
For CI/automatisation : cypress run
You are using it the right way.
Interesting things for CI are screenshots and videos.
Yes, actually when you launch tests based on Cypress on CI (not only Jenkins) - you can't watch the process in debug mode.
Only on the local machine with the open parameter.
Also, save the video OR screenshots of running tests from Jenkins - and look after

Cannot Run Nightwatch Tests in Safari

I have followed all instructions in the Nightwatch docs and followed many issues in github. I believe I have the correct setup in my nightwatch.json for safari. Safari does launch when I run a test against it but then all the commands in my test fail. For example I have a global beforeEach to resize the browser window which works great in Firefox and Chrome but fails in Safari with
The command 'POST /session/FA198F5F-EE09-4129-9FF0-F55FEA0EE6F0/window/current/size' was not found.
If I remove that then the first step in my test (which is a waitForElementVisible test fails with the error of
The command 'GET /session/FA198F5F-EE09-4129-9FF0-F55FEA0EE6F0/element/node-F5A12DD5-2557-4AE6-806A-0A0B99B63EFC/displayed' was not found.
Again, I'm certain my config is setup properly as nightwatch is launching the safari browser but then failing on the test commands. I have enabled safaridriver and checked 'Allow Remote Automation' but everything still fails. Has anyone run into this issue?
If you used Appium and the XCUITest driver as your WebDriverAgent then you can use browser.execute('mobile:gesture',{arguments}) to replace all the 'Element Interaction' commands. The full list of gestures can be found here
For the command like waitForElementVisible(), you can use the assertions commands instead (in my case I have used assert.visible('element css selector')).
Hope they will change things in NightWatch v2 but for now we can only work around that

Console log is not working with Netbeans (Android emulator and Cordova)

Everything works fine except there is no output when calling console.log(...) in the Browser window log (Netbeans).
I created a new HTML5 (Cordova Application) project in Netbeans.
I start the android emulator (Intel Atom x86 API Level 19. Galaxy Nexus. With Use Host GPU option checked). Then build/run the project BUILD SUCCESSFUL (total time: 10 seconds) and I can see the app running in the emulator with the 'Device is ready' text blinking.
But there is not console log output. I have made sure the Debugger Console plugin is selected (inside the project properties). I also have added android:debuggable="true" inside <application .../> tag in AndroidManifest.xml file. And still no console log output.
I have also tested with API 21 and still no ouput from console.log
What am I missing?
I'm using cordova 4.3.0, Netbeans 8.0.2, Java version: 1.8.0_45, Apache Ant 1.9.4.
Thanks in advance.
UPDATE: I can see the log entry with DDMS but since I'm using Use Host GPU, Logcat is spammed with an error and by the looks of it, the filter doesn't work as expected and sometimes it stops logging for whatever reason (DDMS). At least I know the console.log call works inside the javascript. By the looks of it, DDMS is buggy.
I think I found out why Netbeans isn't picking up any log output.
Debugger console seems to only work for Xcode and/or maybe Netbeans isn't configured to get any log from LogCat. Cordova redirects console.log calls to their respective platform logger. That's why I can see the log entry just fine with adb logcat -s "CordovaLog" (CordovaLog being the tag to filer).
Edit:
Netbeans doesn't connect fast enough and it doesn't show you earlier logs. I recommend to use Chrome remote debugging instead of Netbeans.
While this is not a direct answer to your question, NetBeans personally recommends that you use Chrome with their extension for HTML5 projects:
https://netbeans.org/kb/docs/webclient/html5-gettingstarted.html
Hope that works for you!
2 things that might help: Make sure you have Cordova plugin called "Debugger Console" in your project
Second thing try to use NetBeans dev build from here . The dev build contains importnant fix - IDs of core Cordova plugins has been changed recently and as a result NetBeans could be removing these plugins from build when building the project.

What is a good headless browser to run with protractor?

New User here.
After hours of building my smoke and regression tests, I found out after reading many cases online that phantomjs is known to be a trouble to run with protractor. Jenkins has been running phantomjs for all the tasks it has been given so far.
They need these tests to run as part of ci which does not have a windowing system installed.
So I would appreciate it if there is a recommendation for completely headless browser or a headless chrome(that would be most beneficial) and a step by step to set it up. I already have a conf.js and a e2e.conf.js file. My code works perfectly fine with chrome.
I am on a iMac and selenium webdriver, I believe.
Edit: Problem = protractor doesn't work with phantomjs.
What I have done = use different web elements and googled if anyone has faced a similar situation. Also googled for headless browsers that worked for protractor, unable to find a suitable solution.
If anyone reached here - the answers are outdated.
Chromium (on next release) now supports headless mode. no need to work hard.
You can read more here:
https://developers.google.com/web/updates/2017/04/headless-chrome
Here is an example from command line
chrome \
--headless \ # Runs Chrome in headless mode.
--disable-gpu \ # Temporarily needed for now.
--remote-debugging-port=9222 \
https://www.chromestatus.com # URL to open. Defaults to about:blank.
And you can simply trigger protractor with capabilities for chrome:
Activating chrome language flags when activating from protractor (selenium)
Here is the configuraiton I am using
capabilities: {
'browserName': browserName,
chromeOptions: {
binary: '/Users/guymograbi/Downloads/chrome-mac/Chromium.app/Contents/MacOS/Chromium',
args: ['--headless','--disable-gpu']
}
},
Update - new versions of chrome doesn't require binary property
In my environments I found I can remove the binary property as new version of chrome is available on stable branches
My protractor configuration is
capabilities: {
'browserName': 'chrome',
chromeOptions: {
args: [ '--headless', '--disable-gpu', '--no-sandbox', '--window-size=1920x1200' ]
},
},
And it works smoothly for weeks now. highly recommended.
Update - how to do this in karma is super easy
Using headless chrome in karma is super easy:
browsers: 'ChromeHeadless'
it should work with the chrome loader and everything. more info
Your best bet is to continue with Chrome. With a bit of work you can get it to work via a CI and in a headless manner - we do this using Jenkins and Docker Ubuntu servers which are headless.
You will need to configure Chrome to run headless using XVFB. You can start off by following the gist here https://gist.github.com/addyosmani/5336747
You state you are on a Mac so you can either run the headless tests via Docker on your machine or you could set up a second config for the CI tests.
Another resource http://tobyho.com/2015/01/09/headless-browser-testing-xvfb/
I would continue testing in normal browsers with a head, but would use a remote selenium server as a service - Sauce Labs or BrowserStack, see:
Integration Testing with Protractor, WebdriverJS and Sauce Labs
Running Protractor tests on Browserstack Automate
automate-node-samples
You could run your Protractor tests against CodeShip or Drone.io, both of which offer Chrome and/or Firefox running headless for free. No really...
If you've got Chrome 59+ installed, start Chrome with the following flag:
--headless
please let me know if you need more help, will write the config for you :) enjoy

How do you get webdriverjs working?

Anyone here have experience using Selenium and webdriverjs? I'm coming from a non-Java background with a good deal of experience with Node.js and JavaScript in general. According to the Selenium docs, you have to set-up a stand-alone Selenium server to use the node web driver. Fortunately, they seem to be bundled together.
npm install webdriverjs
gets you the JAR file for the standalone selenium server inside the node_modules/webdriverjs/bin directory. Example tests are inside the node node_modules/webdriverjs/examples directory but the tests in them fail when I run them from either the webdriverjs or examples directories.
What's the missing piece here? What's the quickest way to get up and running?
I have read the docs.
Note: Stack overflow wouldn't let me use the tag webdriverjs, but this is specifically about webdriverjs, not using selenium with Java or other languages.
Update: The only problem was that the built-in example tests are broken!
Here's what I did to get webdriverjs working:
Step 1: start selenium standalone in my laptop by running command java -jar selenium-server-standalone-2.33.0.jar. then it will listen to http://localhost:4444/ and you can access it via http://localhost:4444/wd/hub/. You also need to make sure Firefox browser is installed on your laptop.
Step 2: create a new directory and run command npm install webdriverjs.
Step 3: create a new file named test_webdriverjs.js in the new directory you created, and it looks like this:
var webdriverjs = require('webdriverjs');
var client = webdriverjs.remote({
host: 'localhost',
port: 4444
});
client.init();
client.url('https://github.com/')
.getTitle(function(err, title) { console.log (title)}).call(function () {});
client.end();
Then run command node test_webdriverjs.js under the same directory and you will find it works. If it doesn't work, paste out the console output.

Categories