I'm having a hard time getting JSTD to load a fixture HTML file.
My directory structure is:
localhost/JsTestDriver.conf
localhost/JsTestDriver.jar
localhost/js/App.js
localhost/js/App.test.js
localhost/fixtures/index.html
My conf file says:
server: http://localhost:4224
serve:
- fixtures/*.html
load:
- http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js
- jasmine/lib/jasmine-1.1.0/jasmine.js
- jasmine/jasmine-jquery-1.3.1.js
- jasmine/jasmine-jstd.js
- js/App.js
test:
- js/App.test.js
My test is:
describe("App", function(){
beforeEach(function(){
jasmine.getFixtures().fixturesPath = 'fixtures';
loadFixtures('index.html'); **//THIS LINE CAUSES IT TO FAIL**
});
describe("When App is loaded", function(){
it('should have a window object', function(){
expect(window).not.toBe(null);
});
});
});
And my console output is:
(link to full-size image)
I looked at this question but it didn't help me figure it out. The weird thing is, when I comment out the
loadFixtures('index.html');
line, the test passes.
Any ideas?
Okay -- figured it out. JsTestDriver prepends "test" to the path to your fixtures.
Also, jasmine-jquery gets fixtures using ajax.
Thus, these steps finally worked for me:
In jsTestDriver.conf:
serve:
- trunk/wwwroot/fixtures/*.html
load:
- trunk/wwwroot/js/libs/jquery-1.7.1.min.js
- jstd/jasmine/standalone-1.2.0/lib/jasmine-1.2.0/jasmine.js
- jstd/jasmine-jstd-adapter/src/JasmineAdapter.js
- jstd/jasmine-jquery/lib/jasmine-jquery.js
- trunk/wwwroot/js/main.js
test:
- trunk/wwwroot/js/main.test.js
In my test file:
describe("main", function(){
beforeEach(function(){
jasmine.getFixtures().fixturesPath = '/test/trunk/wwwroot/fixtures';
jasmine.getFixtures().load('main.html');
});
describe("when main.js is loaded", function(){
it('should have a div', function(){
expect($('div').length).toBe(1);
});
});
});
Note that the beforeEach() call uses an absolute URL to the HTML fixture.
Try changing the fixture path to:
jasmine.getFixtures().fixturesPath = '/fixtures';
I get different, but similarly weird errors otherwise.
Related
I am running into this issue where I execute my protractor test only to find out that it has failed. Now the issue is not with the actual functionality failing but with the Default Timeout Interval apparently. The Code runs fine, performs all the operation on the Webpage and just when you expect a green dot it errors out.
Before anyone marks it duplicate, I would just like to tell that I have tried the below approaches going through the answers of other similar question.
Included argument in the "it" block and called the argument after the test.
Changed the default_timeout_interval in conf.js file to 30s.
Tried using Async/await in the last function to wait for the promise to get resolved.
I would not only like to find a answer to this one but also if someone can give me an explanation on what exactly Protractor wants to convey here. To me as a novice in JavaScript and Protractor this looks like a very vague message.
Below is my spec file :
describe("Validating Booking for JetBlue WebApplication", function(){
var firstPage = require("../PageLogic/jetBlueHomePage.js");
it("Validating One Way Booking", function(pleaserun){
firstPage.OneWayTrip();
firstPage.EnterFromCity("California");
firstPage.EnterToCity("New York");
firstPage.SelectDepartureDate();
firstPage.searchFlights();
pleaserun();
});
});
Below is my Page file:
var homePage = function(){
this.OneWayTrip = function(){
element(by.xpath("//label[text()=' One-way ']/parent::jb-radio/div")).click();
}
this.EnterFromCity = function(FromCityName){
element(by.xpath("//input[#placeholder='Where from?']")).clear();
element(by.xpath("//input[#placeholder='Where from?']")).sendKeys(FromCityName);
browser.sleep(3000);
element(by.xpath("//ul[#id='listbox']/li[1]")).click();
}
this.EnterToCity = function(ToCityName){
element(by.xpath("//input[#placeholder='Where to?']")).clear();
element(by.xpath("//input[#placeholder='Where to?']")).sendKeys(ToCityName);
browser.sleep(3000);
element(by.xpath("//ul[#id='listbox']/li[1]")).click();
browser.sleep(3000);
}
this.SelectDepartureDate = function(){
element(by.xpath("//input[#placeholder='Select Date']")).click();
browser.sleep(3000);
element(by.xpath("//span[text()=' 24 ']")).click();
}
this.NumberOfPassengers = function(){
element(by.xpath("//button[#pax='traveler-selector']")).click();
}
this.searchFlights = async function(){
await element(by.buttonText('Search flights')).click();
}
};
module.exports = new homePage();
Below is the Conf.js file :
exports.config = {
directConnect: true,
specs:["TestSpecs/jetBlueBookingTest.js"],
onPrepare: function(){
browser.get("https://www.jetblue.com/");
browser.manage().window().maximize();
},
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
isVerbose: true,
includeStackTrace: true,
}
};
Seeking help from all the protractor pros out there to help me get this solution and hopefully make me understand the concept.
the message means that an async script was run in the browser, and it hasn't returned a result within the expected time limit. it would be useful if you could share the full error stack, the root cause is probably mentioned deeper down in it
I have some Protractor tests using Axe (AxeBuilder) like the following:
var AxeBuilder = require('path_to_the/axe-webdriverjs');
describe('Page under test', function() {
'use strict';
it('should be accessible', function() {
AxeBuilder(browser.driver).analyze(function(results) {
expect(results.violations.length).toBe(0);
});
});
});
How would I go about passing results.violations out to Jasmine so that it can be reported in my Jasmine Reporter?
I am currently looking to use the following Jasmine JSON Reporter:
https://github.com/DrewML/jasmine-json-test-reporter
But I will eventually customise this to output HTML.
I found a fix for this in the end.
It turns out that the solution is to write a custom Jasmine matcher, like this: http://jasmine.github.io/2.4/custom_matcher.html
This allows you to control what information is passed out to the result.message.
I am running this test and it seems that when the test get's to the function portion of my describe block, it skips the whole thing and gives a false positive for passing.
// required libraries
var webdriverio = require('webdriverio');
var describe = require('describe');
var after = require('after');
console.log("Lets begin");
describe('Title Test for google site', function() {
console.log("MARTY!!");
// set timeout to 10 seconds
this.timeout(10000);
var driver = {};
console.log("before we start");
// hook to run before tests
before( function (done) {
// load the driver for browser
console.log("before browser");
driver = webdriverio.remote({ desiredCapabilities: {browserName: 'firefox'} });
driver.init(done);
});
it('should load correct page and title', function () {
// load page, then call function()
return driver
.console.log("before site")
.url('http://www.ggogle.com')
// get title, then pass title to function()
.getTitle().then( function (title) {
// verify title
(title).should.be.equal("google");
// uncomment for console debug
// console.log('Current Page Title: ' + title);
});
});
});
// a "hook" to run after all tests in this block
after(function(done) {
driver.end(done);
});
console.log ("Fin");
This is the output I get
Lets begin
Fin
[Finished in 0.4s]
As you can see it skips everything else.
This is wrong and should be removed:
var describe = require('describe');
var after = require('after');
Mocha's describe and after are added to the global space of your test files by Mocha. You do not need to import them. Look at all the examples on the Mocha site, you won't find anywhere where they tell you to import describe and its siblings.
To get Mocha to add describe and its siblings, you need to be running your test through mocha. Running node directly on a test file won't work. And for mocha to be findable it has to be in your PATH. If you installed it locally, it is (most likely) not in your PATH so you have to give the full path ./node_modules/.bin/mocha.
I built a yeoman generator that grabs data from a rest api and populates html, css, and js files in an app dir with those files. I am trying to learn how to build the respective mocha test but keep running into an error on my file exist test.
I pass the "does the generator load" test, but when i try the "do files exist" test, I get an error at the console that:
1)creates files creates expected files:
Uncaught TypeError: cb is not a function
at null.<anonymous> (node_modules/yeoman-generator/lib/base.js:400:5)
at Queue.<anonymous> (node_modules/grouped-queue/lib/queue.js:68:12)
My test is as follows
/*global describe, beforeEach, it*/
'use strict';
var path = require('path');
var helpers = require('yeoman-generator').test;
describe("creates files", function(){
beforeEach(function (done){
helpers.testDirectory(path.join(__dirname, 'temp'), function(err){
if(err){
return done(err);
}
this.app = helpers.createGenerator('snow:app',['../../app']);
done();
}.bind(this));
});
it("creates expected files", function(done){
helpers.mockPrompt(this.app,{
hostname : "empasiegel1",
username : "password",
password : "password",
solution : "testSnow"
});
this.app.run({}, function() {
helpers.assertFile('package.json');
done();
});
});
});
Could it have soemthing to do with the asynchronous nature of the rest calls?
I want to build a test that makes sure the Jasmine Test is using a file called SpecRunner.html".
How do I do that?
You can check window.location (at least if you are running tests in browser).
Quick POC code:
describe("File name", function () {
it("ends with SpecRunner.html", function () {
var fileName = window.location.pathname.split("/").pop();
expect(window.location.pathname).toMatch(/SpecRunner.html$/);
});
});