theintern calling /__intern/client.htm in URL - selenium

I want to run intern tests locally with selenium-standalone both of which i installed through npm.
when i go to run the tests -> "./node_modules/.bin/intern-runner" config=./pmictests/test/bit/GAT/internEx/intern
the browser starts but the url goes to http://localhost:8585/__intern/client.html?config=.%2Fpmictests%2Ftest%2Fbit%2FGAT%2FinternEx%2Fintern&basePath
As in the _intern/client.html? is not what i want
why is this happening? i'm trying to get my head around it but been stuck on this problem for a while.
my config file looks like this:
define({
proxyPort: 9515,
proxyUrl: 'http://localhost:8585/',
tunnel: 'NullTunnel',
useSauceConnect: false,
capabilities: {
'fixSessionCapabilities' : false,
'selenium-version': '2.35.0',
'idle-timeout': 36
},
environments: [
{ browserName: 'chrome' }
],
maxConcurrency: 3,
useSauceConnect: false,
webdriver: {
host: 'localhost',
port: 4444
},
suites: [ './tests/test/' ],
excludeInstrumentation: /^(?:tests|node_modules)\//
});

That URL is for running unit tests. When you run intern-runner, it automatically loads client.html to run any unit test suites listed in suites. Once the unit tests are finished, Intern runs any functional tests listed in functionalSuites (which will load their own URLs).

Related

Nightwatch tests fail when running in docker using selenium/chromedriver

