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

Commit b85af50

Browse files
committed
fix(protractor): change angular-bootstrap wrapper for navigation
1 parent 5d4072c commit b85af50

File tree

3 files changed

+127
-3
lines changed

3 files changed

+127
-3
lines changed

lib/protractor.js

+36-3
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ Protractor.prototype.clearMockModules = function() {
837837
* Remove a registered mock module.
838838
* @param {!string} name The name of the module to remove.
839839
*/
840-
Protractor.prototype.removeMockModule = function (name) {
840+
Protractor.prototype.removeMockModule = function(name) {
841841
var index = this.moduleNames_.indexOf(name);
842842
this.moduleNames_.splice(index, 1);
843843
this.moduleScripts_.splice(index, 1);
@@ -848,7 +848,7 @@ Protractor.prototype.removeMockModule = function (name) {
848848
*
849849
* Navigate to the given destination and loads mock modules before
850850
* Angular. Assumes that the page being loaded uses Angular.
851-
* If you need to access a page which does have Angular on load, use
851+
* If you need to access a page which does not have Angular on load, use
852852
* the wrapped webdriver directly.
853853
*
854854
* @param {string} destination Destination URL.
@@ -867,7 +867,7 @@ Protractor.prototype.get = function(destination, opt_timeout) {
867867
this.driver.get('about:blank');
868868
this.driver.executeScript(
869869
'window.name = "' + DEFER_LABEL + '" + window.name;' +
870-
'window.location.assign("' + destination + '");');
870+
'window.location.replace("' + destination + '");');
871871

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

912+
/**
913+
* See webdriver.WebDriver.refresh
914+
*
915+
* Makes a full reload of the current page and loads mock modules before
916+
* Angular. Assumes that the page being loaded uses Angular.
917+
* If you need to access a page which does not have Angular on load, use
918+
* the wrapped webdriver directly.
919+
*
920+
* @param {number=} opt_timeout Number of seconds to wait for Angular to start.
921+
*/
922+
Protractor.prototype.refresh = function(opt_timeout) {
923+
var timeout = opt_timeout || 10;
924+
var self = this;
925+
926+
if (self.ignoreSynchronization) {
927+
return self.driver.navigate().refresh();
928+
}
929+
930+
return self.driver.executeScript('return window.location.href').then(function(href) {
931+
return self.get(href, opt_timeout);
932+
});
933+
};
934+
935+
/**
936+
* Mixin navigation methods back into the navigation object so that
937+
* they are invoked as before, i.e. driver.navigate().refresh()
938+
*/
939+
Protractor.prototype.navigate = function() {
940+
var nav = this.driver.navigate();
941+
mixin(nav, this, 'refresh');
942+
return nav;
943+
}
944+
912945
/**
913946
* Browse to another page using in-page navigation.
914947
*

spec/basic/actions_spec.js

+45
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,49 @@ describe('using an ActionSequence', function() {
2424

2525
alertDialog.accept();
2626
});
27+
28+
it('should refresh properly', function() {
29+
var username = element(by.model('username'));
30+
var name = element(by.binding('username'));
31+
username.clear();
32+
expect(name.getText()).toEqual('');
33+
34+
browser.navigate().refresh();
35+
36+
expect(name.getText()).toEqual('Anon');
37+
});
38+
39+
// Back and forward do NOT work at the moment because of an issue
40+
// bootstrapping with Angular
41+
/*
42+
it('should navigate back and forward properly', function() {
43+
var port = process.env.HTTP_PORT || '8000';
44+
browser.get('index.html#/repeater');
45+
expect(browser.getCurrentUrl()).
46+
toEqual('http://localhost:'+port+'/index.html#/repeater');
47+
48+
browser.navigate().back();
49+
expect(browser.getCurrentUrl()).
50+
toEqual('http://localhost:'+port+'/index.html#/form');
51+
52+
browser.navigate().forward();
53+
expect(browser.getCurrentUrl()).
54+
toEqual('http://localhost:'+port+'/index.html#/repeater');
55+
});
56+
*/
57+
58+
it('should navigate back and forward properly from link', function() {
59+
var port = process.env.HTTP_PORT || '8000';
60+
element(by.linkText('repeater')).click();
61+
expect(browser.getCurrentUrl()).
62+
toEqual('http://localhost:'+port+'/index.html#/repeater');
63+
64+
browser.navigate().back();
65+
expect(browser.getCurrentUrl()).
66+
toEqual('http://localhost:'+port+'/index.html#/form');
67+
68+
browser.navigate().forward();
69+
expect(browser.getCurrentUrl()).
70+
toEqual('http://localhost:'+port+'/index.html#/repeater');
71+
});
2772
});

spec/basic/mockmodule_spec.js

+46
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,50 @@ describe('mock modules', function() {
4848
expect(element(by.css('[app-version]')).getText()).toEqual('2');
4949
});
5050

51+
it('should load mock modules after refresh', function() {
52+
browser.addMockModule('moduleA', mockModuleA);
53+
54+
browser.get('index.html');
55+
expect(element(by.css('[app-version]')).getText()).toEqual('2');
56+
57+
browser.navigate().refresh();
58+
expect(element(by.css('[app-version]')).getText()).toEqual('2');
59+
});
60+
61+
// Back and forward do NOT work at the moment because of an issue
62+
// bootstrapping with Angular
63+
/*
64+
it('should load mock modules after navigating back and forward', function() {
65+
browser.addMockModule('moduleA', mockModuleA);
66+
67+
browser.get('index.html');
68+
expect(element(by.css('[app-version]')).getText()).toEqual('2');
69+
70+
browser.get('index.html#/repeater');
71+
expect(element(by.css('[app-version]')).getText()).toEqual('2');
72+
73+
browser.navigate().back();
74+
expect(element(by.css('[app-version]')).getText()).toEqual('2');
75+
76+
browser.navigate().forward();
77+
expect(element(by.css('[app-version]')).getText()).toEqual('2');
78+
});
79+
*/
80+
81+
it('should load mock modules after navigating back and forward from link', function() {
82+
browser.addMockModule('moduleA', mockModuleA);
83+
84+
browser.get('index.html');
85+
expect(element(by.css('[app-version]')).getText()).toEqual('2');
86+
87+
element(by.linkText('repeater')).click();
88+
expect(element(by.css('[app-version]')).getText()).toEqual('2');
89+
90+
browser.navigate().back();
91+
expect(element(by.css('[app-version]')).getText()).toEqual('2');
92+
93+
browser.navigate().forward();
94+
expect(element(by.css('[app-version]')).getText()).toEqual('2');
95+
});
96+
5197
});

0 commit comments

Comments
 (0)