forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 1
RNTester - e2e cucumber new approach #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
adzironman
merged 9 commits into
feature/rn-e2e-cucumber
from
rn-e2e-cucumber-new-approach
Jan 12, 2023
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f52dbfe
Updating readme files
adiorsz 1d6c99b
Updating android config
adiorsz f9cce01
Adding common steps file
adiorsz f2ef916
Removing unnecessary files
adiorsz 2789ed0
Updating cucumber tests
adiorsz 3ebe200
github-actions fixes
adiorsz de05312
removing commented lines
adiorsz 97d6045
Removing some user specific values
adiorsz be4415d
Updating typos in readme
adiorsz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -2,9 +2,9 @@ | |
|
|
||
| 1. Create a feature file `(rn-tester-e2e/test/features)` - GivenWhenThen Gherkin syntax | ||
| 2. **OPTIONAL -** Create a screen object or extend the existing one (depends on the test scope) - `rn-tester-e2e/test/screenObjects` - map screen elements for iOS and Android | ||
| 3. Create a step file `(rn-tester-e2e/test/steps)` - import used screen objects, create execution code of GivenWhenThen steps from feature file | ||
| 4. Create a runner file `(rn-tester-e2e/test/runners)` - import steps from step3 and create test scenarios | ||
| 5. Update `(rn-tester-e2e/e2e-config.js)` with proper cababilities of your emulator | ||
| 3. **OPTIONAL -** Add another common step in `rn-tester-e2e/test/common_steps/common.steps.js` | ||
| 4. Create a runner file `(rn-tester-e2e/test/runners)` - import steps and screen objects from point 2 and 3. Create test scenarios | ||
| 5. Update `(rn-tester-e2e/e2e-config.js)` with proper capabilities of your emulator | ||
|
|
||
| # How to execute a test | ||
| 1. Open new Terminal -> navigate to the react-native path -> open Metro by typing | ||
|
|
@@ -16,7 +16,14 @@ or | |
|
|
||
|
|
||
| 2. Open second terminal -> navigate to the react-native/packages/rn-tester-e2e -> MAKE SURE YOUR APPIUM HAS UIAUTOMATOR2 AND XCUITEST INSTALLED! type | ||
| >npm install [email protected] -g | ||
|
|
||
| >appium driver install uiautomator2 | ||
|
|
||
| >appium driver install xcuitest | ||
|
|
||
| >appium --base-path /wd/hub | ||
|
|
||
| 3. Open third terminal -> navigate to the react-native/packages/rn-tester-e2e -> run all tests by typing | ||
| >npm run ios | ||
|
|
||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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,14 @@ | ||
| import { driver } from '../../jest.setup.js'; | ||
|
|
||
| // Common steps reusable between different features | ||
| export const userIsOnMainScreen = (given) => { | ||
| given('User is on the main screen', async () => { | ||
| await driver.pause(2000); | ||
| }); | ||
| }; | ||
|
|
||
| export const clickOkButton = (given) => { | ||
| given('User clicks on the OK button', async () => { | ||
| await driver.pause(2000); | ||
| }); | ||
| }; |
7 changes: 0 additions & 7 deletions
7
packages/rn-tester-e2e/test/common_steps/givenUserOnMainPage.steps.js
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
84 changes: 62 additions & 22 deletions
84
packages/rn-tester-e2e/test/runners/buttonComponentScreenRunner.js
This file contains hidden or 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 |
|---|---|---|
| @@ -1,46 +1,86 @@ | ||
| import { defineFeature, loadFeature } from 'jest-cucumber'; | ||
| import { givenUserOnMainPage } from '../common_steps/givenUserOnMainPage.steps'; | ||
| import * as steps from '../steps/buttonComponentScreen.steps'; | ||
| import { userIsOnMainScreen, clickOkButton } from '../common_steps/common.steps'; | ||
| import componentsScreen from '../screenObjects/components.screen.js'; | ||
| import buttonComponentScreen from '../screenObjects/buttonComponent.screen.js'; | ||
|
|
||
| Object.entries(steps).forEach(([name, exported]) => window[name] = exported); | ||
| // Object.entries(steps).forEach(([name, exported]) => window[name] = exported); | ||
| const feature = loadFeature('test/features/buttonComponentScreen.feature'); | ||
|
|
||
| //Methods used more than once in the feature | ||
| const buttonComponentShouldBeDisplayed = (then) => { | ||
| then('Verify that the Button component is displayed', async () => { | ||
adzironman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| expect(await componentsScreen.checkButtonComponentIsDisplayed()).toBeTruthy(); | ||
| }); | ||
| }; | ||
|
|
||
| const clickOnButtonComponent = (when) => { | ||
| when('User clicks on the Button component', async () => { | ||
| await componentsScreen.clickButtonComponent(); | ||
| }); | ||
| }; | ||
|
|
||
| const buttonHeaderShouldBeDisplayed = (then) => { | ||
| then(/^Verify that the "(.*)" header is displayed$/, async (headerScreenName) => { | ||
| switch (headerScreenName) { | ||
| case 'Button': | ||
| expect(await buttonComponentScreen.checkButtonsScreenIsDisplayed()).toBeTruthy(); | ||
| break; | ||
| // here you can add more similar assertions | ||
| default: throw new Error(`Wrong parameter provided. There is no such case as: ${headerScreenName}`); | ||
| } | ||
| }); | ||
| }; | ||
|
|
||
| const alertBoxShouldHaveText = (then) => { | ||
| then(/^Verify that the cancel|submit alert box has text: "(.*)"$/, async (alertBoxType, alertBoxText) => { | ||
| switch (alertBoxType) { | ||
| case 'cancel': | ||
| expect(await buttonComponentScreen.getCancelAlertText()).toContain(alertBoxText); | ||
| break; | ||
| case 'submit': | ||
| expect(await buttonComponentScreen.getSubmitAlertText()).toContain(alertBoxText); | ||
| break; | ||
| } | ||
| }); | ||
| }; | ||
|
|
||
| defineFeature(feature, (test) => { | ||
| test('Cancel Button', ({ given, when, then }) => { | ||
|
|
||
| givenUserOnMainPage(given); | ||
| userIsOnMainScreen(given); | ||
|
|
||
| thenVerifyThatTheButtonComponentIsDisplayed(then); | ||
| buttonComponentShouldBeDisplayed(then); | ||
|
|
||
| whenUserClicksOnTheButtonComponent(when); | ||
| clickOnButtonComponent(when); | ||
|
|
||
| thenVerifyThatTheButtonHeaderIsDisplayed(then); | ||
| buttonHeaderShouldBeDisplayed(then); | ||
|
|
||
| whenUserClicksOnTheCancelApplicationButton(when); | ||
| //method which is used only once in whole feature | ||
| when(/^User clicks on the Cancel Application button$/, async () => { | ||
| await buttonComponentScreen.clickCancelApplication(); | ||
| }); | ||
|
|
||
| thenVerifyAlertBoxHasText(then); | ||
| alertBoxShouldHaveText(then); | ||
|
|
||
| whenUserClicksOnTheOKButton(when); | ||
|
|
||
| thenVerifyThatTheButtonHeaderIsDisplayed(then); | ||
| clickOkButton(when); | ||
| }); | ||
|
|
||
| test('Submit Button', ({ given, when, then }) => { | ||
|
|
||
| givenUserOnMainPage(given); | ||
|
|
||
| thenVerifyThatTheButtonComponentIsDisplayed(then); | ||
| userIsOnMainScreen(given); | ||
|
|
||
| whenUserClicksOnTheButtonComponent(when); | ||
| buttonComponentShouldBeDisplayed(then); | ||
|
|
||
| thenVerifyThatTheButtonHeaderIsDisplayed(then); | ||
| clickOnButtonComponent(when); | ||
|
|
||
| whenUserClicksOnTheSubmitApplicationButton(when); | ||
| buttonHeaderShouldBeDisplayed(then); | ||
|
|
||
| thenVerifyAlertBoxHasText(then); | ||
| when(/^User clicks on the Submit Application button$/, async () => { | ||
| await buttonComponentScreen.clickCancelApplication(); | ||
| }); | ||
|
|
||
| whenUserClicksOnTheOKButton(when); | ||
| alertBoxShouldHaveText(then); | ||
|
|
||
| thenVerifyThatTheButtonHeaderIsDisplayed(then); | ||
| clickOkButton(when); | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or 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
52 changes: 0 additions & 52 deletions
52
packages/rn-tester-e2e/test/steps/buttonComponentScreen.steps.js
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.