I am running my whole system using docker-compose and I am trying to execute my end-to-end tests (written with Nightwatch) using a selenium/chrome service that is in the same network. My frontend is VueJS and the image is built from a node base image. I am running the tests with docker-compose exec frontend npm run test-selenium and getting the following output:
> frontend#0.1.0 test-selenium
> nightwatch -c nightwatch-selenium.conf.js
[Login Test] Test Suite
──────────────────────────────────────────────
ℹ Connected to chrome on port 4444 (1494ms).
Using: chrome (102.0.5005.61) on LINUX.
Running login:
───────────────────────────────────────────────────────────────────────────────────────────────────
ℹ Loaded url http://frontend:8090/login in 2049ms
NoSuchElementError: An error occurred while running .click() command on <Element [name=#loginBt]>: Timed out while waiting for element "#loginBt" with "css selector" to be present for 5000 milliseconds.
at Object.login (/app/tests/loginTest.js:8:8)
NoSuchElementError: An error occurred while running .setValue() command on <Element [name=#emailField]>: Timed out while waiting for element "input[name = "email"]" with "css selector" to be present for 5000 milliseconds.
at Page.fillUpData (/app/tests/page-objects/loginPage.js:13:21)
at Object.login (/app/tests/loginTest.js:9:8)
NoSuchElementError: An error occurred while running .setValue() command on <Element [name=#passField]>: Timed out while waiting for element "input[name = "password"]"
with "css selector" to be present for 5000 milliseconds.
at Page.fillUpData (/app/tests/page-objects/loginPage.js:13:21)
at Object.login (/app/tests/loginTest.js:10:8)
NoSuchElementError: An error occurred while running .click() command on <Element [name=#submitBt]>: Timed out while waiting for element "button[name = "submit"]" with
"css selector" to be present for 5000 milliseconds.
at Object.login (/app/tests/loginTest.js:11:8)
✖ Testing if the URL contains '/cards' in 5000ms - expected "contains '/cards'" but got: "http://frontend:8090/login" (5143ms)
at Object.login (/app/tests/loginTest.js:12:15)
FAILED: 1 assertions failed and 4 errors (28.22s)
When running tests locally, everything is working just fine. For local tests, I am using the chrome driver installed as dev dependency, accessing the frontend using http://localhost:8090/.
It is my first time dealing with E2E tests in docker, so I am not really sure what is going wrong. Any help is appreciated. Please find the source code below. Let me know if I need to add any more information.
package.json
"scripts": {
...
"test": "nightwatch",
"test-selenium": "nightwatch -c nightwatch-selenium.conf.js",
...
},
docker-compose.yml
services:
frontend:
build:
context: card-market-frontend/
dockerfile: Dockerfile
command: npm run serve
working_dir: /app
ports:
- "8090:8090"
chrome:
image: selenium/standalone-chrome:latest
hostname: chrome
privileged: true
shm_size: 2g
When running the tests with the test-selenium command I am using the nightwatch.conf below:
const chromedriver = require("chromedriver");
require("dotenv").config();
module.exports = {
src_folders: ["/tests"],
page_objects_path: ["tests/page-objects"],
test_workers: false,
selenium: {
start_process: false,
cli_args: {
"webdriver.chrome.driver": chromedriver.path,
},
},
webdriver: {
start_process: false,
},
test_settings: {
default: {
selenium_port: 4444,
selenium_host: "chrome",
screenshots: {
enabled: true,
path: "tests_output/",
on_failure: true,
},
desiredCapabilities: {
browserName: "chrome",
chromeOptions: {
w3c: false,
args: ["--no-sandbox"],
},
},
},
},
};
My page object loginPage.js
module.exports = {
url: `http://frontend:8090/login`,
elements: {
logoutBt: "#logoutBt",
loginBt: "#loginBt",
emailField: 'input[name = "email"]',
passField: 'input[name = "password"]',
submitBt: 'button[name = "submit"]',
},
commands: [
{
fillUpData(selector, data) {
return this.setValue(selector, data);
},
},
],
};
The test that is running loginTest.js
module.exports = {
login(browser) {
const page = browser.page.loginPage();
const email = "coolEmail#gmail.com";
const pass = "coolPass";
page
.navigate()
.click("#loginBt")
.fillUpData("#emailField", email)
.fillUpData("#passField", pass)
.click("#submitBt")
.assert.urlContains("/cards");
},
};
Your first error is:
NoSuchElementError: An error occurred while running .click() command on <Element [name=#logoutBt]>: Timed out while waiting for element "#logoutBt" with "css selector" to be present for 5000 milliseconds.
which indicates that NoSuchElementError was raised while searching for the Logout button.
However as per the test steps within loginTest.js, ideally you are not supposed to find the Logout button just after navigating to the page:
.navigate()
.click("#logoutBt")
You can find the Logout button only after logging in.
Solution
Ideally, the sequence of the commands will be:
page
.navigate()
.click("#loginBt")
.fillUpData("#emailField", email)
.fillUpData("#passField", pass)
.click("#submitBt")
.assert.urlContains("/cards");
.click("#logoutBt")

Can I run Nightwatch js in paralell with a different env per worker?

I'm currently using Nightwatch js to run my E2E tests in paralell.
The issue I'm having is that my tests share the same database, which is causing me problems with shared data being rewritten across different tests/workers, resulting in flaky tests.
I thought about running each test worker with its own database, but I'm not sure how to do it in practice. My starting point would be having different settings for the test databases, each on a night-watch env which can be accessed by the individual workers, but so far I've not found if this would be possible.
Any ideas?
Yes you can run different tests on different workers, Nightwatch provides a way to do that. I have done something very similar where I ran the same test on three different browsers parallely.
You have to add the test_Worker configuration, which allows the tests to be run in parallel. When this is enabled the test runner will launch a configurable number of child processes and then distribute the loaded tests over to run in parallel.
The workers option configures how many child processes can run concurrently.
a) “auto” – determined by the number of CPUs e.g. 4 CPUs means 4 workers
b) {number} – specifies an exact number of workers
test_workers: {
enabled: true,
workers: 'auto'
}
This is how my Nightwatch.conf.js file looks like:
{
module.exports = {
src_folders: ["tests"],
test_settings: {
default: {
desiredCapabilities: {
browserName: 'chrome'
},
webdriver: {
start_process: true,
port: 4444,
server_path: require('chromedriver').path,
}
},
test_workers: {
enabled: true,
workers: 'auto'
},
safari: {
desiredCapabilities: {
browserName: 'safari',
alwaysMatch: {
acceptInsecureCerts: false
}
},
webdriver: {
port: 4445,
start_process: true,
server_path: '/usr/bin/safaridriver'
}
},
firefox: {
desiredCapabilities: {
browserName: 'firefox'
},
webdriver: {
start_process: true,
port: 4446,
server_path: require('geckodriver').path
}
}
}
}
Now to execute the test I use the command:
npx nightwatch tests/TC001_WikiSearch.js -e default,firefox,safari
Referenced from: https://testersdock.com/execute-parallel-tests-nightwatchjs/

Is it possible to run Protractor Test Suites in Parallel?

I have protractor config file :
exports.config = {
suites: {
BVT : 'e2e/TestSuites/_BVT/*.js',
Full : 'e2e/TestSuites/Full/**/*.js',
Smoke : 'e2e/TestSuites/Smoke/*.js',
Login1 : 'e2e/TestSuites/Login/*.js'
};
capabilities: {
'browserName': 'chrome',
shardTestFiles: true,
maxInstances: 3
};
};
I have tried above but my Test Suite doe not run in parallel, is it possible to run BVT, Full and Smoke Test suites in parallel on chrome browser.
Yes possible for sure. Take a look how i am running regression and sanity in the suites.
protractor Test/config.js --suites regression,sanity

How to skip protractor+jasmine tests specific to browsers

Assume that I've automated 25 tests and executing in multiple browsers like chrome, firefox, IE, Edge & Safari. All tests (25) are executing well on Chrome. In Firefox, Only 20 tests are running fine due to few protractor APIs are not supported. Similarly IE can execute only 23 tests.
I would like to skip the test only for browsers, which are not supported for particular test? Is there any way available?
You can create protracotr.conf file for each browser with specific suites where will be specified what tests should run. And execute in one time all protractor.conf files.
//protractor.chrome.conf
export let config: Config = {
...
capabilities: {
browserName: 'chrome',
shardTestFiles: true,
maxInstances: 1
},
SELENIUM_PROMISE_MANAGER: false,
specs: [
'../test/chrome/**/*.js'
]
};
and
//protractor.ie.conf
export let config: Config = {
...
capabilities: {
browserName: 'internet explorer',
shardTestFiles: true,
maxInstances: 1
},
SELENIUM_PROMISE_MANAGER: false,
specs: [
'../test/ie/**/*.js'
]
};
in your package.json:
{
...
"scripts": {
"test:all": "npm run test:chrome && test:ie",
"test:chrome": "protractor ./config/protractor.chrome.conf.js",
"test:ie": "protractor ./config/protractor.ie.conf.js",
...
},
...
}
With jasmine2 you can filter tests using a regular expression. Maybe you can add something like #chrome, #ie to your tests and then only run those ones by passing the grep flag:
it('should do stuff #ie #chrome', function() {
...
});
Then run protractor passing the grep flag:
protractor conf.js --grep='#ie'

Running intern with PhantomJS: window is undefined

I've followed all the steps described here: https://github.com/theintern/intern/wiki/Using-Intern-with-PhantomJS
My intern config is ~ as follows:
define({
proxyPort: 9000,
proxyUrl: 'http://localhost:9000/',
environments: [
{ browserName: 'phantom' }
],
maxConcurrency: 3,
useSauceConnect: false,
webdriver: {
host: 'localhost',
port: 4444
},
reporters: ['runner'],
useLoader: {
'host-node': 'dojo/dojo',
'host-browser': 'node_modules/dojo/dojo.js'
},
loader: {
packages: [
{ name: 'myApp', location: '...' }
],
baseUrl: '...',
paths: {...}
},
suites: [
'test/hello'
],
functionalSuites: [],
excludeInstrumentation: /(^test(\/|\\)|reporters|node_modules)/
});
I run phantomJS with
.\node_modules\.bin\phantomjs --webdriver 4444 --webdriver-loglevel='debug'
and it listens on 4444.
I even disabled Windows Firewall, but still I get
ReferenceError: window is not defined
at ***.js:348:142
at Function.vm.runInThisContext (***\node_modules\intern\node_modules\istanbul\lib\hook.js:163:16)
at ***\node_modules\intern\node_modules\dojo\dojo.js:757:8
at fs.js:266:14
at Object.oncomplete (fs.js:107:15)
as though Intern is running on node, not in Phatom. Phantom's console is also completely silent.
What am I missing? Or is there a way to debug Intern's actions? Thx
OK, I've finally figured this out.
I've been running intern using
.\node_modules\.bin\intern-client config=test/intern
while it should've been
.\node_modules\.bin\intern-runner config=test/intern
Thing is that intern-runner and intern-client are two different applications, one is for running with browsers via WebDriver, the other one for running with Node. It didn't catch my eye even though I was reading and re-reading the docs much more than once. Probably the distinction should be highlighted there.
Hope this helps someone )