This repository has been archived by the owner on Jul 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config): add exmples for dealing with log-in
Adds examples for how to log in when the login page is not written in Angular. New examples are in spec/login.
- Loading branch information
Showing
10 changed files
with
194 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// This is the configuration file showing how a suite of tests might | ||
// handle log-in using the onPrepare field. | ||
exports.config = { | ||
seleniumServerJar: './selenium/selenium-server-standalone-2.35.0.jar', | ||
chromeDriver: './selenium/chromedriver', | ||
|
||
seleniumAddress: 'http://localhost:4444/wd/hub', | ||
|
||
specs: [ | ||
'viaConfigSpec.js' | ||
], | ||
|
||
capabilities: { | ||
'browserName': 'chrome' | ||
}, | ||
|
||
onPrepare: function() { | ||
var ptor = protractor.getInstance(); | ||
ptor.driver.get('http://localhost:8000/app/login.html'); | ||
|
||
ptor.driver.findElement(protractor.By.id('username')).sendKeys('Jane'); | ||
ptor.driver.findElement(protractor.By.id('password')).sendKeys('1234'); | ||
ptor.driver.findElement(protractor.By.id('clickme')).click(); | ||
|
||
// Login takes some time, so wait until it's done. | ||
// For the test app's login, we know it's done when it redirects to | ||
// index.html. | ||
ptor.wait(function() { | ||
return ptor.driver.getCurrentUrl().then(function(url) { | ||
return /index/.test(url); | ||
}); | ||
}); | ||
}, | ||
|
||
baseUrl: 'http://localhost:8000', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
describe('pages with login', function() { | ||
var ptor; | ||
|
||
beforeEach(function() { | ||
ptor = protractor.getInstance(); | ||
}) | ||
|
||
it('should log in with a non-Angular page', function() { | ||
ptor.get('http://localhost:8000/app/index.html'); | ||
|
||
var angularElement = ptor.findElement(protractor.By.input('url')); | ||
expect(angularElement.getAttribute('value')).toEqual('/fastcall'); | ||
|
||
// Make sure the cookie is still set. | ||
ptor.manage().getCookie('testcookie').then(function(cookie) { | ||
expect(cookie.value).toEqual('Jane-1234'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// This is the configuration file showing how a suite of tests might | ||
// handle log-in using the onPrepare field. | ||
exports.config = { | ||
seleniumServerJar: './selenium/selenium-server-standalone-2.35.0.jar', | ||
chromeDriver: './selenium/chromedriver', | ||
|
||
seleniumAddress: 'http://localhost:4444/wd/hub', | ||
|
||
specs: [ | ||
'viaTestSpec.js' | ||
], | ||
|
||
capabilities: { | ||
'browserName': 'chrome' | ||
}, | ||
|
||
baseUrl: 'http://localhost:8000', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
describe('pages with login', function() { | ||
var ptor; | ||
|
||
beforeEach(function() { | ||
ptor = protractor.getInstance(); | ||
}) | ||
|
||
it('should log in with a non-Angular page', function() { | ||
ptor.driver.get('http://localhost:8000/app/login.html'); | ||
|
||
ptor.driver.findElement(protractor.By.id('username')).sendKeys('Jane'); | ||
ptor.driver.findElement(protractor.By.id('password')).sendKeys('1234'); | ||
ptor.driver.findElement(protractor.By.id('clickme')).click(); | ||
|
||
// Login takes some time, so wait until it's done. | ||
// For the test app's login, we know it's done when it redirects to | ||
// index.html. | ||
ptor.wait(function() { | ||
return ptor.driver.getCurrentUrl().then(function(url) { | ||
return /index/.test(url); | ||
}); | ||
}); | ||
|
||
// The login should have set a cookie. Make sure it's there. | ||
ptor.manage().getCookie('testcookie').then(function(cookie) { | ||
expect(cookie.value).toEqual('Jane-1234'); | ||
}); | ||
|
||
|
||
ptor.get('http://localhost:8000/app/index.html'); | ||
|
||
var angularElement = ptor.findElement(protractor.By.input('url')); | ||
expect(angularElement.getAttribute('value')).toEqual('/fastcall'); | ||
|
||
// Make sure the cookie is still set. | ||
ptor.manage().getCookie('testcookie').then(function(cookie) { | ||
expect(cookie.value).toEqual('Jane-1234'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
var ptor = protractor.getInstance(); | ||
ptor.elem = ptor.findElement; | ||
ptor.elems = ptor.findElements; | ||
global.by = protractor.By; | ||
global.ptor = ptor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Configuration using a string in onPrepare to load a file with code to | ||
// execute once before tests. | ||
exports.config = { | ||
seleniumServerJar: './selenium/selenium-server-standalone-2.35.0.jar', | ||
chromeDriver: './selenium/chromedriver', | ||
|
||
seleniumAddress: 'http://localhost:4444/wd/hub', | ||
|
||
// Spec patterns are relative to this directory. | ||
specs: [ | ||
'onPrepare/*_spec.js' | ||
], | ||
|
||
capabilities: { | ||
'browserName': 'chrome' | ||
}, | ||
|
||
baseUrl: 'http://localhost:8000', | ||
|
||
onPrepare: 'onPrepare/startup.js' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<html> | ||
<head> | ||
<title>Test Application Login</title> | ||
<script> | ||
function login() { | ||
// Make sure everything works when the login is slow. | ||
window.setTimeout(function() { | ||
// Set a simple cookie. | ||
var username = document.getElementById('username').value; | ||
var password = document.getElementById('password').value; | ||
|
||
document.cookie = 'testcookie=' + username + '-' + password; | ||
|
||
window.location.assign('index.html'); | ||
}, 2000); | ||
}; | ||
</script> | ||
</head> | ||
<body> | ||
<div>Login</div> | ||
<div><label>Username</label><input id="username" type="text"/></div> | ||
<div><label>Password</label><input id="password" type="text"/></div> | ||
<div><button id="clickme" onClick="login()">Go</button></div> | ||
</body> | ||
</html> |