Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
fix(protractor): Added an interaction to Hover.over(target), correcte…
…d the DoubleClick interaction s
- Loading branch information
Showing
with
153 additions
and 8 deletions.
- +58 −4 packages/protractor/spec/screenplay/interactions/Clear.spec.ts
- +49 −0 packages/protractor/spec/screenplay/interactions/Hover.spec.ts
- +12 −2 packages/protractor/src/screenplay/interactions/Clear.ts
- +8 −2 packages/protractor/src/screenplay/interactions/DoubleClick.ts
- +25 −0 packages/protractor/src/screenplay/interactions/Hover.ts
- +1 −0 packages/protractor/src/screenplay/interactions/index.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,49 @@ | ||
import { expect, stage } from '@integration/testing-tools'; | ||
import { Ensure, equals } from '@serenity-js/assertions'; | ||
import { by } from 'protractor'; | ||
|
||
import { Attribute, Hover, Navigate, Target } from '../../../src'; | ||
import { pageFromTemplate } from '../../fixtures'; | ||
import { UIActors } from '../../UIActors'; | ||
|
||
describe('Hover', function () { | ||
|
||
const Mickey = stage(new UIActors()).actor('Mickey'); | ||
|
||
const pageWithALink = pageFromTemplate(` | ||
<html> | ||
<body style="margin:0; padding:0 0 1024px 0;"> | ||
<h1>A page with a link</h1> | ||
<a href="javascript:void(0)" | ||
class="off" | ||
onmouseover="this.className='on';" onmouseout="this.className='off';"> | ||
>link</a> | ||
</body> | ||
</html> | ||
`); | ||
|
||
const Page = { | ||
Header: Target.the('header').located(by.css('h1')), | ||
Link: Target.the('link').located(by.css('a')), | ||
}; | ||
|
||
/** @test {Scroll} */ | ||
/** @test {Scroll.to} */ | ||
it('allows the actor to move the mouse to a given target', () => Mickey.attemptsTo( | ||
Navigate.to(pageWithALink), | ||
|
||
Ensure.that(Attribute.of(Page.Link).called('class'), equals('off')), | ||
|
||
Hover.over(Page.Link), | ||
Ensure.that(Attribute.of(Page.Link).called('class'), equals('on')), | ||
|
||
Hover.over(Page.Header), | ||
Ensure.that(Attribute.of(Page.Link).called('class'), equals('off')), | ||
)); | ||
|
||
/** @test {Enter#toString} */ | ||
it('provides a sensible description of the interaction being performed', () => { | ||
expect(Hover.over(Page.Link).toString()) | ||
.to.equal(`#actor hovers the mouse over the link`); | ||
}); | ||
}); |
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
@@ -0,0 +1,25 @@ | ||
import { AnswersQuestions, Interaction, Question, UsesAbilities } from '@serenity-js/core'; | ||
import { formatted } from '@serenity-js/core/lib/io'; | ||
import { ElementFinder } from 'protractor'; | ||
import { BrowseTheWeb } from '../abilities'; | ||
import { withAnswerOf } from '../withAnswerOf'; | ||
|
||
export class Hover extends Interaction { | ||
static over(target: Question<ElementFinder> | ElementFinder) { | ||
return new Hover(target); | ||
} | ||
|
||
constructor( | ||
private readonly target: Question<ElementFinder> | ElementFinder, | ||
) { | ||
super(); | ||
} | ||
|
||
performAs(actor: UsesAbilities & AnswersQuestions): PromiseLike<void> { | ||
return withAnswerOf(actor, this.target, elf => BrowseTheWeb.as(actor).actions().mouseMove(elf).perform()); | ||
} | ||
|
||
toString(): string { | ||
return formatted `#actor hovers the mouse over ${this.target}`; | ||
} | ||
} |
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