upgrading serenity/JS 2.0 + protractor to serenity/JS 3.0 + webdriverIO #2394
-
@jan-molak here is pervious code where I am using protractor import { Wait } from '@serenity-js/protractor';
import { by, element } from 'protractor';
describe(' process', () => {
it('actor checks the future step', () =>
element.all(by.css('.page-steps__step--future')).first().getText().then(function (text) {
if (text.indexOf('Extras') > -1) {
futureStep = 'Extras';
console.log('Future step set to {0}', futureStep);
}
}));
it('actor goes to extras screen', () => {
if (futureStep !== 'Extras') {
return;
}
actorCalled('Jasmine').attemptsTo(
Wait.for(Duration.ofSeconds(20)),
ContinueToExtras());
});
it('actor waits for the extras to appear', () => {
if (futureStep !== 'Extras') {
return;
}
actorCalled('Jasmine').attemptsTo(
WaitForExtrasToAppear());
});
}); how can I rewrite the logic using latest version of Serenity/JS 3 it('actor checks the future step', () =>
element.all(by.css('.page-steps__step--future')).first().getText().then(function (text) {
if (text.indexOf('Extras') > -1) {
futureStep = 'Extras';
console.log('Future step set to {0}', futureStep);
}
})); in Serenity/JS 3 getText().then not available |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
OK, there's quite a few things that could be improved in this snippet:
To answer your immediate question, though, let's look at what the old Protractor code was doing: describe('My feature', () = > {
let futureStep;
// ...
await element.all(by.css('.page-steps__step--future'))
.first()
.getText()
.then(function (text) {
if (text.indexOf('Extras') > -1) {
futureStep = 'Extras';
}
})
// ...
}) First, you'll need to identify the page elements of interest (You can learn more about it in my article on the Page Element Query Language): import { PageElements, By } from '@serenity-js/web'
const steps = () =>
PageElements.located(By.css('.page-steps__step--future'))
.describedAs('steps') Next, I'm guessing that you'd want a condition that should the import { actorCalled, Check } from '@serenity-js/core'
import { contain } from '@serenity-js/assertions'
describe('my feature', () => {
it('some scenario scenario', async () => {
await actorCalled('Jasmine').attemptsTo(
Check.whether(Text.ofAll(steps()), contain('Extras'))
.andIfSo(
//...
)
)
});
}); |
Beta Was this translation helpful? Give feedback.
OK, there's quite a few things that could be improved in this snippet:
futureStep
variable; Instead, consider using abeforeAll
orbeforeEach
hooksWait.until
actor.attemptsTo
returns aPromise
. You'll need to useasync/await
or return thePromise
to Jasmine to ensure your test runner is correctly synchronised with your scenario.To answer your immediate question, though, let's look at what the old Protractor code was doing: