This repository was archived by the owner on Jul 29, 2024. It is now read-only.
File tree 5 files changed +61
-2
lines changed
5 files changed +61
-2
lines changed Original file line number Diff line number Diff line change @@ -154,13 +154,19 @@ var startJasmineTests = function() {
154
154
// Export protractor to the global namespace to be used in tests.
155
155
global . protractor = protractor ;
156
156
157
- // Set up the Jasmine WebDriver Adapter
157
+ // Set up the Jasmine WebDriver Adapter.
158
158
require ( '../jasminewd' ) ;
159
159
160
160
var options = config . jasmineNodeOpts ;
161
161
originalOnComplete = options . onComplete ;
162
162
options . onComplete = cleanUp ;
163
163
164
+ // Let the configuration configure the protractor instance before running
165
+ // the tests.
166
+ if ( config . onPrepare ) {
167
+ config . onPrepare ( ) ;
168
+ }
169
+
164
170
minijn . executeSpecs ( options ) ;
165
171
} ) ;
166
172
}
Original file line number Diff line number Diff line change 31
31
"bin" : " bin/protractor" ,
32
32
"main" : " lib/protractor.js" ,
33
33
"scripts" : {
34
- "test" : " node lib/cli.js spec/basicConf.js; node lib/cli.js spec/altRootConf.js; node_modules/.bin/minijasminenode jasminewd/spec/adapterSpec.js"
34
+ "test" : " node lib/cli.js spec/basicConf.js; node lib/cli.js spec/altRootConf.js; node lib/cli.js spec/onPrepareConf.js; node_modules/.bin/minijasminenode jasminewd/spec/adapterSpec.js"
35
35
},
36
36
"version" : " 0.9.0"
37
37
}
Original file line number Diff line number Diff line change @@ -60,6 +60,15 @@ exports.config = {
60
60
// body, but is necessary if ng-app is on a descendant of <body>
61
61
rootElement : 'body' ,
62
62
63
+ // A callback function called once protractor is ready and available, and
64
+ // before the specs are executed
65
+ onPrepare : function ( ) {
66
+ // At this point, global 'protractor' object will be set up, and jasmine
67
+ // will be available. For example, you can add a Jasmine reporter with:
68
+ // jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter(
69
+ // 'outputdir/', true, true));
70
+ } ,
71
+
63
72
// ----- Options to be passed to minijasminenode -----
64
73
jasmineNodeOpts : {
65
74
// onComplete will be called just before the driver quits.
Original file line number Diff line number Diff line change
1
+ describe ( 'tests that use the shortcuts set by the onPrepare in the config' ,
2
+ function ( ) {
3
+ beforeEach ( function ( ) {
4
+ // ptor is in the globals thanks to the onPrepare callback function in the
5
+ // config.
6
+ ptor . get ( 'app/index.html#/form' ) ;
7
+ } ) ;
8
+
9
+ it ( 'should find an element using elem instead of findElement' , function ( ) {
10
+ var greeting = ptor . elem ( protractor . By . binding ( '{{greeting}}' ) ) ;
11
+ expect ( greeting . getText ( ) ) . toEqual ( 'Hiya' ) ;
12
+ } ) ;
13
+
14
+ it ( 'should find an element using the global by function' , function ( ) {
15
+ var greeting = ptor . elem ( by . binding ( '{{greeting}}' ) ) ;
16
+ expect ( greeting . getText ( ) ) . toEqual ( 'Hiya' ) ;
17
+ } ) ;
18
+ } ) ;
Original file line number Diff line number Diff line change
1
+ // The main suite of Protractor tests.
2
+ exports . config = {
3
+ seleniumServerJar : './selenium/selenium-server-standalone-2.35.0.jar' ,
4
+ chromeDriver : './selenium/chromedriver' ,
5
+
6
+ seleniumAddress : 'http://localhost:4444/wd/hub' ,
7
+
8
+ // Spec patterns are relative to this directory.
9
+ specs : [
10
+ 'onPrepare/*_spec.js'
11
+ ] ,
12
+
13
+ capabilities : {
14
+ 'browserName' : 'chrome'
15
+ } ,
16
+
17
+ baseUrl : 'http://localhost:8000' ,
18
+
19
+ onPrepare : function ( ) {
20
+ var ptor = protractor . getInstance ( ) ;
21
+ ptor . elem = ptor . findElement ;
22
+ ptor . elems = ptor . findElements ;
23
+ global . by = protractor . By ;
24
+ global . ptor = ptor ;
25
+ }
26
+ } ;
You can’t perform that action at this time.
0 commit comments