Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
fix(protractor): change angular-bootstrap wrapper for navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
hankduan committed Apr 24, 2014
1 parent 5d4072c commit b85af50
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 3 deletions.
39 changes: 36 additions & 3 deletions lib/protractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ Protractor.prototype.clearMockModules = function() {
* Remove a registered mock module.
* @param {!string} name The name of the module to remove.
*/
Protractor.prototype.removeMockModule = function (name) {
Protractor.prototype.removeMockModule = function(name) {
var index = this.moduleNames_.indexOf(name);
this.moduleNames_.splice(index, 1);
this.moduleScripts_.splice(index, 1);
Expand All @@ -848,7 +848,7 @@ Protractor.prototype.removeMockModule = function (name) {
*
* Navigate to the given destination and loads mock modules before
* Angular. Assumes that the page being loaded uses Angular.
* If you need to access a page which does have Angular on load, use
* If you need to access a page which does not have Angular on load, use
* the wrapped webdriver directly.
*
* @param {string} destination Destination URL.
Expand All @@ -867,7 +867,7 @@ Protractor.prototype.get = function(destination, opt_timeout) {
this.driver.get('about:blank');
this.driver.executeScript(
'window.name = "' + DEFER_LABEL + '" + window.name;' +
'window.location.assign("' + destination + '");');
'window.location.replace("' + destination + '");');

// At this point, we need to make sure the new url has loaded before
// we try to execute any asynchronous scripts.
Expand Down Expand Up @@ -909,6 +909,39 @@ Protractor.prototype.get = function(destination, opt_timeout) {
}, this.moduleNames_);
};

/**
* See webdriver.WebDriver.refresh
*
* Makes a full reload of the current page and loads mock modules before
* Angular. Assumes that the page being loaded uses Angular.
* If you need to access a page which does not have Angular on load, use
* the wrapped webdriver directly.
*
* @param {number=} opt_timeout Number of seconds to wait for Angular to start.
*/
Protractor.prototype.refresh = function(opt_timeout) {
var timeout = opt_timeout || 10;
var self = this;

if (self.ignoreSynchronization) {
return self.driver.navigate().refresh();
}

return self.driver.executeScript('return window.location.href').then(function(href) {
return self.get(href, opt_timeout);
});
};

/**
* Mixin navigation methods back into the navigation object so that
* they are invoked as before, i.e. driver.navigate().refresh()
*/
Protractor.prototype.navigate = function() {
var nav = this.driver.navigate();
mixin(nav, this, 'refresh');
return nav;
}

/**
* Browse to another page using in-page navigation.
*
Expand Down
45 changes: 45 additions & 0 deletions spec/basic/actions_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,49 @@ describe('using an ActionSequence', function() {

alertDialog.accept();
});

it('should refresh properly', function() {
var username = element(by.model('username'));
var name = element(by.binding('username'));
username.clear();
expect(name.getText()).toEqual('');

browser.navigate().refresh();

expect(name.getText()).toEqual('Anon');
});

// Back and forward do NOT work at the moment because of an issue
// bootstrapping with Angular
/*
it('should navigate back and forward properly', function() {
var port = process.env.HTTP_PORT || '8000';
browser.get('index.html#/repeater');
expect(browser.getCurrentUrl()).
toEqual('http://localhost:'+port+'/index.html#/repeater');
browser.navigate().back();
expect(browser.getCurrentUrl()).
toEqual('http://localhost:'+port+'/index.html#/form');
browser.navigate().forward();
expect(browser.getCurrentUrl()).
toEqual('http://localhost:'+port+'/index.html#/repeater');
});
*/

it('should navigate back and forward properly from link', function() {
var port = process.env.HTTP_PORT || '8000';
element(by.linkText('repeater')).click();
expect(browser.getCurrentUrl()).
toEqual('http://localhost:'+port+'/index.html#/repeater');

browser.navigate().back();
expect(browser.getCurrentUrl()).
toEqual('http://localhost:'+port+'/index.html#/form');

browser.navigate().forward();
expect(browser.getCurrentUrl()).
toEqual('http://localhost:'+port+'/index.html#/repeater');
});
});
46 changes: 46 additions & 0 deletions spec/basic/mockmodule_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,50 @@ describe('mock modules', function() {
expect(element(by.css('[app-version]')).getText()).toEqual('2');
});

it('should load mock modules after refresh', function() {
browser.addMockModule('moduleA', mockModuleA);

browser.get('index.html');
expect(element(by.css('[app-version]')).getText()).toEqual('2');

browser.navigate().refresh();
expect(element(by.css('[app-version]')).getText()).toEqual('2');
});

// Back and forward do NOT work at the moment because of an issue
// bootstrapping with Angular
/*
it('should load mock modules after navigating back and forward', function() {
browser.addMockModule('moduleA', mockModuleA);
browser.get('index.html');
expect(element(by.css('[app-version]')).getText()).toEqual('2');
browser.get('index.html#/repeater');
expect(element(by.css('[app-version]')).getText()).toEqual('2');
browser.navigate().back();
expect(element(by.css('[app-version]')).getText()).toEqual('2');
browser.navigate().forward();
expect(element(by.css('[app-version]')).getText()).toEqual('2');
});
*/

it('should load mock modules after navigating back and forward from link', function() {
browser.addMockModule('moduleA', mockModuleA);

browser.get('index.html');
expect(element(by.css('[app-version]')).getText()).toEqual('2');

element(by.linkText('repeater')).click();
expect(element(by.css('[app-version]')).getText()).toEqual('2');

browser.navigate().back();
expect(element(by.css('[app-version]')).getText()).toEqual('2');

browser.navigate().forward();
expect(element(by.css('[app-version]')).getText()).toEqual('2');
});

});

0 comments on commit b85af50

Please sign in to comment.