Created
September 23, 2020 17:28
-
-
Save flucivja/e73abff27ed3b042668f5e6b46ed5b54 to your computer and use it in GitHub Desktop.
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
// 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