Driving Nightwatch Tests through REPL - selenium

I currently have nightwatch.js setup using the vue automated setup. That template is located here.
https://github.com/vuejs-templates/webpack/tree/master/template/test/e2e
Is it possible to run nightwatch assertions through the command line in a REPL like fashion that is available in webdriver.io? Here is a reference to the webdriver feature https://twitter.com/webdriverio/status/806911722682544128
Update, we have moved to using Cypress.io It has made us pretty happy

You can use nightwatch-repl package available on NPM.
https://www.npmjs.com/package/nightwatch-repl
// nightwatch.conf.js
var repl = require('nightwatch-repl');
module.exports = (function (settings) {
repl.init(settings);
...
...
return settings;
})(require('./nightwatch.json'));
Once you run your tests and invoke browser.repl()
you should see the following in your console
Running: Login to dashboard
Type in a command (eg: browser.function()) or type "quit" to exit
repl>

Related

SAUCE_CONFIG_PATH is not working for me in testcafe-browser-provider-saucelabs

I am trying to use testcafe-browser-provider-saucelabs.
My tests can successfully connect to SauceLabs and run there, but testcafe creates a unique sauceconnect tunnel, whereas I need to use a shared tunnel. Also, screenResolution is not being picked up from sauceLabsConfig.json file.
I have saucelabs credentials set as environment variables.
I am launching tests using these commands:
export SAUCE_JOB="Regression Job"
export SAUCE_BUILD="Build 1"
export SAUCE_CONFIG_PATH="./sauceLabsConfig.json"
testcafe saucelabs:chrome tests/
I created a sauce config JSON file:
{
"parentTunnel": "PARENT_TUNNEL",
"tunnelIdentifier": "qa",
"screenResolution": "1920x1080"
}
Why is my SAUCE_CONFIG_PATH variable not working?
At present, not all SauceLabs options are supported for the 'testcafe-browser-provider-saucelabs'. For example, the tunnelIdentifier option is not supported. I've created an issue in the browser provider repository. Track it be informed about the progress.
Note that this issue seems to be fixed, per this pull request:
https://github.com/DevExpress/saucelabs-connector/pull/33
...and integrated in to testcafe 1.14.0:
https://github.com/DevExpress/testcafe/tree/v1.14.0

Test VueJs localization using Nightwatch

I have an application that I started in English from scratch. I had nightwatch tests and everything is working perfectly fine... but after adding 2 more languages, I want the main tests to run as they used to in English, then change the browser language (since that's the criteria on which I choose the language) so I can run the other tests in German or French... etc. Is there a way to start a test suite by changing the browser's language?
I looked into the documentation and found nothing in this area
In order to set the language and run the tests locally, I did the following:
chrome: {
desiredCapabilities: {
chromeOptions: {
prefs: {
intl: { accept_languages: "ss-ZA" }
}, args: []
}
}
}
this allows you to run the tests locally, on only that language. or you can manage setting that locale code to a variable in a way and try setting it at the beginning of your test suite.
I did not get that far, because in my case, I have to run my tests headless because they will run later on a remote git server that runs only headless tests. According to this issue on Nightwatch's github page, setting a browser language parameter for a headless test is not possible!

Run Same Testcafe tests with different URLs per environment

I am working on a TestCafe proof of concept. I have a few tests working in one test environment. I need a way to run the same tests in up to 3 different test environments that have different URLs. Is there a best practice for this scenario?
A solution is to add custom options on the testcafe command-line like for example : --env=uat.
Use minimist to read all custom options that you have added to the TestCafe command-line and export a config object like this:
import * as minimist from 'minimist';
const args = minimist(process.argv.slice(2));
// get the options --env=xxx --user=yyy from the command line
export const config = {
env: args.env,
user: args.user,
};
Then import that config object wherever you need it in the test code.
see How do I work with configuration files and environment variables? for more details.
In v1.20.0 and later, TestCafe offers a way to specify the baseUrl in the test run setup:
CLI
Program API runner.run({baseUrl})
Config file
You can use this approach along with environment variables or custom command line arguments to determine what url should be assigned to the baseUrl option.
Alternatively, you can have a different configuration file for each test run setup and switch between these files using the --config-file option.

Can I run Durandal's Tests Framework outside of PhantomJS?

The Durandal Test Framework runs Jasmine tests within PhantomJS.
Where I'm implementing this for the first time I'm getting a lot of errors, and reading through these on the command prompt is proving to be very tedious.
If I load up the spec.html file in my web browser, it tells me that no specs were found:
Yet PhantomJS is able to find the specs with no problem:
Is there a way I can configure these Jasmine tests to run through my web browser and not through (or as well as) PhantomJS?
I've set up a new index.html file and have replaced the var runTests = ... section with a simple require() call:
require(['../test/specs/system.spec.js']);
Durandal's system.spec.js file is loaded in the browser, but Jasmine is still stating that no specs were found.
Jasmine's tests weren't being run because I wasn't telling it to re-execute. The solution to this was to simply re-execute by calling this within the require callback:
require(['../test/specs/system.spec.js'], function() {
jasmine.getEnv().execute();
});
Note: A drawback of this is that the 'no specs found' bar is still present and the 'raise exceptions' control on the re-executed specs doesn't appear to function:

How to skip tests in PHPUnit if Selenium server is not running?

I want to add a suite of Selenium tests as part of a global PHPUnit test suite for an application. I have hooked the suite of Selenium tests into the global AllTests.php file and everything runs fine whilst the Selenium server is running.
However, I would like the script to skip the Selnium tests if the Selenium server isn't running so other developers aren't forced to install Selenium server in order for the tests to run. I would normally try to connect within the setUp method of each testcase and mark the tests as skipped if this failed, but this seems to throw a RuntimeException with message:
The response from the Selenium RC server is invalid: ERROR Server Exception: sessionId should not be null; has this session been started yet?
Does anyone have a method for marking the Selenium tests as skipped in this scenario?
You could use test dependencies that were introduced in PHPUnit 3.4.
Basically
write a test that checks whether Selenium is up.
If not, call $this->markTestAsSkipped().
Make all your selenium requiring tests depend on this one.
My preferred selenium / PHPUnit Configuration:
Maintaining integration (selenium) tests can be a lot of work. I use the firefox selenium IDE for developing test cases, which doesn't support exporting test suites to PHPUnit, and only supports individual test cases. As such - if I had to maintain even 5 tests, that'd be a lot of manual work to re-PHPUnit them every time they needed to be updated. That is why I setup PHPUnit to use Selenium IDE's HTML Test files! They can be reloaded & reused between PHPUnit & selenium IDE
<?php
class RunSeleniumTests extends PHPUnit_Extensions_SeleniumTestCase {
protected $captureScreenshotOnFailure = true;
protected $screenshotPath = 'build/screenshots';
protected $screenshotUrl = "http://localhost/site-under-test/build/screenshots";
//This is where the magic happens! PHPUnit will parse all "selenese" *.html files
public static $seleneseDirectory = 'tests/selenium';
protected function setUp() {
parent::setUp();
$selenium_running = false;
$fp = #fsockopen('localhost', 4444);
if ($fp !== false) {
$selenium_running = true;
fclose($fp);
}
if (! $selenium_running)
$this->markTestSkipped('Please start selenium server');
//OK to run tests
$this->setBrowser("*firefox");
$this->setBrowserUrl("http://localhost/");
$this->setSpeed(0);
$this->start();
//Setup each test case to be logged into WordPress
$this->open('/site-under-test/wp-login.php');
$this->type('id=user_login', 'admin');
$this->type('id=user_pass', '1234');
$this->click('id=wp-submit');
$this->waitForPageToLoad();
}
//No need to write separate tests here - PHPUnit runs them all from the Selenese files stored in the $seleneseDirectory above!
} ?>
You can try skipWithNoServerRunning()
For more information follow this link