-
-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(protractor): expectation to check if an element isActive()
- Loading branch information
Showing
3 changed files
with
80 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import 'mocha'; | ||
|
||
import { expect } from '@integration/testing-tools'; | ||
import { Ensure, not } from '@serenity-js/assertions'; | ||
import { actorCalled, AssertionError } from '@serenity-js/core'; | ||
import { by } from 'protractor'; | ||
|
||
import { Click, isActive, Navigate, Target, Wait } from '../../src'; | ||
import { pageFromTemplate } from '../fixtures'; | ||
|
||
describe('isActive', function () { | ||
|
||
const Page = { | ||
Active_Input: Target.the('active input').located(by.id('active')), | ||
Inactive_Input: Target.the('inactive input').located(by.id('inactive')), | ||
}; | ||
|
||
beforeEach(() => actorCalled('Bernie').attemptsTo( | ||
Navigate.to(pageFromTemplate(` | ||
<html> | ||
<body> | ||
<input type="text" id="active" /> | ||
<input type="text" id="inactive" /> | ||
</body> | ||
</html> | ||
`)), | ||
)); | ||
|
||
/** @test {isActive} */ | ||
it('allows the actor flow to continue when the element is active', () => expect(actorCalled('Bernie').attemptsTo( | ||
Wait.until(Page.Active_Input, not(isActive())), | ||
Ensure.that(Page.Active_Input, not(isActive())), | ||
Click.on(Page.Active_Input), | ||
Wait.until(Page.Active_Input, isActive()), | ||
Ensure.that(Page.Active_Input, isActive()), | ||
)).to.be.fulfilled); | ||
|
||
/** @test {isActive} */ | ||
it('breaks the actor flow when element is inactive', () => { | ||
return expect(actorCalled('Bernie').attemptsTo( | ||
Ensure.that(Page.Inactive_Input, isActive()), | ||
)).to.be.rejectedWith(AssertionError, `Expected the inactive input to become active`); | ||
}); | ||
|
||
/** @test {isActive} */ | ||
it('contributes to a human-readable description of an assertion', () => { | ||
expect(Ensure.that(Page.Active_Input, isActive()).toString()) | ||
.to.equal(`#actor ensures that the active input does become active`); | ||
}); | ||
|
||
/** @test {isActive} */ | ||
it('contributes to a human-readable description of a wait', () => { | ||
expect(Wait.until(Page.Active_Input, isActive()).toString()) | ||
.to.equal(`#actor waits up to 5s until the active input does become active`); | ||
}); | ||
}); |
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,23 @@ | ||
import { Expectation } from '@serenity-js/assertions'; | ||
import { ElementFinder, WebElement } from 'protractor'; | ||
import { ElementFinderExpectation } from './ElementFinderExpectation'; | ||
|
||
/** | ||
* @desc | ||
* Expectation that the element is active. | ||
* | ||
* @returns {Expectation<boolean, ElementFinder>} | ||
* | ||
* @see {@link @serenity-js/assertions~Ensure} | ||
* @see {@link @serenity-js/assertions~Check} | ||
* @see {@link Wait} | ||
*/ | ||
export function isActive(): Expectation<boolean, ElementFinder> { | ||
return ElementFinderExpectation.forElementTo('become active', (actual: ElementFinder) => | ||
actual.getWebElement().then(element => | ||
element.getDriver().switchTo().activeElement().then((active: WebElement) => | ||
actual.equals(active), | ||
), | ||
), | ||
); | ||
} |