Skip to content

Instantly share code, notes, and snippets.

@flucivja
Created September 23, 2020 17:28
Show Gist options
  • Save flucivja/e73abff27ed3b042668f5e6b46ed5b54 to your computer and use it in GitHub Desktop.
Save flucivja/e73abff27ed3b042668f5e6b46ed5b54 to your computer and use it in GitHub Desktop.
// test file
import { given } from 'cypress-bdd';
import { TwitterPage } from './TwitterPage';
describe("Some test suite", () => {
it("some test", () => {
given(TwitterPage, twitterPage => twitterPage.open())
.when(twitterPage =>
twitterPage
.tweetNewMessage("some message")
.then.refreshTweets()
)
.then(twitterPage =>
twitterPage.getComponent().$tweets.should("contain", "some message"));
});
});
// Page objects looks like this:
// file TweetDialog.ts
import { FindBy, BaseComponent, CypressElement } from 'cypress-bdd';
class TweetDialog extends BaseComponent {
@FindBy(".input")
$textInput!: CypressElement;
@FindBy(".btn")
$submitBtn!: CypressElement;
fillInput(text: string) {
this.$textInput.type(text);
}
submit() {
this.$submitBtn.click();
}
}
// file TwitterPage.ts
import { FindBy, BasePage, Component, CypressElement } from 'cypress-bdd';
import { TweetDialog } from './TweetDialog';
class TwitterPage extends BasePage {
url = "twitter.com";
@FindBy(".new-tweet-btn")
$newTweetBtn!: CypressElement;
@FindBy(".refresh-btn")
$refreshTweetsBtn!: CypressElement;
@FindBy(".tweets")
$tweets!: CypressElement;
@Component(TweetDialog)
tweetDialogComponent!: TweetDialog;
tweetNewMessage = action(this, (message: string) => {
this.tweetDialogComponent.fillInput(message);
this.tweetDialogComponent.submit();
});
refreshTweets = action(this, () => {
this.$refreshTweetsBtn.click();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment