-
Notifications
You must be signed in to change notification settings - Fork 4
ui tests #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
isabelrios
wants to merge
1
commit into
mozilla-sensorweb:master
Choose a base branch
from
isabelrios:add-ui-tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
ui tests #15
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -7,7 +7,12 @@ | |
"url": "[email protected]:mozilla-sensorweb/sensorweb-admin-panel.git" | ||
}, | ||
"devDependencies": { | ||
"react-scripts": "0.4.1" | ||
"react-scripts": "0.4.1", | ||
"chai": "^3.5.0", | ||
"chromedriver": "^2.27.2", | ||
"mocha": "^2.5.3", | ||
"selenium-webdriver": "^3.0.1", | ||
"wd": "^0.4.0" | ||
}, | ||
"dependencies": { | ||
"classnames": "^2.2.5", | ||
|
This file contains hidden or 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 @@ | ||
'use strict'; | ||
|
||
var LoginView = require('./views/login/view.js'); | ||
|
||
function MainPage(driver) { | ||
this.driver = driver; | ||
} | ||
|
||
MainPage.prototype = { | ||
getLogInPage : function() { | ||
return new LoginView(this.driver); | ||
}, | ||
|
||
stop() { | ||
return this.driver.quit(); | ||
}, | ||
}; | ||
|
||
module.exports = MainPage; |
This file contains hidden or 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,89 @@ | ||
'use strict'; | ||
|
||
var assert = require('assert'); | ||
var webdriver = require('selenium-webdriver'); | ||
var chrome = require('selenium-webdriver/chrome'); | ||
var path = require('chromedriver').path; | ||
|
||
const By = require('selenium-webdriver').By; | ||
const until = webdriver.until; | ||
|
||
var service = new chrome.ServiceBuilder(path).build(); | ||
chrome.setDefaultService(service); | ||
|
||
var HOST_URL = 'http://localhost:3000' | ||
|
||
describe( 'Show main page', function(done) { | ||
|
||
var mochaTimeOut = 30000; //ms | ||
var driver; | ||
|
||
var MainPage = require('./mainPage'); | ||
var mainPage; | ||
var loginView; | ||
var elements; | ||
|
||
|
||
before(function() { | ||
this.timeout(mochaTimeOut); | ||
driver = new webdriver.Builder() | ||
.withCapabilities(webdriver.Capabilities.chrome()) | ||
.build(); | ||
}); | ||
|
||
after(() => mainPage.stop()); | ||
|
||
beforeEach(function() { | ||
driver.get(HOST_URL) | ||
}); | ||
|
||
it('should be titled sensorweb', function () { | ||
this.timeout(mochaTimeOut); | ||
return driver.wait(webdriver.until.titleIs('SensorWeb'), 5000) | ||
.then(function(value) { | ||
return assert.equal(value, true); | ||
}); | ||
}); | ||
|
||
describe('Sign In', function() { | ||
|
||
beforeEach(function() { | ||
elements = { | ||
pwd: driver.findElement(webdriver.By.css('#app > div > div.jumbotron > div > div > form > div:nth-child(2) > input')), | ||
signIn: driver.findElement(webdriver.By.css('button.btn.btn-primary.btn-lg')) | ||
}; | ||
mainPage = new MainPage(driver); | ||
loginView = mainPage.getLogInPage(); | ||
return loginView; | ||
}); | ||
|
||
it('should have the rights fields', function() { | ||
var types = { | ||
pwd: 'password', | ||
signIn: 'submit' | ||
}; | ||
var promises = Object.keys(elements).map(function(key) { | ||
return elements[key].getAttribute('type') | ||
.then(function(value) { | ||
assert.equal(value, types[key]); | ||
}); | ||
}); | ||
return Promise.all(promises); | ||
}); | ||
|
||
it('should error if wrong password', function () { | ||
return loginView.incorrectLogin('a') | ||
.then((text) => { assert.equal(text, 'Unauthorized')}); | ||
}); | ||
|
||
it('should error if empty password', function () { | ||
return loginView.incorrectLogin('') | ||
.then((text) => { assert.equal(text, 'Unauthorized')}); | ||
}); | ||
|
||
it('should login if password is correct', function () { | ||
// The password should be the one used in server -> dev.json file | ||
return loginView.correctPassword('PasswordSet') | ||
}); | ||
}); | ||
}); |
This file contains hidden or 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,17 @@ | ||
'use strict'; | ||
|
||
const until = require('selenium-webdriver').until; | ||
|
||
|
||
function Accessors(driver) { | ||
this.driver = driver; | ||
} | ||
|
||
Accessors.prototype = { | ||
waitForElement(locator) { | ||
const element = this.driver.wait(until.elementLocated(locator)); | ||
return this.driver.wait(until.elementIsEnabled(element)); | ||
}, | ||
}; | ||
|
||
module.exports = Accessors; |
This file contains hidden or 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,27 @@ | ||
'use strict'; | ||
|
||
const By = require('selenium-webdriver').By; | ||
const Accessors = require('../accessors'); | ||
|
||
|
||
function LoginAccessors() { | ||
Accessors.apply(this, arguments); | ||
} | ||
|
||
LoginAccessors.prototype = Object.assign({ | ||
|
||
get passwordField() { | ||
return this.waitForElement(By.css('#app > div > div.jumbotron > div > div > form > div:nth-child(2) > input')); | ||
}, | ||
|
||
get singInButton() { | ||
return this.waitForElement(By.css('#app > div > div.jumbotron > div > div > form > div:nth-child(3) > button')); | ||
}, | ||
|
||
get unauthorizedError() { | ||
return this.waitForElement(By.css('#app > div > div.jumbotron > div > div > form > div.form-group.has-error > span')) | ||
} | ||
|
||
}, Accessors.prototype); | ||
|
||
module.exports = LoginAccessors; |
This file contains hidden or 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 @@ | ||
'use strict'; | ||
|
||
const View = require('../view'); | ||
const LoginAccessors = require('./accessors'); | ||
|
||
|
||
function LoginView() { | ||
[].push.call(arguments, LoginAccessors); | ||
View.apply(this, arguments); | ||
|
||
this.accessors.passwordField; | ||
this.accessors.singInButton; | ||
} | ||
|
||
LoginView.prototype = Object.assign({ | ||
|
||
correctPassword(password) { | ||
return this.accessors.passwordField.sendKeys(password) | ||
.then(() => { this.accessors.singInButton.click() | ||
.then(() => { | ||
const SignedInView = require('../signed_in/view'); | ||
return new SignedInView(this.driver); | ||
}); | ||
}); | ||
}, | ||
|
||
incorrectLogin(password) { | ||
return this.accessors.passwordField.sendKeys(password) | ||
.then(()=>{ | ||
return this.accessors.singInButton.click() | ||
}).then(() => { return this.accessors.unauthorizedError.getText()}) | ||
} | ||
|
||
}, View.prototype); | ||
|
||
module.exports = LoginView; |
This file contains hidden or 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,17 @@ | ||
'use strict'; | ||
|
||
const By = require('selenium-webdriver').By; | ||
const Accessors = require('../accessors'); | ||
|
||
|
||
function SignedInAccessors() { | ||
Accessors.apply(this, arguments); | ||
} | ||
|
||
SignedInAccessors.prototype = Object.assign({ | ||
|
||
//TBD | ||
|
||
}, Accessors.prototype); | ||
|
||
module.exports = SignedInAccessors; |
This file contains hidden or 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 @@ | ||
'use strict'; | ||
|
||
const View = require('../view'); | ||
const SignedInAccessors = require('./accessors'); | ||
|
||
|
||
function SignedInView() { | ||
[].push.call(arguments, SignedInAccessors); | ||
View.apply(this, arguments); | ||
} | ||
|
||
SignedInView.prototype = Object.assign({ | ||
|
||
// Functions for the SingedIn View TBD | ||
|
||
}, View.prototype); | ||
|
||
module.exports = SignedInView; |
This file contains hidden or 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,8 @@ | ||
'use strict'; | ||
|
||
function View(driver, Accessors) { | ||
this.driver = driver; | ||
this.accessors = new Accessors(driver); | ||
} | ||
|
||
module.exports = View; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how we can set a default password for the tests. If it depends on the one created in dev.json, could we have that file by default? Or could there be another way?