diff options
| author | Julie | 2014-01-11 16:59:15 -0800 |
|---|---|---|
| committer | Caitlin Potter | 2014-01-28 14:14:20 -0500 |
| commit | 7aef2d54e0a48fae18a289813f699962d8310565 (patch) | |
| tree | 60d1d559510c17e879aff798f298e6bcc262d3ab /src/ng | |
| parent | ce37ae28687167f7b4274ba547f013980126a219 (diff) | |
| download | angular.js-7aef2d54e0a48fae18a289813f699962d8310565.tar.bz2 | |
test(docs): convert example end to end doc tests from scenario runner to protractor
Thanks to jeffbcross, petebacondarwin, btford, jdeboer, tbosch for contributions!
Closes #6023
Diffstat (limited to 'src/ng')
28 files changed, 645 insertions, 496 deletions
diff --git a/src/ng/compile.js b/src/ng/compile.js index dd47ca3b..193dff7a 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -424,13 +424,17 @@ <div compile="html"></div> </div> </doc:source> - <doc:scenario> + <doc:protractor> it('should auto compile', function() { - expect(element('div[compile]').text()).toBe('Hello Angular'); - input('html').enter('{{name}}!'); - expect(element('div[compile]').text()).toBe('Angular!'); + var textarea = $('textarea'); + var output = $('div[compile]'); + // The initial state reads 'Hello Angular'. + expect(output.getText()).toBe('Hello Angular'); + textarea.clear(); + textarea.sendKeys('{{name}}!'); + expect(output.getText()).toBe('Angular!'); }); - </doc:scenario> + </doc:protractor> </doc:example> * diff --git a/src/ng/directive/booleanAttrs.js b/src/ng/directive/booleanAttrs.js index 30e57bdf..79199925 100644 --- a/src/ng/directive/booleanAttrs.js +++ b/src/ng/directive/booleanAttrs.js @@ -41,46 +41,48 @@ <a id="link-5" name="xxx" ng-click="value = 5">anchor</a> (no link)<br /> <a id="link-6" ng-href="{{value}}">link</a> (link, change location) </doc:source> - <doc:scenario> + <doc:protractor> it('should execute ng-click but not reload when href without value', function() { - element('#link-1').click(); - expect(input('value').val()).toEqual('1'); - expect(element('#link-1').attr('href')).toBe(""); + element(by.id('link-1')).click(); + expect(element(by.model('value')).getAttribute('value')).toEqual('1'); + expect(element(by.id('link-1')).getAttribute('href')).toBe(''); }); it('should execute ng-click but not reload when href empty string', function() { - element('#link-2').click(); - expect(input('value').val()).toEqual('2'); - expect(element('#link-2').attr('href')).toBe(""); + element(by.id('link-2')).click(); + expect(element(by.model('value')).getAttribute('value')).toEqual('2'); + expect(element(by.id('link-2')).getAttribute('href')).toBe(''); }); it('should execute ng-click and change url when ng-href specified', function() { - expect(element('#link-3').attr('href')).toBe("/123"); + expect(element(by.id('link-3')).getAttribute('href')).toMatch(/\/123$/); - element('#link-3').click(); - expect(browser().window().path()).toEqual('/123'); + element(by.id('link-3')).click(); + + expect(browser.driver.getCurrentUrl()).toMatch(/\/123$/); }); it('should execute ng-click but not reload when href empty string and name specified', function() { - element('#link-4').click(); - expect(input('value').val()).toEqual('4'); - expect(element('#link-4').attr('href')).toBe(''); + element(by.id('link-4')).click(); + expect(element(by.model('value')).getAttribute('value')).toEqual('4'); + expect(element(by.id('link-4')).getAttribute('href')).toBe(''); }); it('should execute ng-click but not reload when no href but name specified', function() { - element('#link-5').click(); - expect(input('value').val()).toEqual('5'); - expect(element('#link-5').attr('href')).toBe(undefined); + element(by.id('link-5')).click(); + expect(element(by.model('value')).getAttribute('value')).toEqual('5'); + expect(element(by.id('link-5')).getAttribute('href')).toBe(null); }); it('should only change url when only ng-href', function() { - input('value').enter('6'); - expect(element('#link-6').attr('href')).toBe('6'); + element(by.model('value')).clear(); + element(by.model('value')).sendKeys('6'); + expect(element(by.id('link-6')).getAttribute('href')).toMatch(/\/6$/); - element('#link-6').click(); - expect(browser().location().url()).toEqual('/6'); + element(by.id('link-6')).click(); + expect(browser.getCurrentUrl()).toMatch(/\/6$/); }); - </doc:scenario> + </doc:protractor> </doc:example> */ @@ -165,13 +167,13 @@ Click me to toggle: <input type="checkbox" ng-model="checked"><br/> <button ng-model="button" ng-disabled="checked">Button</button> </doc:source> - <doc:scenario> + <doc:protractor> it('should toggle button', function() { - expect(element('.doc-example-live :button').prop('disabled')).toBeFalsy(); - input('checked').check(); - expect(element('.doc-example-live :button').prop('disabled')).toBeTruthy(); + expect(element(by.css('.doc-example-live button')).getAttribute('disabled')).toBeFalsy(); + element(by.model('checked')).click(); + expect(element(by.css('.doc-example-live button')).getAttribute('disabled')).toBeTruthy(); }); - </doc:scenario> + </doc:protractor> </doc:example> * * @element INPUT @@ -200,13 +202,13 @@ Check me to check both: <input type="checkbox" ng-model="master"><br/> <input id="checkSlave" type="checkbox" ng-checked="master"> </doc:source> - <doc:scenario> + <doc:protractor> it('should check both checkBoxes', function() { - expect(element('.doc-example-live #checkSlave').prop('checked')).toBeFalsy(); - input('master').check(); - expect(element('.doc-example-live #checkSlave').prop('checked')).toBeTruthy(); + expect(element(by.id('checkSlave')).getAttribute('checked')).toBeFalsy(); + element(by.model('master')).click(); + expect(element(by.id('checkSlave')).getAttribute('checked')).toBeTruthy(); }); - </doc:scenario> + </doc:protractor> </doc:example> * * @element INPUT @@ -235,13 +237,13 @@ Check me to make text readonly: <input type="checkbox" ng-model="checked"><br/> <input type="text" ng-readonly="checked" value="I'm Angular"/> </doc:source> - <doc:scenario> + <doc:protractor> it('should toggle readonly attr', function() { - expect(element('.doc-example-live :text').prop('readonly')).toBeFalsy(); - input('checked').check(); - expect(element('.doc-example-live :text').prop('readonly')).toBeTruthy(); + expect(element(by.css('.doc-example-live [type="text"]')).getAttribute('readonly')).toBeFalsy(); + element(by.model('checked')).click(); + expect(element(by.css('.doc-example-live [type="text"]')).getAttribute('readonly')).toBeTruthy(); }); - </doc:scenario> + </doc:protractor> </doc:example> * * @element INPUT @@ -274,13 +276,13 @@ <option id="greet" ng-selected="selected">Greetings!</option> </select> </doc:source> - <doc:scenario> + <doc:protractor> it('should select Greetings!', function() { - expect(element('.doc-example-live #greet').prop('selected')).toBeFalsy(); - input('selected').check(); - expect(element('.doc-example-live #greet').prop('selected')).toBeTruthy(); + expect(element(by.id('greet')).getAttribute('selected')).toBeFalsy(); + element(by.model('selected')).click(); + expect(element(by.id('greet')).getAttribute('selected')).toBeTruthy(); }); - </doc:scenario> + </doc:protractor> </doc:example> * * @element OPTION @@ -310,13 +312,13 @@ <summary>Show/Hide me</summary> </details> </doc:source> - <doc:scenario> + <doc:protractor> it('should toggle open', function() { - expect(element('#details').prop('open')).toBeFalsy(); - input('open').check(); - expect(element('#details').prop('open')).toBeTruthy(); + expect(element(by.id('details')).getAttribute('open')).toBeFalsy(); + element(by.model('open')).click(); + expect(element(by.id('details')).getAttribute('open')).toBeTruthy(); }); - </doc:scenario> + </doc:protractor> </doc:example> * * @element DETAILS diff --git a/src/ng/directive/form.js b/src/ng/directive/form.js index 06ffad86..86776ae7 100644 --- a/src/ng/directive/form.js +++ b/src/ng/directive/form.js @@ -305,18 +305,27 @@ function FormController(element, attrs) { <tt>myForm.$error.required = {{!!myForm.$error.required}}</tt><br> </form> </doc:source> - <doc:scenario> + <doc:protractor> it('should initialize to model', function() { - expect(binding('userType')).toEqual('guest'); - expect(binding('myForm.input.$valid')).toEqual('true'); + var userType = element(by.binding('userType')); + var valid = element(by.binding('myForm.input.$valid')); + + expect(userType.getText()).toContain('guest'); + expect(valid.getText()).toContain('true'); }); it('should be invalid if empty', function() { - input('userType').enter(''); - expect(binding('userType')).toEqual(''); - expect(binding('myForm.input.$valid')).toEqual('false'); + var userType = element(by.binding('userType')); + var valid = element(by.binding('myForm.input.$valid')); + var userInput = element(by.model('userType')); + + userInput.clear(); + userInput.sendKeys(''); + + expect(userType.getText()).toEqual('userType ='); + expect(valid.getText()).toContain('false'); }); - </doc:scenario> + </doc:protractor> </doc:example> */ var formDirectiveFactory = function(isNgForm) { diff --git a/src/ng/directive/input.js b/src/ng/directive/input.js index 53a8ddd4..85d0f22d 100644 --- a/src/ng/directive/input.js +++ b/src/ng/directive/input.js @@ -62,29 +62,31 @@ var inputType = { <tt>myForm.$error.required = {{!!myForm.$error.required}}</tt><br/> </form> </doc:source> - <doc:scenario> + <doc:protractor> + var text = element(by.binding('text')); + var valid = element(by.binding('myForm.input.$valid')); + var input = element(by.model('text')); + it('should initialize to model', function() { - expect(binding('text')).toEqual('guest'); - expect(binding('myForm.input.$valid')).toEqual('true'); + expect(text.getText()).toContain('guest'); + expect(valid.getText()).toContain('true'); }); it('should be invalid if empty', function() { - input('text').enter(''); - expect(binding('text')).toEqual(''); - expect(binding('myForm.input.$valid')).toEqual('false'); + input.clear(); + input.sendKeys(''); + + expect(text.getText()).toEqual('text ='); + expect(valid.getText()).toContain('false'); }); it('should be invalid if multi word', function() { - input('text').enter('hello world'); - expect(binding('myForm.input.$valid')).toEqual('false'); - }); + input.clear(); + input.sendKeys('hello world'); - it('should not be trimmed', function() { - input('text').enter('untrimmed '); - expect(binding('text')).toEqual('untrimmed '); - expect(binding('myForm.input.$valid')).toEqual('true'); + expect(valid.getText()).toContain('false'); }); - </doc:scenario> + </doc:protractor> </doc:example> */ 'text': textInputType, @@ -138,24 +140,30 @@ var inputType = { <tt>myForm.$error.required = {{!!myForm.$error.required}}</tt><br/> </form> </doc:source> - <doc:scenario> + <doc:protractor> + var value = element(by.binding('value')); + var valid = element(by.binding('myForm.input.$valid')); + var input = element(by.model('value')); + it('should initialize to model', function() { - expect(binding('value')).toEqual('12'); - expect(binding('myForm.input.$valid')).toEqual('true'); + expect(value.getText()).toContain('12'); + expect(valid.getText()).toContain('true'); }); it('should be invalid if empty', function() { - input('value').enter(''); - expect(binding('value')).toEqual(''); - expect(binding('myForm.input.$valid')).toEqual('false'); + input.clear(); + input.sendKeys(''); + expect(value.getText()).toEqual('value ='); + expect(valid.getText()).toContain('false'); }); it('should be invalid if over max', function() { - input('value').enter('123'); - expect(binding('value')).toEqual(''); - expect(binding('myForm.input.$valid')).toEqual('false'); + input.clear(); + input.sendKeys('123'); + expect(value.getText()).toEqual('value ='); + expect(valid.getText()).toContain('false'); }); - </doc:scenario> + </doc:protractor> </doc:example> */ 'number': numberInputType, @@ -207,23 +215,31 @@ var inputType = { <tt>myForm.$error.url = {{!!myForm.$error.url}}</tt><br/> </form> </doc:source> - <doc:scenario> + <doc:protractor> + var text = element(by.binding('text')); + var valid = element(by.binding('myForm.input.$valid')); + var input = element(by.model('text')); + it('should initialize to model', function() { - expect(binding('text')).toEqual('http://google.com'); - expect(binding('myForm.input.$valid')).toEqual('true'); + expect(text.getText()).toContain('http://google.com'); + expect(valid.getText()).toContain('true'); }); it('should be invalid if empty', function() { - input('text').enter(''); - expect(binding('text')).toEqual(''); - expect(binding('myForm.input.$valid')).toEqual('false'); + input.clear(); + input.sendKeys(''); + + expect(text.getText()).toEqual('text ='); + expect(valid.getText()).toContain('false'); }); it('should be invalid if not url', function() { - input('text').enter('xxx'); - expect(binding('myForm.input.$valid')).toEqual('false'); + input.clear(); + input.sendKeys('box'); + + expect(valid.getText()).toContain('false'); }); - </doc:scenario> + </doc:protractor> </doc:example> */ 'url': urlInputType, @@ -275,23 +291,30 @@ var inputType = { <tt>myForm.$error.email = {{!!myForm.$error.email}}</tt><br/> </form> </doc:source> - <doc:scenario> + <doc:protractor> + var text = element(by.binding('text')); + var valid = element(by.binding('myForm.input.$valid')); + var input = element(by.model('text')); + it('should initialize to model', function() { - expect(binding('text')).toEqual('me@example.com'); - expect(binding('myForm.input.$valid')).toEqual('true'); + expect(text.getText()).toContain('me@example.com'); + expect(valid.getText()).toContain('true'); }); it('should be invalid if empty', function() { - input('text').enter(''); - expect(binding('text')).toEqual(''); - expect(binding('myForm.input.$valid')).toEqual('false'); + input.clear(); + input.sendKeys(''); + expect(text.getText()).toEqual('text ='); + expect(valid.getText()).toContain('false'); }); it('should be invalid if not email', function() { - input('text').enter('xxx'); - expect(binding('myForm.input.$valid')).toEqual('false'); + input.clear(); + input.sendKeys('xxx'); + + expect(valid.getText()).toContain('false'); }); - </doc:scenario> + </doc:protractor> </doc:example> */ 'email': emailInputType, @@ -332,14 +355,17 @@ var inputType = { </form> Note that `ng-value="specialValue"` sets radio item's value to be the value of `$scope.specialValue`. </doc:source> - <doc:scenario> + <doc:protractor> it('should change state', function() { - expect(binding('color')).toEqual('"blue"'); + var color = element(by.binding('color')); + + expect(color.getText()).toContain('blue'); + + element.all(by.model('color')).get(0).click(); - input('color').select('red'); - expect(binding('color')).toEqual('"red"'); + expect(color.getText()).toContain('red'); }); - </doc:scenario> + </doc:protractor> </doc:example> */ 'radio': radioInputType, @@ -376,17 +402,21 @@ var inputType = { <tt>value2 = {{value2}}</tt><br/> </form> </doc:source> - <doc:scenario> + <doc:protractor> it('should change state', function() { - expect(binding('value1')).toEqual('true'); - expect(binding('value2')).toEqual('YES'); + var value1 = element(by.binding('value1')); + var value2 = element(by.binding('value2')); - input('value1').check(); - input('value2').check(); - expect(binding('value1')).toEqual('false'); - expect(binding('value2')).toEqual('NO'); + expect(value1.getText()).toContain('true'); + expect(value2.getText()).toContain('YES'); + + element(by.model('value1')).click(); + element(by.model('value2')).click(); + + expect(value1.getText()).toContain('false'); + expect(value2.getText()).toContain('NO'); }); - </doc:scenario> + </doc:protractor> </doc:example> */ 'checkbox': checkboxInputType, @@ -739,44 +769,59 @@ function checkboxInputType(scope, element, attr, ctrl) { <tt>myForm.$error.maxlength = {{!!myForm.$error.maxlength}}</tt><br> </div> </doc:source> - <doc:scenario> + <doc:protractor> + var user = element(by.binding('{{user}}')); + var userNameValid = element(by.binding('myForm.userName.$valid')); + var lastNameValid = element(by.binding('myForm.lastName.$valid')); + var lastNameError = element(by.binding('myForm.lastName.$error')); + var formValid = element(by.binding('myForm.$valid')); + var userNameInput = element(by.model('user.name')); + var userLastInput = element(by.model('user.last')); + it('should initialize to model', function() { - expect(binding('user')).toEqual('{"name":"guest","last":"visitor"}'); - expect(binding('myForm.userName.$valid')).toEqual('true'); - expect(binding('myForm.$valid')).toEqual('true'); + expect(user.getText()).toContain('{"name":"guest","last":"visitor"}'); + expect(userNameValid.getText()).toContain('true'); + expect(formValid.getText()).toContain('true'); }); it('should be invalid if empty when required', function() { - input('user.name').enter(''); - expect(binding('user')).toEqual('{"last":"visitor"}'); - expect(binding('myForm.userName.$valid')).toEqual('false'); - expect(binding('myForm.$valid')).toEqual('false'); + userNameInput.clear(); + userNameInput.sendKeys(''); + + expect(user.getText()).toContain('{"last":"visitor"}'); + expect(userNameValid.getText()).toContain('false'); + expect(formValid.getText()).toContain('false'); }); it('should be valid if empty when min length is set', function() { - input('user.last').enter(''); - expect(binding('user')).toEqual('{"name":"guest","last":""}'); - expect(binding('myForm.lastName.$valid')).toEqual('true'); - expect(binding('myForm.$valid')).toEqual('true'); + userLastInput.clear(); + userLastInput.sendKeys(''); + + expect(user.getText()).toContain('{"name":"guest","last":""}'); + expect(lastNameValid.getText()).toContain('true'); + expect(formValid.getText()).toContain('true'); }); it('should be invalid if less than required min length', function() { - input('user.last').enter('xx'); - expect(binding('user')).toEqual('{"name":"guest"}'); - expect(binding('myForm.lastName.$valid')).toEqual('false'); - expect(binding('myForm.lastName.$error')).toMatch(/minlength/); - expect(binding('myForm.$valid')).toEqual('false'); + userLastInput.clear(); + userLastInput.sendKeys('xx'); + + expect(user.getText()).toContain('{"name":"guest"}'); + expect(lastNameValid.getText()).toContain('false'); + expect(lastNameError.getText()).toContain('minlength'); + expect(formValid.getText()).toContain('false'); }); it('should be invalid if longer than max length', function() { - input('user.last').enter('some ridiculously long name'); - expect(binding('user')) - .toEqual('{"name":"guest"}'); - expect(binding('myForm.lastName.$valid')).toEqual('false'); - expect(binding('myForm.lastName.$error')).toMatch(/maxlength/); - expect(binding('myForm.$valid')).toEqual('false'); + userLastInput.clear(); + userLastInput.sendKeys('some ridiculously long name'); + + expect(user.getText()).toContain('{"name":"guest"}'); + expect(lastNameValid.getText()).toContain('false'); + expect(lastNameError.getText()).toContain('maxlength'); + expect(formValid.getText()).toContain('false'); }); - </doc:scenario> + </doc:protractor> </doc:example> */ var inputDirective = ['$browser', '$sniffer', function($browser, $sniffer) { @@ -908,14 +953,17 @@ var VALID_CLASS = 'ng-valid', <textarea ng-model="userContent"></textarea> </form> </file> - <file name="scenario.js"> + <file name="protractorTest.js"> it('should data-bind and become invalid', function() { - var contentEditable = element('[contenteditable]'); + var contentEditable = element(by.css('.doc-example-live [contenteditable]')); + + expect(contentEditable.getText()).toEqual('Change me!'); - expect(contentEditable.text()).toEqual('Change me!'); - input('userContent').enter(''); - expect(contentEditable.text()).toEqual(''); - expect(contentEditable.prop('className')).toMatch(/ng-invalid-required/); + contentEditable.clear(); + contentEditable.sendKeys(protractor.Key.BACK_SPACE); + + expect(contentEditable.getText()).toEqual(''); + expect(contentEditable.getAttribute('class')).toMatch(/ng-invalid-required/); }); </file> * </example> @@ -1222,24 +1270,30 @@ var ngModelDirective = function() { * <input type="checkbox" ng-model="confirmed" ng-change="change()" id="ng-change-example1" /> * <input type="checkbox" ng-model="confirmed" id="ng-change-example2" /> * <label for="ng-change-example2">Confirmed</label><br /> - * debug = {{confirmed}}<br /> - * counter = {{counter}} + * <tt>debug = {{confirmed}}</tt><br/> + * <tt>counter = {{counter}}</tt><br/> * </div> * </doc:source> - * <doc:scenario> + * <doc:protractor> + * var counter = element(by.binding('counter')); + * var debug = element(by.binding('confirmed')); + * * it('should evaluate the expression if changing from view', function() { - * expect(binding('counter')).toEqual('0'); - * element('#ng-change-example1').click(); - * expect(binding('counter')).toEqual('1'); - * expect(binding('confirmed')).toEqual('true'); + * expect(counter.getText()).toContain('0'); + * + * element(by.id('ng-change-example1')).click(); + * + * expect(counter.getText()).toContain('1'); + * expect(debug.getText()).toContain('true'); * }); * * it('should not evaluate the expression if changing from model', function() { - * element('#ng-change-example2').click(); - * expect(binding('counter')).toEqual('0'); - * expect(binding('confirmed')).toEqual('true'); + * element(by.id('ng-change-example2')).click(); + + * expect(counter.getText()).toContain('0'); + * expect(debug.getText()).toContain('true'); * }); - * </doc:scenario> + * </doc:protractor> * </doc:example> */ var ngChangeDirective = valueFn({ @@ -1312,20 +1366,26 @@ var requiredDirective = function() { <tt>myForm.$error.required = {{!!myForm.$error.required}}</tt><br/> </form> </doc:source> - <doc:scenario> + <doc:protractor> + var listInput = element(by.model('names')); + var names = element(by.binding('{{names}}')); + var valid = element(by.binding('myForm.namesInput.$valid')); + var error = element(by.css('span.error')); + it('should initialize to model', function() { - expect(binding('names')).toEqual('["igor","misko","vojta"]'); - expect(binding('myForm.namesInput.$valid')).toEqual('true'); - expect(element('span.error').css('display')).toBe('none'); + expect(names.getText()).toContain('["igor","misko","vojta"]'); + expect(valid.getText()).toContain('true'); + expect(error.getCssValue('display')).toBe('none'); }); it('should be invalid if empty', function() { - input('names').enter(''); - expect(binding('names')).toEqual(''); - expect(binding('myForm.namesInput.$valid')).toEqual('false'); - expect(element('span.error').css('display')).not().toBe('none'); - }); - </doc:scenario> + listInput.clear(); + listInput.sendKeys(''); + + expect(names.getText()).toContain(''); + expect(valid.getText()).toContain('false'); + expect(error.getCssValue('display')).not.toBe('none'); }); + </doc:protractor> </doc:example> */ var ngListDirective = function() { @@ -1407,15 +1467,17 @@ var CONSTANT_VALUE_REGEXP = /^(true|false|\d+)$/; <div>You chose {{my.favorite}}</div> </form> </doc:source> - <doc:scenario> + <doc:protractor> + var favorite = element(by.binding('my.favorite')); + it('should initialize to model', function() { - expect(binding('my.favorite')).toEqual('unicorns'); + expect(favorite.getText()).toContain('unicorns'); }); it('should bind the values to the inputs', function() { - input('my.favorite').select('pizza'); - expect(binding('my.favorite')).toEqual('pizza'); + element.all(by.model('my.favorite')).get(0).click(); + expect(favorite.getText()).toContain('pizza'); }); - </doc:scenario> + </doc:protractor> </doc:example> */ var ngValueDirective = function() { diff --git a/src/ng/directive/ngBind.js b/src/ng/directive/ngBind.js index ecfc8ab6..5d0e3009 100644 --- a/src/ng/directive/ngBind.js +++ b/src/ng/directive/ngBind.js @@ -38,13 +38,17 @@ Hello <span ng-bind="name"></span>! </div> </doc:source> - <doc:scenario> + <doc:protractor> it('should check ng-bind', function() { - expect(using('.doc-example-live').binding('name')).toBe('Whirled'); - using('.doc-example-live').input('name').enter('world'); - expect(using('.doc-example-live').binding('name')).toBe('world'); + var exampleContainer = $('.doc-example-live'); + var nameInput = element(by.model('name')); + + expect(exampleContainer.findElement(by.binding('name')).getText()).toBe('Whirled'); + nameInput.clear(); + nameInput.sendKeys('world'); + expect(exampleContainer.findElement(by.binding('name')).getText()).toBe('world'); }); - </doc:scenario> + </doc:protractor> </doc:example> */ var ngBindDirective = ngDirective(function(scope, element, attr) { @@ -90,20 +94,22 @@ var ngBindDirective = ngDirective(function(scope, element, attr) { <pre ng-bind-template="{{salutation}} {{name}}!"></pre> </div> </doc:source> - <doc:scenario> + <doc:protractor> it('should check ng-bind', function() { - expect(using('.doc-example-live').binding('salutation')). - toBe('Hello'); - expect(using('.doc-example-live').binding('name')). - toBe('World'); - using('.doc-example-live').input('salutation').enter('Greetings'); - using('.doc-example-live').input('name').enter('user'); - expect(using('.doc-example-live').binding('salutation')). - toBe('Greetings'); - expect(using('.doc-example-live').binding('name')). - toBe('user'); + var salutationElem = element(by.binding('salutation')); + var salutationInput = element(by.model('salutation')); + var nameInput = element(by.model('name')); + + expect(salutationElem.getText()).toBe('Hello World!'); + + salutationInput.clear(); + salutationInput.sendKeys('Greetings'); + nameInput.clear(); + nameInput.sendKeys('user'); + + expect(salutationElem.getText()).toBe('Greetings user!'); }); - </doc:scenario> + </doc:protractor> </doc:example> */ var ngBindTemplateDirective = ['$interpolate', function($interpolate) { @@ -156,12 +162,10 @@ var ngBindTemplateDirective = ['$interpolate', function($interpolate) { }]); </file> - <file name="scenario.js"> + <file name="protractorTest.js"> it('should check ng-bind-html', function() { - expect(using('.doc-example-live').binding('myHTML')). - toBe( - 'I am an <code>HTML</code>string with <a href="#">links!</a> and other <em>stuff</em>' - ); + expect(element(by.binding('myHTML')).getText()).toBe( + 'I am an HTMLstring with links! and other stuff'); }); </file> </example> diff --git a/src/ng/directive/ngClass.js b/src/ng/directive/ngClass.js index 21316c57..c9384b08 100644 --- a/src/ng/directive/ngClass.js +++ b/src/ng/directive/ngClass.js @@ -114,31 +114,35 @@ function classDirective(name, selector) { color: red; } </file> - <file name="scenario.js"> + <file name="protractorTest.js"> + var ps = element.all(by.css('.doc-example-live p')); + it('should let you toggle the class', function() { - expect(element('.doc-example-live p:first').prop('className')).not().toMatch(/bold/); - expect(element('.doc-example-live p:first').prop('className')).not().toMatch(/red/); + expect(ps.first().getAttribute('class')).not.toMatch(/bold/); + expect(ps.first().getAttribute('class')).not.toMatch(/red/); - input('important').check(); - expect(element('.doc-example-live p:first').prop('className')).toMatch(/bold/); + element(by.model('important')).click(); + expect(ps.first().getAttribute('class')).toMatch(/bold/); - input('error').check(); - expect(element('.doc-example-live p:first').prop('className')).toMatch(/red/); + element(by.model('error')).click(); + expect(ps.first().getAttribute('class')).toMatch(/red/); }); it('should let you toggle string example', function() { - expect(element('.doc-example-live p:nth-of-type(2)').prop('className')).toBe(''); - input('style').enter('red'); - expect(element('.doc-example-live p:nth-of-type(2)').prop('className')).toBe('red'); + expect(ps.get(1).getAttribute('class')).toBe(''); + element(by.model('style')).clear(); + element(by.model('style')).sendKeys('red'); + browser.debugger(); + expect(ps.get(1).getAttribute('class')).toBe('red'); }); it('array example should have 3 classes', function() { - expect(element('.doc-example-live p:last').prop('className')).toBe(''); - input('style1').enter('bold'); - input('style2').enter('strike'); - input('style3').enter('red'); - expect(element('.doc-example-live p:last').prop('className')).toBe('bold strike red'); + expect(ps.last().getAttribute('class')).toBe(''); + element(by.model('style1')).sendKeys('bold'); + element(by.model('style2')).sendKeys('strike'); + element(by.model('style3')).sendKeys('red'); + expect(ps.last().getAttribute('class')).toBe('bold strike red'); }); </file> </example> @@ -149,8 +153,8 @@ function classDirective(name, selector) { <example animations="true"> <file name="index.html"> - <input type="button" value="set" ng-click="myVar='my-class'"> - <input type="button" value="clear" ng-click="myVar=''"> + <input id="setbtn" type="button" value="set" ng-click="myVar='my-class'"> + <input id="clearbtn" type="button" value="clear" ng-click="myVar=''"> <br> <span class="base-class" ng-class="myVar">Sample Text</span> </file> @@ -165,19 +169,19 @@ function classDirective(name, selector) { font-size:3em; } </file> - <file name="scenario.js"> + <file name="protractorTest.js"> it('should check ng-class', function() { - expect(element('.doc-example-live span').prop('className')).not(). + expect(element(by.css('.base-class')).getAttribute('class')).not. toMatch(/my-class/); - using('.doc-example-live').element(':button:first').click(); + element(by.id('setbtn')).click(); - expect(element('.doc-example-live span').prop('className')). + expect(element(by.css('.base-class')).getAttribute('class')). toMatch(/my-class/); - using('.doc-example-live').element(':button:last').click(); + element(by.id('clearbtn')).click(); - expect(element('.doc-example-live span').prop('className')).not(). + expect(element(by.css('.base-class')).getAttribute('class')).not. toMatch(/my-class/); }); </file> @@ -229,11 +233,11 @@ var ngClassDirective = classDirective('', true); color: blue; } </file> - <file name="scenario.js"> + <file name="protractorTest.js"> it('should check ng-class-odd and ng-class-even', function() { - expect(element('.doc-example-live li:first span').prop('className')). + expect(element(by.repeater('name in names').row(0).column('name')).getAttribute('class')). toMatch(/odd/); - expect(element('.doc-example-live li:last span').prop('className')). + expect(element(by.repeater('name in names').row(1).column('name')).getAttribute('class')). toMatch(/even/); }); </file> @@ -277,11 +281,11 @@ var ngClassOddDirective = classDirective('Odd', 0); color: blue; } </file> - <file name="scenario.js"> + <file name="protractorTest.js"> it('should check ng-class-odd and ng-class-even', function() { - expect(element('.doc-example-live li:first span').prop('className')). + expect(element(by.repeater('name in names').row(0).column('name')).getAttribute('class')). toMatch(/odd/); - expect(element('.doc-example-live li:last span').prop('className')). + expect(element(by.repeater('name in names').row(1).column('name')).getAttribute('class')). toMatch(/even/); }); </file> diff --git a/src/ng/directive/ngCloak.js b/src/ng/directive/ngCloak.js index 5072c8c2..220c964d 100644 --- a/src/ng/directive/ngCloak.js +++ b/src/ng/directive/ngCloak.js @@ -45,14 +45,14 @@ <div id="template1" ng-cloak>{{ 'hello' }}</div> <div id="template2" ng-cloak class="ng-cloak">{{ 'hello IE7' }}</div> </doc:source> - <doc:scenario> + <doc:protractor> it('should remove the template directive and css class', function() { - expect(element('.doc-example-live #template1').attr('ng-cloak')). - not().toBeDefined(); - expect(element('.doc-example-live #template2').attr('ng-cloak')). - not().toBeDefined(); + expect($('.doc-example-live #template1').getAttribute('ng-cloak')). + toBeNull(); + expect($('.doc-example-live #template2').getAttribute('ng-cloak')). + toBeNull(); }); - </doc:scenario> + </doc:protractor> </doc:example> * */ diff --git a/src/ng/directive/ngController.js b/src/ng/directive/ngController.js index 5550b77f..7149d090 100644 --- a/src/ng/directive/ngController.js +++ b/src/ng/directive/ngController.js @@ -82,22 +82,36 @@ </ul> </div> </doc:source> - <doc:scenario> + <doc:protractor> it('should check controller as', function() { - expect(element('#ctrl-as-exmpl>:input').val()).toBe('John Smith'); - expect(element('#ctrl-as-exmpl li:nth-child(1) input').val()) - .toBe('408 555 1212'); - expect(element('#ctrl-as-exmpl li:nth-child(2) input').val()) - .toBe('john.smith@example.org'); - - element('#ctrl-as-exmpl li:first a:contains("clear")').click(); - expect(element('#ctrl-as-exmpl li:first input').val()).toBe(''); - - element('#ctrl-as-exmpl li:last a:contains("add")').click(); - expect(element('#ctrl-as-exmpl li:nth-child(3) input').val()) - .toBe('yourname@example.org'); + var container = element(by.id('ctrl-as-exmpl')); + + expect(container.findElement(by.model('settings.name')) + .getAttribute('value')).toBe('John Smith'); + + var firstRepeat = + container.findElement(by.repeater('contact in settings.contacts').row(0)); + var secondRepeat = + container.findElement(by.repeater('contact in settings.contacts').row(1)); + + expect(firstRepeat.findElement(by.model('contact.value')).getAttribute('value')) + .toBe('408 555 1212'); + expect(secondRepeat.findElement(by.model('contact.value')).getAttribute('value')) + .toBe('john.smith@example.org'); + + firstRepeat.findElement(by.linkText('clear')).click() + + expect(firstRepeat.findElement(by.model('contact.value')).getAttribute('value')) + .toBe(''); + + container.findElement(by.linkText('add')).click(); + + expect(container.findElement(by.repeater('contact in settings.contacts').row(2)) + .findElement(by.model('contact.value')) + .getAttribute('value')) + .toBe('yourname@example.org'); }); - </doc:scenario> + </doc:protractor> </doc:example> <doc:example> <doc:source> @@ -145,22 +159,36 @@ </ul> </div> </doc:source> - <doc:scenario> + <doc:protractor> it('should check controller', function() { - expect(element('#ctrl-exmpl>:input').val()).toBe('John Smith'); - expect(element('#ctrl-exmpl li:nth-child(1) input').val()) - .toBe('408 555 1212'); - expect(element('#ctrl-exmpl li:nth-child(2) input').val()) - .toBe('john.smith@example.org'); - - element('#ctrl-exmpl li:first a:contains("clear")').click(); - expect(element('#ctrl-exmpl li:first input').val()).toBe(''); - - element('#ctrl-exmpl li:last a:contains("add")').click(); - expect(element('#ctrl-exmpl li:nth-child(3) input').val()) - .toBe('yourname@example.org'); + var container = element(by.id('ctrl-exmpl')); + + expect(container.findElement(by.model('name')) + .getAttribute('value')).toBe('John Smith'); + + var firstRepeat = + container.findElement(by.repeater('contact in contacts').row(0)); + var secondRepeat = + container.findElement(by.repeater('contact in contacts').row(1)); + + expect(firstRepeat.findElement(by.model('contact.value')).getAttribute('value')) + .toBe('408 555 1212'); + expect(secondRepeat.findElement(by.model('contact.value')).getAttribute('value')) + .toBe('john.smith@example.org'); + + firstRepeat.findElement(by.linkText('clear')).click() + + expect(firstRepeat.findElement(by.model('contact.value')).getAttribute('value')) + .toBe(''); + + container.findElement(by.linkText('add')).click(); + + expect(container.findElement(by.repeater('contact in contacts').row(2)) + .findElement(by.model('contact.value')) + .getAttribute('value')) + .toBe('yourname@example.org'); }); - </doc:scenario> + </doc:protractor> </doc:example> */ diff --git a/src/ng/directive/ngEventDirs.js b/src/ng/directive/ngEventDirs.js index 7dba5749..f63d3ca1 100644 --- a/src/ng/directive/ngEventDirs.js +++ b/src/ng/directive/ngEventDirs.js @@ -327,20 +327,20 @@ forEach( <pre>list={{list}}</pre> </form> </doc:source> - <doc:scenario> + <doc:protractor> it('should check ng-submit', function() { - expect(binding('list')).toBe('[]'); - element('.doc-example-live #submit').click(); - expect(binding('list')).toBe('["hello"]'); - expect(input('text').val()).toBe(''); + expect(element(by.binding('list')).getText()).toBe('list=[]'); + element(by.css('.doc-example-live #submit')).click(); + expect(element(by.binding('list')).getText()).toContain('hello'); + expect(element(by.input('text')).getAttribute('value')).toBe(''); }); it('should ignore empty strings', function() { - expect(binding('list')).toBe('[]'); - element('.doc-example-live #submit').click(); - element('.doc-example-live #submit').click(); - expect(binding('list')).toBe('["hello"]'); - }); - </doc:scenario> + expect(element(by.binding('list')).getText()).toBe('list=[]'); + element(by.css('.doc-example-live #submit')).click(); + element(by.css('.doc-example-live #submit')).click(); + expect(element(by.binding('list')).getText()).toContain('hello'); + }); + </doc:protractor> </doc:example> */ diff --git a/src/ng/directive/ngInclude.js b/src/ng/directive/ngInclude.js index d6b38663..4935edd4 100644 --- a/src/ng/directive/ngInclude.js +++ b/src/ng/directive/ngInclude.js @@ -110,19 +110,24 @@ top:50px; } </file> - <file name="scenario.js"> + <file name="protractorTest.js"> + var templateSelect = element(by.model('template')); + var includeElem = element(by.css('.doc-example-live [ng-include]')); + it('should load template1.html', function() { - expect(element('.doc-example-live [ng-include]').text()). - toMatch(/Content of template1.html/); + expect(includeElem.getText()).toMatch(/Content of template1.html/); }); + it('should load template2.html', function() { - select('template').option('1'); - expect(element('.doc-example-live [ng-include]').text()). - toMatch(/Content of template2.html/); + templateSelect.click(); + templateSelect.element.all(by.css('option')).get(2).click(); + expect(includeElem.getText()).toMatch(/Content of template2.html/); }); + it('should change to blank', function() { - select('template').option(''); - expect(element('.doc-example-live [ng-include]')).toBe(undefined); + templateSelect.click(); + templateSelect.element.all(by.css('option')).get(0).click(); + expect(includeElem.isPresent()).toBe(false); }); </file> </example> diff --git a/src/ng/directive/ngInit.js b/src/ng/directive/ngInit.js index 6270a6d8..d5a1e245 100644 --- a/src/ng/directive/ngInit.js +++ b/src/ng/directive/ngInit.js @@ -44,15 +44,15 @@ </div> </div> </doc:source> - <doc:scenario> + <doc:protractor> it('should alias index positions', function() { - expect(element('.example-init').text()) - .toBe('list[ 0 ][ 0 ] = a;' + - 'list[ 0 ][ 1 ] = b;' + - 'list[ 1 ][ 0 ] = c;' + - 'list[ 1 ][ 1 ] = d;'); + var elements = element.all(by.css('.example-init')); + expect(elements.get(0).getText()).toBe('list[ 0 ][ 0 ] = a;'); + expect(elements.get(1).getText()).toBe('list[ 0 ][ 1 ] = b;'); + expect(elements.get(2).getText()).toBe('list[ 1 ][ 0 ] = c;'); + expect(elements.get(3).getText()).toBe('list[ 1 ][ 1 ] = d;'); }); - </doc:scenario> + </doc:protractor> </doc:example> */ var ngInitDirective = ngDirective({ diff --git a/src/ng/directive/ngNonBindable.js b/src/ng/directive/ngNonBindable.js index 473b416b..16073376 100644 --- a/src/ng/directive/ngNonBindable.js +++ b/src/ng/directive/ngNonBindable.js @@ -24,13 +24,12 @@ <div>Normal: {{1 + 2}}</div> <div ng-non-bindable>Ignored: {{1 + 2}}</div> </doc:source> - <doc:scenario> + <doc:protractor> it('should check ng-non-bindable', function() { - expect(using('.doc-example-live').binding('1 + 2')).toBe('3'); - expect(using('.doc-example-live').element('div:last').text()). - toMatch(/1 \+ 2/); + expect(element(by.binding('1 + 2')).getText()).toContain('3'); + expect(element.all(by.css('.doc-example-live div')).last().getText()).toMatch(/1 \+ 2/); }); - </doc:scenario> + </doc:protractor> </doc:example> */ var ngNonBindableDirective = ngDirective({ terminal: true, priority: 1000 }); diff --git a/src/ng/directive/ngPluralize.js b/src/ng/directive/ngPluralize.js index 7004bf4f..58af4515 100644 --- a/src/ng/directive/ngPluralize.js +++ b/src/ng/directive/ngPluralize.js @@ -123,49 +123,53 @@ </ng-pluralize> </div> </doc:source> - <doc:scenario> + <doc:protractor> it('should show correct pluralized string', function() { - expect(element('.doc-example-live ng-pluralize:first').text()). - toBe('1 person is viewing.'); - expect(element('.doc-example-live ng-pluralize:last').text()). - toBe('Igor is viewing.'); + var withoutOffset = element.all(by.css('ng-pluralize')).get(0); + var withOffset = element.all(by.css('ng-pluralize')).get(1); + var countInput = element(by.model('personCount')); - using('.doc-example-live').input('personCount').enter('0'); - expect(element('.doc-example-live ng-pluralize:first').text()). - toBe('Nobody is viewing.'); - expect(element('.doc-example-live ng-pluralize:last').text()). - toBe('Nobody is viewing.'); + expect(withoutOffset.getText()).toEqual('1 person is viewing.'); + expect(withOffset.getText()).toEqual('Igor is viewing.'); - using('.doc-example-live').input('personCount').enter('2'); - expect(element('.doc-example-live ng-pluralize:first').text()). - toBe('2 people are viewing.'); - expect(element('.doc-example-live ng-pluralize:last').text()). - toBe('Igor and Misko are viewing.'); + countInput.clear(); + countInput.sendKeys('0'); - using('.doc-example-live').input('personCount').enter('3'); - expect(element('.doc-example-live ng-pluralize:first').text()). - toBe('3 people are viewing.'); - expect(element('.doc-example-live ng-pluralize:last').text()). - toBe('Igor, Misko and one other person are viewing.'); + expect(withoutOffset.getText()).toEqual('Nobody is viewing.'); + expect(withOffset.getText()).toEqual('Nobody is viewing.'); - using('.doc-example-live').input('personCount').enter('4'); - expect(element('.doc-example-live ng-pluralize:first').text()). - toBe('4 people are viewing.'); - expect(element('.doc-example-live ng-pluralize:last').text()). - toBe('Igor, Misko and 2 other people are viewing.'); - }); + countInput.clear(); + countInput.sendKeys('2'); + + expect(withoutOffset.getText()).toEqual('2 people are viewing.'); + expect(withOffset.getText()).toEqual('Igor and Misko are viewing.'); + + countInput.clear(); + countInput.sendKeys('3'); - it('should show data-binded names', function() { - using('.doc-example-live').input('personCount').enter('4'); - expect(element('.doc-example-live ng-pluralize:last').text()). - toBe('Igor, Misko and 2 other people are viewing.'); + expect(withoutOffset.getText()).toEqual('3 people are viewing.'); + expect(withOffset.getText()).toEqual('Igor, Misko and one other person are viewing.'); - using('.doc-example-live').input('person1').enter('Di'); - using('.doc-example-live').input('person2').enter('Vojta'); - expect(element('.doc-example-live ng-pluralize:last').text()). - toBe('Di, Vojta and 2 other people are viewing.'); + countInput.clear(); + countInput.sendKeys('4'); + + expect(withoutOffset.getText()).toEqual('4 people are viewing.'); + expect(withOffset.getText()).toEqual('Igor, Misko and 2 other people are viewing.'); + }); + it('should show data-bound names', function() { + var withOffset = element.all(by.css('ng-pluralize')).get(1); + var personCount = element(by.model('personCount')); + var person1 = element(by.model('person1')); + var person2 = element(by.model('person2')); + personCount.clear(); + personCount.sendKeys('4'); + person1.clear(); + person1.sendKeys('Di'); + person2.clear(); + person2.sendKeys('Vojta'); + expect(withOffset.getText()).toEqual('Di, Vojta and 2 other people are viewing.'); }); - </doc:scenario> + </doc:protractor> </doc:example> */ var ngPluralizeDirective = ['$locale', '$interpolate', function($locale, $interpolate) { diff --git a/src/ng/directive/ngRepeat.js b/src/ng/directive/ngRepeat.js index 43db58ba..e819877c 100644 --- a/src/ng/directive/ngRepeat.js +++ b/src/ng/directive/ngRepeat.js @@ -172,25 +172,27 @@ max-height:40px; } </file> - <file name="scenario.js"> - it('should render initial data set', function() { - var r = using('.doc-example-live').repeater('ul li'); - expect(r.count()).toBe(10); - expect(r.row(0)).toEqual(["1","John","25"]); - expect(r.row(1)).toEqual(["2","Jessie","30"]); - expect(r.row(9)).toEqual(["10","Samantha","60"]); - expect(binding('friends.length')).toBe("10"); - }); + <file name="protractorTest.js"> + var friends = element(by.css('.doc-example-live')) + .element.all(by.repeater('friend in friends')); + + it('should render initial data set', function() { + expect(friends.count()).toBe(10); + expect(friends.get(0).getText()).toEqual('[1] John who is 25 years old.'); + expect(friends.get(1).getText()).toEqual('[2] Jessie who is 30 years old.'); + expect(friends.last().getText()).toEqual('[10] Samantha who is 60 years old.'); + expect(element(by.binding('friends.length')).getText()) + .toMatch("I have 10 friends. They are:"); + }); it('should update repeater when filter predicate changes', function() { - var r = using('.doc-example-live').repeater('ul li'); - expect(r.count()).toBe(10); + expect(friends.count()).toBe(10); - input('q').enter('ma'); + element(by.css('.doc-example-live')).element(by.model('q')).sendKeys('ma'); - expect(r.count()).toBe(2); - expect(r.row(0)).toEqual(["1","Mary","28"]); - expect(r.row(1)).toEqual(["2","Samantha","60"]); + expect(friends.count()).toBe(2); + expect(friends.get(0).getText()).toEqual('[1] Mary who is 28 years old.'); + expect(friends.last().getText()).toEqual('[2] Samantha who is 60 years old.'); }); </file> </example> diff --git a/src/ng/directive/ngShowHide.js b/src/ng/directive/ngShowHide.js index a3a9348d..ba33bb1a 100644 --- a/src/ng/directive/ngShowHide.js +++ b/src/ng/directive/ngShowHide.js @@ -132,16 +132,19 @@ background:white; } </file> - <file name="scenario.js"> - it('should check ng-show / ng-hide', function() { - expect(element('.doc-example-live span:first:hidden').count()).toEqual(1); - expect(element('.doc-example-live span:last:visible').count()).toEqual(1); + <file name="protractorTest.js"> + var thumbsUp = element(by.css('.doc-example-live span.icon-thumbs-up')); + var thumbsDown = element(by.css('.doc-example-live span.icon-thumbs-down')); - input('checked').check(); + it('should check ng-show / ng-hide', function() { + expect(thumbsUp.isDisplayed()).toBeFalsy(); + expect(thumbsDown.isDisplayed()).toBeTruthy(); - expect(element('.doc-example-live span:first:visible').count()).toEqual(1); - expect(element('.doc-example-live span:last:hidden').count()).toEqual(1); - }); + element(by.model('checked')).click(); + + expect(thumbsUp.isDisplayed()).toBeTruthy(); + expect(thumbsDown.isDisplayed()).toBeFalsy(); + }); </file> </example> */ @@ -286,16 +289,19 @@ var ngShowDirective = ['$animate', function($animate) { background:white; } </file> - <file name="scenario.js"> - it('should check ng-show / ng-hide', function() { - expect(element('.doc-example-live .check-element:first:hidden').count()).toEqual(1); - expect(element('.doc-example-live .check-element:last:visible').count()).toEqual(1); + <file name="protractorTest.js"> + var thumbsUp = element(by.css('.doc-example-live span.icon-thumbs-up')); + var thumbsDown = element(by.css('.doc-example-live span.icon-thumbs-down')); + + it('should check ng-show / ng-hide', function() { + expect(thumbsUp.isDisplayed()).toBeFalsy(); + expect(thumbsDown.isDisplayed()).toBeTruthy(); - input('checked').check(); + element(by.model('checked')).click(); - expect(element('.doc-example-live .check-element:first:visible').count()).toEqual(1); - expect(element('.doc-example-live .check-element:last:hidden').count()).toEqual(1); - }); + expect(thumbsUp.isDisplayed()).toBeTruthy(); + expect(thumbsDown.isDisplayed()).toBeFalsy(); + }); </file> </example> */ diff --git a/src/ng/directive/ngStyle.js b/src/ng/directive/ngStyle.js index b9fbe216..05dcfab1 100644 --- a/src/ng/directive/ngStyle.js +++ b/src/ng/directive/ngStyle.js @@ -27,13 +27,15 @@ color: black; } </file> - <file name="scenario.js"> + <file name="protractorTest.js"> + var colorSpan = element(by.css('.doc-example-live span')); + it('should check ng-style', function() { - expect(element('.doc-example-live span').css('color')).toBe('rgb(0, 0, 0)'); - element('.doc-example-live :button[value=set]').click(); - expect(element('.doc-example-live span').css('color')).toBe('rgb(255, 0, 0)'); - element('.doc-example-live :button[value=clear]').click(); - expect(element('.doc-example-live span').css('color')).toBe('rgb(0, 0, 0)'); + expect(colorSpan.getCssValue('color')).toBe('rgba(0, 0, 0, 1)'); + element(by.css('.doc-example-live input[value=set]')).click(); + expect(colorSpan.getCssValue('color')).toBe('rgba(255, 0, 0, 1)'); + element(by.css('.doc-example-live input[value=clear]')).click(); + expect(colorSpan.getCssValue('color')).toBe('rgba(0, 0, 0, 1)'); }); </file> </example> diff --git a/src/ng/directive/ngSwitch.js b/src/ng/directive/ngSwitch.js index a9845a06..97029d41 100644 --- a/src/ng/directive/ngSwitch.js +++ b/src/ng/directive/ngSwitch.js @@ -107,17 +107,20 @@ top:0; } </file> - <file name="scenario.js"> + <file name="protractorTest.js"> + var switchElem = element(by.css('.doc-example-live [ng-switch]')); + var select = element(by.model('selection')); + it('should start in settings', function() { - expect(element('.doc-example-live [ng-switch]').text()).toMatch(/Settings Div/); + expect(switchElem.getText()).toMatch(/Settings Div/); }); it('should change to home', function() { - select('selection').option('home'); - expect(element('.doc-example-live [ng-switch]').text()).toMatch(/Home Span/); + select.element.all(by.css('option')).get(1).click(); + expect(switchElem.getText()).toMatch(/Home Span/); }); it('should select default', function() { - select('selection').option('other'); - expect(element('.doc-example-live [ng-switch]').text()).toMatch(/default/); + select.element.all(by.css('option')).get(2).click(); + expect(switchElem.getText()).toMatch(/default/); }); </file> </example> diff --git a/src/ng/directive/ngTransclude.js b/src/ng/directive/ngTransclude.js index 8eefb6ff..295e47a9 100644 --- a/src/ng/directive/ngTransclude.js +++ b/src/ng/directive/ngTransclude.js @@ -40,14 +40,18 @@ <pane title="{{title}}">{{text}}</pane> </div> </doc:source> - <doc:scenario> + <doc:protractor> it('should have transcluded', function() { - input('title').enter('TITLE'); - input('text').enter('TEXT'); - expect(binding('title')).toEqual('TITLE'); - expect(binding('text')).toEqual('TEXT'); + var titleElement = element(by.model('title')); + titleElement.clear(); + titleElement.sendKeys('TITLE'); + var textElement = element(by.model('text')); + textElement.clear(); + textElement.sendKeys('TEXT'); + expect(element(by.binding('title')).getText()).toEqual('TITLE'); + expect(element(by.binding('text')).getText()).toEqual('TEXT'); }); - </doc:scenario> + </doc:protractor> </doc:example> * */ diff --git a/src/ng/directive/script.js b/src/ng/directive/script.js index 86233ff8..e86285ae 100644 --- a/src/ng/directive/script.js +++ b/src/ng/directive/script.js @@ -25,12 +25,12 @@ <a ng-click="currentTpl='/tpl.html'" id="tpl-link">Load inlined template</a> <div id="tpl-content" ng-include src="currentTpl"></div> </doc:source> - <doc:scenario> + <doc:protractor> it('should load template defined inside script tag', function() { - element('#tpl-link').click(); - expect(element('#tpl-content').text()).toMatch(/Content of the template/); + element(by.css('#tpl-link')).click(); + expect(element(by.css('#tpl-content')).getText()).toMatch(/Content of the template/); }); - </doc:scenario> + </doc:protractor> </doc:example> */ var scriptDirective = ['$templateCache', function($templateCache) { diff --git a/src/ng/directive/select.js b/src/ng/directive/select.js index 0e64cc43..c4498f81 100644 --- a/src/ng/directive/select.js +++ b/src/ng/directive/select.js @@ -120,15 +120,17 @@ var ngOptionsMinErr = minErr('ngOptions'); </div> </div> </doc:source> - <doc:scenario> + <doc:protractor> it('should check ng-options', function() { - expect(binding('{selected_color:color}')).toMatch('red'); - select('color').option('0'); - expect(binding('{selected_color:color}')).toMatch('black'); - using('.nullable').select('color').option(''); - expect(binding('{selected_color:color}')).toMatch('null'); + expect(element(by.binding('{selected_color:color}')).getText()).toMatch('red'); + element.all(by.select('color')).first().click(); + element.all(by.css('select[ng-model="color"] option')).first().click(); + expect(element(by.binding('{selected_color:color}')).getText()).toMatch('black'); + element(by.css('.nullable select[ng-model="color"]')).click(); + element.all(by.css('.nullable select[ng-model="color"] option')).first().click(); + expect(element(by.binding('{selected_color:color}')).getText()).toMatch('null'); }); - </doc:scenario> + </doc:protractor> </doc:example> */ diff --git a/src/ng/filter/filter.js b/src/ng/filter/filter.js index e328d61a..7720bb13 100644 --- a/src/ng/filter/filter.js +++ b/src/ng/filter/filter.js @@ -70,35 +70,47 @@ Equality <input type="checkbox" ng-model="strict"><br> <table id="searchObjResults"> <tr><th>Name</th><th>Phone</th></tr> - <tr ng-repeat="friend in friends | filter:search:strict"> - <td>{{friend.name}}</td> - <td>{{friend.phone}}</td> + <tr ng-repeat="friendObj in friends | filter:search:strict"> + <td>{{friendObj.name}}</td> + <td>{{friendObj.phone}}</td> </tr> </table> </doc:source> - <doc:scenario> + <doc:protractor> + var expectFriendNames = function(expectedNames, key) { + element.all(by.repeater(key + ' in friends').column(key + '.name')).then(function(arr) { + arr.forEach(function(wd, i) { + expect(wd.getText()).toMatch(expectedNames[i]); + }); + }); + }; + it('should search across all fields when filtering with a string', function() { - input('searchText').enter('m'); - expect(repeater('#searchTextResults tr', 'friend in friends').column('friend.name')). - toEqual(['Mary', 'Mike', 'Adam']); + var searchText = element(by.model('searchText')); + searchText.clear(); + searchText.sendKeys('m'); + expectFriendNames(['Mary', 'Mike', 'Adam'], 'friend'); - input('searchText').enter('76'); - expect(repeater('#searchTextResults tr', 'friend in friends').column('friend.name')). - toEqual(['John', 'Julie']); + searchText.clear(); + searchText.sendKeys('76'); + expectFriendNames(['John', 'Julie'], 'friend'); }); it('should search in specific fields when filtering with a predicate object', function() { - input('search.$').enter('i'); - expect(repeater('#searchObjResults tr', 'friend in friends').column('friend.name')). - toEqual(['Mary', 'Mike', 'Julie', 'Juliette']); + var searchAny = element(by.model('search.$')); + searchAny.clear(); + searchAny.sendKeys('i'); + expectFriendNames(['Mary', 'Mike', 'Julie', 'Juliette'], 'friendObj'); }); it('should use a equal comparison when comparator is true', function() { - input('search.name').enter('Julie'); - input('strict').check(); - expect(repeater('#searchObjResults tr', 'friend in friends').column('friend.name')). - toEqual(['Julie']); + var searchName = element(by.model('search.name')); + var strict = element(by.model('strict')); + searchName.clear(); + searchName.sendKeys('Julie'); + strict.click(); + expectFriendNames(['Julie'], 'friendObj'); }); - </doc:scenario> + </doc:protractor> </doc:example> */ function filterFilter() { diff --git a/src/ng/filter/filters.js b/src/ng/filter/filters.js index c92ed384..63ea270c 100644 --- a/src/ng/filter/filters.js +++ b/src/ng/filter/filters.js @@ -24,21 +24,22 @@ </script> <div ng-controller="Ctrl"> <input type="number" ng-model="amount"> <br> - default currency symbol ($): {{amount | currency}}<br> - custom currency identifier (USD$): {{amount | currency:"USD$"}} + default currency symbol ($): <span id="currency-default">{{amount | currency}}</span><br> + custom currency identifier (USD$): <span>{{amount | currency:"USD$"}}</span> </div> </doc:source> - <doc:scenario> + <doc:protractor> it('should init with 1234.56', function() { - expect(binding('amount | currency')).toBe('$1,234.56'); - expect(binding('amount | currency:"USD$"')).toBe('USD$1,234.56'); + expect(element(by.id('currency-default')).getText()).toBe('$1,234.56'); + expect(element(by.binding('amount | currency:"USD$"')).getText()).toBe('USD$1,234.56'); }); it('should update', function() { - input('amount').enter('-1234'); - expect(binding('amount | currency')).toBe('($1,234.00)'); - expect(binding('amount | currency:"USD$"')).toBe('(USD$1,234.00)'); + element(by.model('amount')).clear(); + element(by.model('amount')).sendKeys('-1234'); + expect(element(by.id('currency-default')).getText()).toBe('($1,234.00)'); + expect(element(by.binding('amount | currency:"USD$"')).getText()).toBe('(USD$1,234.00)'); }); - </doc:scenario> + </doc:protractor> </doc:example> */ currencyFilter.$inject = ['$locale']; @@ -77,25 +78,26 @@ function currencyFilter($locale) { </script> <div ng-controller="Ctrl"> Enter number: <input ng-model='val'><br> - Default formatting: {{val | number}}<br> - No fractions: {{val | number:0}}<br> - Negative number: {{-val | number:4}} + Default formatting: <span id='number-default'>{{val | number}}</span><br> + No fractions: <span>{{val | number:0}}</span><br> + Negative number: <span>{{-val | number:4}}</span> </div> </doc:source> - <doc:scenario> + <doc:protractor> it('should format numbers', function() { - expect(binding('val | number')).toBe('1,234.568'); - expect(binding('val | number:0')).toBe('1,235'); - expect(binding('-val | number:4')).toBe('-1,234.5679'); + expect(element(by.id('number-default')).getText()).toBe('1,234.568'); + expect(element(by.binding('val | number:0')).getText()).toBe('1,235'); + expect(element(by.binding('-val | number:4')).getText()).toBe('-1,234.5679'); }); it('should update', function() { - input('val').enter('3374.333'); - expect(binding('val | number')).toBe('3,374.333'); - expect(binding('val | number:0')).toBe('3,374'); - expect(binding('-val | number:4')).toBe('-3,374.3330'); - }); - </doc:scenario> + element(by.model('val')).clear(); + element(by.model('val')).sendKeys('3374.333'); + expect(element(by.id('number-default')).getText()).toBe('3,374.333'); + expect(element(by.binding('val | number:0')).getText()).toBe('3,374'); + expect(element(by.binding('-val | number:4')).getText()).toBe('-3,374.3330'); + }); + </doc:protractor> </doc:example> */ @@ -325,22 +327,22 @@ var DATE_FORMATS_SPLIT = /((?:[^yMdHhmsaZE']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|d+ <doc:example> <doc:source> <span ng-non-bindable>{{1288323623006 | date:'medium'}}</span>: - {{1288323623006 | date:'medium'}}<br> + <span>{{1288323623006 | date:'medium'}}</span><br> <span ng-non-bindable>{{1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'}}</span>: - {{1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'}}<br> + <span>{{1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'}}</span><br> <span ng-non-bindable>{{1288323623006 | date:'MM/dd/yyyy @ h:mma'}}</span>: - {{'1288323623006' | date:'MM/dd/yyyy @ h:mma'}}<br> + <span>{{'1288323623006' | date:'MM/dd/yyyy @ h:mma'}}</span><br> </doc:source> - <doc:scenario> + <doc:protractor> it('should format date', function() { - expect(binding("1288323623006 | date:'medium'")). + expect(element(by.binding("1288323623006 | date:'medium'")).getText()). toMatch(/Oct 2\d, 2010 \d{1,2}:\d{2}:\d{2} (AM|PM)/); - expect(binding("1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'")). + expect(element(by.binding("1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'")).getText()). toMatch(/2010\-10\-2\d \d{2}:\d{2}:\d{2} (\-|\+)?\d{4}/); - expect(binding("'1288323623006' | date:'MM/dd/yyyy @ h:mma'")). + expect(element(by.binding("'1288323623006' | date:'MM/dd/yyyy @ h:mma'")).getText()). toMatch(/10\/2\d\/2010 @ \d{1,2}:\d{2}(AM|PM)/); }); - </doc:scenario> + </doc:protractor> </doc:example> */ dateFilter.$inject = ['$locale']; @@ -439,11 +441,11 @@ function dateFilter($locale) { <doc:source> <pre>{{ {'name':'value'} | json }}</pre> </doc:source> - <doc:scenario> + <doc:protractor> it('should jsonify filtered objects', function() { - expect(binding("{'name':'value'}")).toMatch(/\{\n "name": ?"value"\n}/); + expect(element(by.binding("{'name':'value'}")).getText()).toMatch(/\{\n "name": ?"value"\n}/); }); - </doc:scenario> + </doc:protractor> </doc:example> * */ diff --git a/src/ng/filter/limitTo.js b/src/ng/filter/limitTo.js index 07ce675d..bb1756f2 100644 --- a/src/ng/filter/limitTo.js +++ b/src/ng/filter/limitTo.js @@ -36,28 +36,37 @@ <p>Output letters: {{ letters | limitTo:letterLimit }}</p> </div> </doc:source> - <doc:scenario> + <doc:protractor> + var numLimitInput = element(by.model('numLimit')); + var letterLimitInput = element(by.model('letterLimit')); + var limitedNumbers = element(by.binding('numbers | limitTo:numLimit')); + var limitedLetters = element(by.binding('letters | limitTo:letterLimit')); + it('should limit the number array to first three items', function() { - expect(element('.doc-example-live input[ng-model=numLimit]').val()).toBe('3'); - expect(element('.doc-example-live input[ng-model=letterLimit]').val()).toBe('3'); - expect(binding('numbers | limitTo:numLimit')).toEqual('[1,2,3]'); - expect(binding('letters | limitTo:letterLimit')).toEqual('abc'); + expect(numLimitInput.getAttribute('value')).toBe('3'); + expect(letterLimitInput.getAttribute('value')).toBe('3'); + expect(limitedNumbers.getText()).toEqual('Output numbers: [1,2,3]'); + expect(limitedLetters.getText()).toEqual('Output letters: abc'); }); it('should update the output when -3 is entered', function() { - input('numLimit').enter(-3); - input('letterLimit').enter(-3); - expect(binding('numbers | limitTo:numLimit')).toEqual('[7,8,9]'); - expect(binding('letters | limitTo:letterLimit')).toEqual('ghi'); + numLimitInput.clear(); + numLimitInput.sendKeys('-3'); + letterLimitInput.clear(); + letterLimitInput.sendKeys('-3'); + expect(limitedNumbers.getText()).toEqual('Output numbers: [7,8,9]'); + expect(limitedLetters.getText()).toEqual('Output letters: ghi'); }); it('should not exceed the maximum size of input array', function() { - input('numLimit').enter(100); - input('letterLimit').enter(100); - expect(binding('numbers | limitTo:numLimit')).toEqual('[1,2,3,4,5,6,7,8,9]'); - expect(binding('letters | limitTo:letterLimit')).toEqual('abcdefghi'); + numLimitInput.clear(); + numLimitInput.sendKeys('100'); + letterLimitInput.clear(); + letterLimitInput.sendKeys('100'); + expect(limitedNumbers.getText()).toEqual('Output numbers: [1,2,3,4,5,6,7,8,9]'); + expect(limitedLetters.getText()).toEqual('Output letters: abcdefghi'); }); - </doc:scenario> + </doc:protractor> </doc:example> */ function limitToFilter(){ diff --git a/src/ng/filter/orderBy.js b/src/ng/filter/orderBy.js index 961faa36..4127f902 100644 --- a/src/ng/filter/orderBy.js +++ b/src/ng/filter/orderBy.js @@ -58,29 +58,6 @@ </table> </div> </doc:source> - <doc:scenario> - it('should be reverse ordered by aged', function() { - expect(binding('predicate')).toBe('-age'); - expect(repeater('table.friend', 'friend in friends').column('friend.age')). - toEqual(['35', '29', '21', '19', '10']); - expect(repeater('table.friend', 'friend in friends').column('friend.name')). - toEqual(['Adam', 'Julie', 'Mike', 'Mary', 'John']); - }); - - it('should reorder the table when user selects different predicate', function() { - element('.doc-example-live a:contains("Name")').click(); - expect(repeater('table.friend', 'friend in friends').column('friend.name')). - toEqual(['Adam', 'John', 'Julie', 'Mary', 'Mike']); - expect(repeater('table.friend', 'friend in friends').column('friend.age')). - toEqual(['35', '10', '29', '19', '21']); - - element('.doc-example-live a:contains("Phone")').click(); - expect(repeater('table.friend', 'friend in friends').column('friend.phone')). - toEqual(['555-9876', '555-8765', '555-5678', '555-4321', '555-1212']); - expect(repeater('table.friend', 'friend in friends').column('friend.name')). - toEqual(['Mary', 'Julie', 'Adam', 'Mike', 'John']); - }); - </doc:scenario> </doc:example> */ orderByFilter.$inject = ['$parse']; diff --git a/src/ng/http.js b/src/ng/http.js index f20d54fd..57dc7172 100644 --- a/src/ng/http.js +++ b/src/ng/http.js @@ -587,14 +587,14 @@ function $HttpProvider() { <option>JSONP</option> </select> <input type="text" ng-model="url" size="80"/> - <button ng-click="fetch()">fetch</button><br> - <button ng-click="updateModel('GET', 'http-hello.html')">Sample GET</button> - <button + <button id="fetchbtn" ng-click="fetch()">fetch</button><br> + <button id="samplegetbtn" ng-click="updateModel('GET', 'http-hello.html')">Sample GET</button> + <button id="samplejsonpbtn" ng-click="updateModel('JSONP', 'http://angularjs.org/greet.php?callback=JSON_CALLBACK&name=Super%20Hero')"> Sample JSONP </button> - <button + <button id="invalidjsonpbtn" ng-click="updateModel('JSONP', 'http://angularjs.org/doesntexist&callback=JSON_CALLBACK')"> Invalid JSONP </button> @@ -631,27 +631,34 @@ function $HttpProvider() { <file name="http-hello.html"> Hello, $http! </file> -<file name="scenario.js"> +<file name="protractorTest.js"> + var status = element(by.binding('status')); + var data = element(by.binding('data')); + var fetchBtn = element(by.id('fetchbtn')); + var sampleGetBtn = element(by.id('samplegetbtn')); + var sampleJsonpBtn = element(by.id('samplejsonpbtn')); + var invalidJsonpBtn = element(by.id('invalidjsonpbtn')); + it('should make an xhr GET request', function() { - element(':button:contains("Sample GET")').click(); - element(':button:contains("fetch")').click(); - expect(binding('status')).toBe('200'); - expect(binding('data')).toMatch(/Hello, \$http!/); + sampleGetBtn.click(); + fetchBtn.click(); + expect(status.getText()).toMatch('200'); + expect(data.getText()).toMatch(/Hello, \$http!/) }); it('should make a JSONP request to angularjs.org', function() { - element(':button:contains("Sample JSONP")').click(); - element(':button:contains("fetch")').click(); - expect(binding('status')).toBe('200'); - expect(binding('data')).toMatch(/Super Hero!/); + sampleJsonpBtn.click(); + fetchBtn.click(); + expect(status.getText()).toMatch('200'); + expect(data.getText()).toMatch(/Super Hero!/); }); it('should make JSONP request to invalid URL and invoke the error handler', function() { - element(':button:contains("Invalid JSONP")').click(); - element(':button:contains("fetch")').click(); - expect(binding('status')).toBe('0'); - expect(binding('data')).toBe('Request failed'); + invalidJsonpBtn.click(); + fetchBtn.click(); + expect(status.getText()).toMatch('0'); + expect(data.getText()).toMatch('Request failed'); }); </file> </example> diff --git a/src/ng/interpolate.js b/src/ng/interpolate.js index b78f44a4..1a7e50ad 100644 --- a/src/ng/interpolate.js +++ b/src/ng/interpolate.js @@ -31,11 +31,11 @@ var $interpolateMinErr = minErr('$interpolate'); //demo.label// </div> </doc:source> -<doc:scenario> - it('should interpolate binding with custom symbols', function() { - expect(binding('demo.label')).toBe('This binding is brought you by // interpolation symbols.'); - }); -</doc:scenario> +<doc:protractor> + it('should interpolate binding with custom symbols', function() { + expect(element(by.binding('demo.label')).getText()).toBe('This binding is brought you by // interpolation symbols.'); + }); +</doc:protractor> </doc:example> */ function $InterpolateProvider() { diff --git a/src/ng/sce.js b/src/ng/sce.js index 321921f5..a7d616a5 100644 --- a/src/ng/sce.js +++ b/src/ng/sce.js @@ -624,13 +624,15 @@ function $SceDelegateProvider() { ] </file> -<file name="scenario.js"> +<file name="protractorTest.js"> describe('SCE doc demo', function() { it('should sanitize untrusted values', function() { - expect(element('.htmlComment').html()).toBe('<span>Is <i>anyone</i> reading this?</span>'); + expect(element(by.css('.htmlComment')).getInnerHtml()) + .toBe('<span>Is <i>anyone</i> reading this?</span>'); }); + it('should NOT sanitize explicitly trusted values', function() { - expect(element('#explicitlyTrustedHtml').html()).toBe( + expect(element(by.id('explicitlyTrustedHtml')).getInnerHtml()).toBe( '<span onmouseover="this.textContent="Explicitly trusted HTML bypasses ' + 'sanitization."">Hover over this text.</span>'); }); diff --git a/src/ng/window.js b/src/ng/window.js index 7702f29f..4f0717af 100644 --- a/src/ng/window.js +++ b/src/ng/window.js @@ -31,13 +31,13 @@ <button ng-click="doGreeting(greeting)">ALERT</button> </div> </doc:source> - <doc:scenario> + <doc:protractor> it('should display the greeting in the input box', function() { - input('greeting').enter('Hello, E2E Tests'); + element(by.model('greeting')).sendKeys('Hello, E2E Tests'); // If we click the button it will block the test runner // element(':button').click(); }); - </doc:scenario> + </doc:protractor> </doc:example> */ function $WindowProvider(){ |
