Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
with
235 additions
and 23 deletions.
- +11 −11 packages/protractor/spec/screenplay/interactions/Press.spec.ts
- +144 −0 packages/protractor/spec/screenplay/questions/Target.spec.ts
- +2 −2 packages/protractor/spec/screenplay/questions/Text.spec.ts
- +1 −1 packages/protractor/spec/screenplay/questions/Value.spec.ts
- +2 −2 packages/protractor/src/screenplay/interactions/Press.ts
- +75 −7 packages/protractor/src/screenplay/questions/Target.ts
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
@@ -0,0 +1,144 @@ | ||
import { expect } from '@integration/testing-tools'; | ||
import { contains, Ensure, equals } from '@serenity-js/assertions'; | ||
import { Actor } from '@serenity-js/core'; | ||
import { by, protractor } from 'protractor'; | ||
import { BrowseTheWeb, Navigate, Target, Text } from '../../../src'; | ||
import { pageFromTemplate } from '../../fixtures'; | ||
|
||
/** @target {Target} */ | ||
describe('Target', () => { | ||
|
||
const shoppingListPage = pageFromTemplate(` | ||
<html> | ||
<body> | ||
<div id="shopping-list-app"> | ||
<h1>Shopping <span>list</span></h1> | ||
<h2 class="progress"><span>2</span> out of 3</h2> | ||
<ul> | ||
<li class="buy">oats</li> | ||
<li class="buy">coconut milk</li> | ||
<li class="bought">coffee</li> | ||
</ul> | ||
</div> | ||
</body> | ||
</html> | ||
`); | ||
|
||
class ShoppingList { | ||
static App = Target.the('shopping list app').located(by.id('shopping-list-app')); | ||
static Progress = Target.the('progress bar').in(ShoppingList.App).located(by.css('.progress')); | ||
static Number_Of_Items_Left = Target.the('number of items left').in(ShoppingList.Progress).located(by.css('span')); | ||
|
||
static Header = Target.the('header').located(by.tagName('h1')); | ||
static List = Target.the('shopping list').located(by.tagName('ul')); | ||
static Items = Target.all('items').in(ShoppingList.App).located(by.tagName('li')); | ||
static Bought_Items = Target.all('bought items').in(ShoppingList.List).located(by.css('.bought')); | ||
} | ||
|
||
const Bernie = Actor.named('Bernie').whoCan( | ||
BrowseTheWeb.using(protractor.browser), | ||
); | ||
|
||
describe('allows the actor to locate', () => { | ||
|
||
it('a single web element matching the selector', () => Bernie.attemptsTo( | ||
Navigate.to(shoppingListPage), | ||
|
||
Ensure.that(Text.of(ShoppingList.Header), equals('Shopping list')), | ||
)); | ||
|
||
it('all web elements matching the selector', () => Bernie.attemptsTo( | ||
Navigate.to(shoppingListPage), | ||
|
||
Ensure.that(Text.ofAll(ShoppingList.Items), contains('oats')), | ||
)); | ||
|
||
it('an element relative to another target', () => Bernie.attemptsTo( | ||
Navigate.to(shoppingListPage), | ||
|
||
Ensure.that(Text.of(ShoppingList.Number_Of_Items_Left), equals('2')), | ||
)); | ||
|
||
it('all elements relative to another target', () => Bernie.attemptsTo( | ||
Navigate.to(shoppingListPage), | ||
|
||
Ensure.that(Text.ofAll(ShoppingList.Bought_Items), equals(['coffee'])), | ||
)); | ||
}); | ||
|
||
describe('provides a sensible description of', () => { | ||
describe('an element that', () => { | ||
|
||
it('is being targeted', () => { | ||
expect(ShoppingList.Header.toString()) | ||
.to.equal('the header'); | ||
}); | ||
|
||
it('has been located', () => { | ||
expect(ShoppingList.Header.answeredBy(Bernie).toString()) | ||
.to.equal('the header'); | ||
}); | ||
|
||
it('is nested', () => { | ||
expect(ShoppingList.Number_Of_Items_Left.answeredBy(Bernie).toString()) | ||
.to.equal('the number of items left in the progress bar in the shopping list app'); | ||
}); | ||
}); | ||
|
||
describe('elements that', () => { | ||
|
||
it('are being targeted', () => { | ||
expect(ShoppingList.Items.toString()) | ||
.to.equal('all the items in the shopping list app'); | ||
}); | ||
|
||
it('have been located', () => { | ||
expect(ShoppingList.Items.answeredBy(Bernie).toString()) | ||
.to.equal('all the items in the shopping list app'); | ||
}); | ||
|
||
it('are nested', () => { | ||
expect(ShoppingList.Bought_Items.answeredBy(Bernie).toString()) | ||
.to.equal('all the bought items in the shopping list'); | ||
}); | ||
}); | ||
}); | ||
|
||
// it('allows the actor to locate first web elements matching the selector', () => Bernie.attemptsTo( | ||
// Navigate.to(shoppingListPage), | ||
// | ||
// Ensure.that(Text.of(First.of(ShoppingList.Items)), contains('oats')), | ||
// )); | ||
|
||
// it('allows the actor to locate first web elements matching the selector and expectation', () => Bernie.attemptsTo( | ||
// Navigate.to(shoppingListPage), | ||
// | ||
// Ensure.that(Text.of(First.of(ShoppingList.Items).that(in)), contains('oats')), | ||
// )); | ||
|
||
/* | ||
Click.on(First.of(ShoppingList.Items)) | ||
Click.on(First.of(ShoppingList.Items).that(matches(/milk/))) | ||
Click.on(Last.of(ShoppingList.Items)) | ||
Click.on(Last.of(ShoppingList.Items).that(matches(/milk/))) | ||
Click.on( | ||
First.of( | ||
Those.of(ShoppingList.Items).whereEach(matches(/milk/)) | ||
).that(hasClassThat(matches(/bargain/)) | ||
) | ||
Ensure.that( | ||
Text.ofAll( | ||
Those.of(ShoppingList.Items).whereEach(matches(/milk/)) | ||
), | ||
includes('coconut milk') | ||
) | ||
*/ | ||
|
||
// it(`produces a sensible description of the question being asked`, () => { | ||
// expect(Text.of(Target.the('header').located(by.tagName('h1'))).toString()) | ||
// .to.equal('the text of the header'); | ||
// }); | ||
}); |
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