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(cli): add an onPrepare callback to the config
This onPrepare callback is useful when you want to do something with protractor before running the specs. For example, you might want to monkey-patch protractor with custom functions used by all the specs, or add the protractor instance to the globals. An example usage is shown in the spec/onPrepareConf.js file and its associated spec.
- Loading branch information
Showing
5 changed files
with
61 additions
and
2 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,18 @@ | ||
describe('tests that use the shortcuts set by the onPrepare in the config', | ||
function() { | ||
beforeEach(function() { | ||
// ptor is in the globals thanks to the onPrepare callback function in the | ||
// config. | ||
ptor.get('app/index.html#/form'); | ||
}); | ||
|
||
it('should find an element using elem instead of findElement', function() { | ||
var greeting = ptor.elem(protractor.By.binding('{{greeting}}')); | ||
expect(greeting.getText()).toEqual('Hiya'); | ||
}); | ||
|
||
it('should find an element using the global by function', function() { | ||
var greeting = ptor.elem(by.binding('{{greeting}}')); | ||
expect(greeting.getText()).toEqual('Hiya'); | ||
}); | ||
}); |
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,26 @@ | ||
// The main suite of Protractor 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: function() { | ||
var ptor = protractor.getInstance(); | ||
ptor.elem = ptor.findElement; | ||
ptor.elems = ptor.findElements; | ||
global.by = protractor.By; | ||
global.ptor = ptor; | ||
} | ||
}; |