I'm trying to test protractor on a vanilla.js app and when I run protractor basicConf.js
I am getting below error :
This webpage is not available ERR_CONNECTION_REFUSED
This is my test:
describe('foo', function() {
beforeEach(function() {
browser.get('index.html');
});
it('should return the same result as browser.findElement', function() {
$('#newItem').sendKeys('sdg');
element('#addBtn').click().then(function(){
});
});
})
And my protractor config:
// The main suite of Protractor tests.
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
framework: 'jasmine2',
// Spec patterns are relative to this directory.
specs: [
'spec.js'
],
// Exclude patterns are relative to this directory.
exclude: [
'basic/exclude*.js'
],
capabilities: {'browserName': 'chrome'},
baseUrl: 'http://localhost:' + ( '8082'),
jasmineNodeOpts: {
isVerbose: true,
realtimeFailure: true
},
params: {
login: {
user: 'Jane',
password: '1234'
}
}
};
Any ideas what I need to do to start fixing this?
I have run both:
protactor npm install -g protractor
webdriver webdriver-manager update
Error connection gets refused if either the webdriver server isn't started or there is a configuration compatibility issue with your protractor and browser. Looking at your config file and config data, there is no such issue. However, you should start your webdriver before running your tests. Open a command prompt in windows or terminal in mac and then run the following command to start the selenium webdriver -
webdriver-manager start
Later run your protractor scripts with the command that you already have. Hope this helps.
Looking over your test I believe the issue originates from the address that you are passing to the browser.get() function. You'll want to either reference the baseUrl you setup in the config file and append the "index.html" piece in your test or adjust the baseUrl and reference that in your beforeEach function. Try one of the following:
...
baseUrl: 'http://localhost:8082',
...
browser.get(browser.baseUrl + '/index.html');
or
...
baseUrl: 'http://localhost:8082/',
...
browser.get(browser.baseUrl);
or
browser.get('http://localhost:8082/index.html');
Also you could try this:
...
baseUrl: 'http://localhost:8082/index.html');
...
browser.get(browser.baseUrl);
Related
My goal is to be able to publish a Web Worker NPM package which can be imported normally (import MyPkg from 'my-pkg') without requiring the user to import it with worker-loader (inline or otherwise)
To accomplish this, I've tried using a Babel build script as well as Webpack with worker-loader.
In the following examples there are two projects: the Web Worker package ("Package") which is npm linked to a test application ("App").
The Package is split into two files: entry.webpack.js and index.worker.js. The entry, when built and moved to /dist is designated as the main file in the package.json, and it currently looks like this:
entry.webpack.js
var MyPkg = require('worker-loader!./index.worker.js')
module.exports = MyPkg
index.worker.js
// This is just example code. It doesn't really matter
// what this code does so long as it ends up being run
// as a Web Worker.
var selfRef = self;
function ExampleWorker () {
console.log('Running Worker...');
setTimeout(function () {
// wait 10 seconds then post a message
selfRef.postMessage({foo: "bar"});
}, 10000)
}
module.exports = ExampleWorker
I then bundle the Package with Webpack:
package.json
"build": "rm -rf dist/*.* && webpack --progress"
webpack.config.js
module.exports = {
mode: 'production',
devtool: 'source-map',
entry: __dirname + '/src/entry.webpack.js',
output: {
filename: 'bundle.js',
path: __dirname + '/dist'
},
optimization: {
minimize: false
}
}
This generates two files: bundle.js and a Web Worker file as a hash: [hash].worker.js with the code we want evaluated in it. They key part in this, though, is that because we used worker-loader inline to import, the webpack compiled output looks something like:
module.exports = function() {
return new Worker(__webpack_require__.p + "53dc9610ebc22e0dddef.worker.js");
};
Finally, the App should be able to import it and use it like this:
App.js
import MyPkg from 'my-pkg'
// logging MyPkg here produces `{}`
const worker = new MyPkg()
// That throws an Error:
// Uncaught TypeError: _my_pkg__WEBPACK_IMPORTED_MODULE_4___default.a is not a constructor
worker.onmessage = event => {
// this is where we'd receive our message from the web worker
}
However, you can get it to work if, in the App itself you import the worker build like this:
import MyPkg from 'my-pkg/dist/53dc9610ebc22e0dddef.worker.js'
But, it's a requirement of the package to:
A) NOT require applications using the package to have to explicitly install worker-loader and
B) not have to reference the my-pkg/dist/[hash].worker.js explicitly.
I've tried also designating the built [hash].worker.js' as themain` in package.json but that doesn't work either.
Edit 1: I forgot to mention that I'm basing all of this off of how react-pdf does it. If you take a look in /src/entry.webpack.js and follow how it works throughout the package you'll see a few similarities.
you could try worker-loader with option:
{
test: /\.worker\.js$/,
use: {
loader: 'worker-loader',
options: {
name: '[name].[hash:8].js',
// notice here
inline: true,
fallback: false
}
}
},
I have a Windows box and an Ubuntu box which I run my automated tests on. Currently, in my protractor.config.js file I have two seleniumAddress fields under my multiCapabilities: [{}] section and just comment out one or the other depending on which environment I would like to run in.
Is there a way to parameterize the seleniumAddress: so I can tell from my command line which environment to run in?
Something like this: gulp e2e --suite <suiteName> --baseUrl <URL>
--environment Windows
Here is my current multiCapabilities section from my protractor conf file:
multiCapabilities: [{
browserName: 'chrome',
// seleniumAddress: "URL to webdriver-manager Windows Box",
seleniumAddress: "URL to webdriver-manager Ubuntu Box",
platform: 'ANY',
version: 'ANY',
chromeOptions: {
args: ['--no-sandbox', '--test-type=browser', '--lang=en', '--window-size=1680,1050'],
prefs: {
'credentials_enable_service': false,
'profile': {
'password_manager_enabled': false
},
download: {
prompt_for_download: false,
directory_upgrade: true,
default_directory: 'C:\\downloads\\'
},
},
}
// shardTestFiles: true,
// maxInstances: 2
}],
Protractor is run on Node.js, so you should be able to pass an argument (a little more complicated), or easier, set an environmental variable:
Protractor conf snippet from the Protractor website with environmental variable logic added:
// Use the Windows selenium if the environmental variable IS_WINDOWS is set.
const seleniumServer = process.env.IS_WINDOWS ?
'https://path/to/windows-silenium' : 'https://path-to-default-selenium';
exports.config = {
// The address of a running selenium server.
seleniumAddress: seleniumServer,
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'chrome'
},
// Spec patterns are relative to the configuration file location passed
// to protractor (in this example conf.js).
// They may include glob patterns.
specs: ['example-spec.js'],
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true, // Use colors in the command line report.
}
};
I'm not quite sure what you would want to choose from (and I don't use gulp), but for the snippet above, you would probably use:
IS_WINDOWS=true gulp e2e --suite <suiteName> --baseUrl <URL>
I am trying to write a code for tasting that I'm redirected to the index.html file using protractor .When I type in terminal protractor protractor.conf.js to execute the e2e tests. it shows me this error :
W/protractor - browser.getLocationAbsUrl() is deprecated, please use browser.getCurrentUrl instead.
Why is that happening?Isn't getLocationAbsUrl Protractor's words?
the code for Configuring Protractor
exports.config = {
allScriptsTimeout: 11000,
specs: [
'e2e/*.js'
],
capabilities: {
'browserName': 'chrome'
},
baseUrl: 'http://localhost:3000/',
framework: 'jasmine',
directConnect: true,
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
}
};
Code for e2e test
'use strict';
describe('conFusion App E2E Testing', function() {
it('should automatically redirect to / when location hash/fragment is empty', function() {
browser.get('index.html');
expect(browser.getLocationAbsUrl()).toMatch("/");
});
As your error said, this function is deprecated. It means the use of this code is now discouraged. You should use getCurrentUrl().
From Protractor's Github:
browser.getLocationAbsUrl() is now deprecated, you should use
browser.getCurrentUrl() instead.
I believe there is a problem with using angular-mocks and foundation-apps when trying to run a karma jasmine unit test. It could also be that I have missed something. Since there is so much code to see I have posted an example project on github for review.
Basically the site runs fine and karma runs the test but when you debug into the angular.mocks.module function you find that your module from your app is not being loaded.
If you take foundation-apps out of the situation it will work fine.
Could this be a version conflict because foundation-apps has an older dependency for angular-mocks?
fatest on github
I hit the same issue and my solution was to add resulting css-file (app.css - generated with sass task) to karma configuration. Without this file i got:
TypeError: 'null' is not an object (evaluating 'mediaQueries[key].replace')
Here is my gulp config:
var karma = require('karma').server;
//...........//
// Compiles Sass
gulp.task('sass', function () {
return gulp.src('client/assets/scss/app.scss')
.pipe(plugins.sass({
includePaths: paths.sass,
outputStyle: (isProduction ? 'compressed' : 'nested'),
errLogToConsole: true
}))
.pipe(plugins.autoprefixer({browsers: ['last 2 versions', 'ie 10']}))
.pipe(gulp.dest('./build/assets/css/'))
.pipe(plugins.livereload());
});
/// ..... some other things here ......///
gulp.task('unit-test', function (done) {
var testFiles = [
{pattern:'./build/assets/js/foundation.js',watched:false},
{pattern:'./build/assets/js/routes.js',watched:false},
{pattern:'./build/assets/css/app.css',watched:false},
{pattern:'./build/assets/js/templates.js',watched:false},
{pattern:'./bower_components/angular-mocks/angular-mocks.js', watched:false},
{pattern:'./client/assets/js/*.js'},
{pattern:'./client/templates/**/*.js'}
];
karma.start({
configFile:__dirname + '/karma.conf.js',
singleRun: true,
files: testFiles
}, done);
});
Assuming your application is already builded, just run gulp unit-test.
First of all I'm a noob with e2e testing. What I've done is
installed protractor nmp install protractor
installed webdriver-manager
run webdriver-manager start from the directory where my angularjs app sits. it runs fine
run protractor tests/e2e/conf.js it also runs fine
However in few seconds it says Timed out waiting for page to load
Here are my files:
tests/e2e/conf.js:
// An example configuration file.
exports.config = {
// The address of a running selenium server.
seleniumAddress: 'http://localhost:4444/wd/hub',
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'chrome'
},
// Spec patterns are relative to the current working directly when
// protractor is called.
specs: ['example_spec.js'],
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000
}
};
tests/e2e/example_spec.js
var protr;
describe('addressBook homepage', function() {
var ptor;
beforeEach(function() {
ptor = protractor.getInstance();
});
it('should greet the named user', function() {
browser.get('/'); // <-- exception here
element(by.model('yourName')).sendKeys('Julie');
var greeting = element(by.binding('yourName'));
expect(greeting.getText()).toEqual('Hello Julie!');
});
});
I just can't understand where to define my webapp laypout/placement so protractor/webdriver knows which context to run.
With that setup protractor will be trying to navigate to "/". You need to either set the baseUrl property in the configuration file, or put an absolute url in the browser.get(). If all your tests are going to be on the same domain I'd recommend the first option.