|
| 1 | +import { AppiumDriver, createDriver, logWarn, nsCapabilities } from "nativescript-dev-appium"; |
| 2 | + |
| 3 | +import { Screen, playersData, teamsData } from "./screen"; |
| 4 | +import * as shared from "./shared.e2e-spec"; |
| 5 | +import { suspendTime, appSuspendResume, dontKeepActivities, transitions } from "./config"; |
| 6 | + |
| 7 | +const roots = ["BottomNavigation"]; |
| 8 | + |
| 9 | +const rootType = "bottom-navigation-root"; |
| 10 | +describe(rootType, async function () { |
| 11 | + let driver: AppiumDriver; |
| 12 | + let screen: Screen; |
| 13 | + |
| 14 | + before(async function () { |
| 15 | + nsCapabilities.testReporter.context = this; |
| 16 | + logWarn(`====== ${rootType} ========`); |
| 17 | + driver = await createDriver(); |
| 18 | + screen = new Screen(driver); |
| 19 | + if (dontKeepActivities) { |
| 20 | + await driver.setDontKeepActivities(true); |
| 21 | + } |
| 22 | + |
| 23 | + driver.defaultWaitTime = 8000; |
| 24 | + }); |
| 25 | + |
| 26 | + after(async function () { |
| 27 | + if (dontKeepActivities) { |
| 28 | + await driver.setDontKeepActivities(false); |
| 29 | + } |
| 30 | + await driver.quit(); |
| 31 | + console.log("Quit driver!"); |
| 32 | + }); |
| 33 | + |
| 34 | + afterEach(async function () { |
| 35 | + if (this.currentTest.state === "failed") { |
| 36 | + await driver.logTestArtifacts(this.currentTest.title); |
| 37 | + } |
| 38 | + }); |
| 39 | + |
| 40 | + for (let index = 0; index < roots.length; index++) { |
| 41 | + const root = roots[index]; |
| 42 | + describe(`${rootType}-${root}-scenarios:`, async function () { |
| 43 | + |
| 44 | + before(async function () { |
| 45 | + nsCapabilities.testReporter.context = this; |
| 46 | + }); |
| 47 | + |
| 48 | + for (let index = 0; index < transitions.length; index++) { |
| 49 | + const transition = transitions[index]; |
| 50 | + |
| 51 | + const playerOne = playersData[`playerOne${transition}`]; |
| 52 | + const playerTwo = playersData[`playerTwo${transition}`]; |
| 53 | + const teamOne = teamsData[`teamOne${transition}`]; |
| 54 | + const teamTwo = teamsData[`teamTwo${transition}`]; |
| 55 | + |
| 56 | + describe(`${rootType}-${root}-transition-${transition}-scenarios:`, async function () { |
| 57 | + |
| 58 | + before(async function () { |
| 59 | + nsCapabilities.testReporter.context = this; |
| 60 | + |
| 61 | + if (transition === "Flip" && |
| 62 | + driver.isAndroid && parseInt(driver.platformVersion) === 19) { |
| 63 | + // TODO: known issue https://github.com/NativeScript/NativeScript/issues/6798 |
| 64 | + console.log("skipping flip transition tests on api level 19"); |
| 65 | + this.skip(); |
| 66 | + } |
| 67 | + }); |
| 68 | + |
| 69 | + it("loaded home page", async function () { |
| 70 | + await screen.loadedHome(); |
| 71 | + }); |
| 72 | + |
| 73 | + it(`loaded ${root} root with frames`, async function () { |
| 74 | + await screen[`navigateTo${root}RootWithFrames`](); |
| 75 | + await screen[`loaded${root}RootWithFrames`](); |
| 76 | + }); |
| 77 | + |
| 78 | + it("loaded players list", async function () { |
| 79 | + await screen.loadedPlayersList(); |
| 80 | + }); |
| 81 | + |
| 82 | + it("loaded player details and go back twice", async function () { |
| 83 | + await shared.testPlayerNavigated(playerTwo, screen); |
| 84 | + |
| 85 | + if (appSuspendResume) { |
| 86 | + await driver.backgroundApp(suspendTime); |
| 87 | + await driver.waitForElement(playerTwo.name); // wait for player |
| 88 | + } |
| 89 | + |
| 90 | + await shared.testPlayerNavigatedBack(screen, driver); |
| 91 | + |
| 92 | + if (appSuspendResume) { |
| 93 | + await driver.backgroundApp(suspendTime); |
| 94 | + await driver.waitForElement(playerOne.name); // wait for players list |
| 95 | + } |
| 96 | + |
| 97 | + await shared.testPlayerNavigated(playerTwo, screen); |
| 98 | + await shared.testPlayerNavigatedBack(screen, driver); |
| 99 | + }); |
| 100 | + |
| 101 | + it("toggle teams tab", async function () { |
| 102 | + await screen.toggleTeamsTab(); |
| 103 | + |
| 104 | + if (appSuspendResume) { |
| 105 | + await driver.backgroundApp(suspendTime); |
| 106 | + await driver.waitForElement(teamOne.name); // wait for teams list |
| 107 | + } |
| 108 | + }); |
| 109 | + |
| 110 | + it("loaded teams list", async function () { |
| 111 | + await screen.loadedTeamsList(); |
| 112 | + }); |
| 113 | + |
| 114 | + it("mix player and team list actions and go back", async function () { |
| 115 | + await screen.togglePlayersTab(); |
| 116 | + |
| 117 | + if (appSuspendResume) { |
| 118 | + await driver.backgroundApp(suspendTime); |
| 119 | + await driver.waitForElement(playerOne.name); // wait for players list |
| 120 | + } |
| 121 | + |
| 122 | + await screen.loadedPlayersList(); |
| 123 | + |
| 124 | + await shared.testPlayerNavigated(playerTwo, screen); |
| 125 | + |
| 126 | + if (driver.isIOS) { |
| 127 | + if (appSuspendResume) { |
| 128 | + await driver.backgroundApp(suspendTime); |
| 129 | + await driver.waitForElement(playerTwo.name); // wait for player |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + await screen.toggleTeamsTab(); |
| 134 | + |
| 135 | + if (driver.isIOS) { |
| 136 | + // TODO: run in background from appium breaks the test. Investigate the issue, once with the app and with appium |
| 137 | + if (appSuspendResume) { |
| 138 | + await driver.backgroundApp(suspendTime); |
| 139 | + await driver.waitForElement(teamOne.name); // wait for teams list |
| 140 | + } |
| 141 | + } |
| 142 | + |
| 143 | + await screen.loadedTeamsList(); |
| 144 | + |
| 145 | + await shared.testTeamNavigated(teamTwo, screen); |
| 146 | + |
| 147 | + if (appSuspendResume) { |
| 148 | + await driver.backgroundApp(suspendTime); |
| 149 | + await driver.waitForElement(teamTwo.name); // wait for team |
| 150 | + } |
| 151 | + |
| 152 | + await screen.togglePlayersTab(); |
| 153 | + |
| 154 | + if (appSuspendResume) { |
| 155 | + await driver.backgroundApp(suspendTime); |
| 156 | + await driver.waitForElement(playerTwo.name); // wait for player |
| 157 | + } |
| 158 | + |
| 159 | + await screen.loadedPlayerDetails(playerTwo); |
| 160 | + |
| 161 | + await screen.toggleTeamsTab(); |
| 162 | + |
| 163 | + await screen.goBackToTeamsList(); |
| 164 | + await screen.loadedTeamsList(); |
| 165 | + |
| 166 | + await screen.togglePlayersTab(); |
| 167 | + |
| 168 | + await screen.goBackToPlayersList(); |
| 169 | + await screen.loadedPlayersList(); |
| 170 | + }); |
| 171 | + |
| 172 | + it("loaded home page again", async function () { |
| 173 | + await screen.resetToHome(); |
| 174 | + await screen.loadedHome(); |
| 175 | + }); |
| 176 | + }); |
| 177 | + } |
| 178 | + }); |
| 179 | + } |
| 180 | +}); |
0 commit comments