|
| 1 | +import { |
| 2 | + AppiumDriver, |
| 3 | + createDriver, |
| 4 | + SearchOptions |
| 5 | +} from "nativescript-dev-appium"; |
| 6 | +import { isSauceLab, runType } from "nativescript-dev-appium/lib/parser"; |
| 7 | +import { expect } from "chai"; |
| 8 | +import "mocha"; |
| 9 | + |
| 10 | +const isSauceRun = isSauceLab; |
| 11 | +const isAndroid: boolean = runType.includes("android"); |
| 12 | + |
| 13 | +describe("Facebook tests", async function () { |
| 14 | + const FACEBOOK_BUTTON = "fbLogin"; |
| 15 | + const USERNAME = "nativescript_gctpjih_user@tfbnw.net"; |
| 16 | + const PASSWORD = "P@ssw0rd"; |
| 17 | + const CUSTOM_LOGOUT_BUTTON = "customLogOut"; |
| 18 | + const USER_NAME = "Nativescript User"; |
| 19 | + let driver: AppiumDriver; |
| 20 | + |
| 21 | + before(async () => { |
| 22 | + driver = await createDriver(); |
| 23 | + driver.defaultWaitTime = 20000; |
| 24 | + }); |
| 25 | + |
| 26 | + after(async () => { |
| 27 | + if (isSauceRun) { |
| 28 | + driver.sessionId().then(function (sessionId) { |
| 29 | + console.log("Report: https://saucelabs.com/beta/tests/" + sessionId); |
| 30 | + }); |
| 31 | + } |
| 32 | + await driver.quit(); |
| 33 | + console.log("Driver successfully quit"); |
| 34 | + }); |
| 35 | + |
| 36 | + it("should log in via custom button", async function () { |
| 37 | + if (isAndroid) { |
| 38 | + var userNameLabelElement = "[@text='Nativescript User']"; |
| 39 | + } else { |
| 40 | + var userNameLabelElement = "[@name='Nativescript User']"; |
| 41 | + } |
| 42 | + |
| 43 | + const facebookButton = await driver.findElementByText("Custom", SearchOptions.contains); |
| 44 | + await facebookButton.click(); |
| 45 | + |
| 46 | + if (isAndroid) { |
| 47 | + const allFields = await driver.findElementsByClassName(driver.locators.getElementByName("textfield")); |
| 48 | + const wd = driver.wd(); |
| 49 | + const action = new wd.TouchAction(driver.driver); |
| 50 | + action |
| 51 | + .press({ x: 52, y: 499 }) |
| 52 | + .moveTo({ x: -2, y: -294 }) |
| 53 | + .release(); |
| 54 | + await action.perform(); |
| 55 | + await driver.wait(1000); |
| 56 | + await allFields[1].sendKeys(PASSWORD); |
| 57 | + try { |
| 58 | + await driver.driver.hideDeviceKeyboard(); |
| 59 | + } catch (error) { } |
| 60 | + await driver.wait(1000); |
| 61 | + await allFields[0].sendKeys(USERNAME); |
| 62 | + } else { |
| 63 | + const passField = await driver.findElementByClassName(driver.locators.getElementByName("securetextfield")); |
| 64 | + await passField.click(); |
| 65 | + await passField.sendKeys(PASSWORD); |
| 66 | + const usernameField = await driver.findElementByClassName(driver.locators.getElementByName("textfield")); |
| 67 | + await usernameField.click(); |
| 68 | + await usernameField.sendKeys(USERNAME); |
| 69 | + } |
| 70 | + try { |
| 71 | + await driver.driver.hideDeviceKeyboard("Done"); |
| 72 | + } catch (error) { } |
| 73 | + if (isAndroid) { |
| 74 | + const logInButton = await driver.findElementByClassName(driver.locators.button); |
| 75 | + await logInButton.click(); |
| 76 | + const continueButton = await driver.findElementByText("Continue"); |
| 77 | + await continueButton.click(); |
| 78 | + } else { |
| 79 | + const logInButton = await driver.findElementByText("Log In"); |
| 80 | + await logInButton.click(); |
| 81 | + const continueButton = await driver.findElementByText("Continue"); |
| 82 | + await continueButton.click(); |
| 83 | + } |
| 84 | + const userNameLabel = await driver.findElementByXPath( |
| 85 | + "//" + driver.locators.getElementByName("label") + userNameLabelElement |
| 86 | + ); |
| 87 | + const userName = await userNameLabel.text(); |
| 88 | + expect(userName).to.equal(USER_NAME, "Not logged with the same user"); |
| 89 | + }); |
| 90 | + |
| 91 | + it("should log out via custom button", async function () { |
| 92 | + const allButtons = await driver.findElementsByClassName(driver.locators.button); |
| 93 | + await allButtons[1].click(); |
| 94 | + const facebookButton = await driver.findElementByText("Continue with Facebook", SearchOptions.exact); |
| 95 | + expect(facebookButton).to.exist; |
| 96 | + }); |
| 97 | + |
| 98 | + it("should share a link", async function () { |
| 99 | + const shareLinkButton = await driver.findElementByText("Open Share dialog", SearchOptions.contains); |
| 100 | + await shareLinkButton.click(); |
| 101 | + if (isAndroid) { |
| 102 | + const allFields = await driver.findElementsByClassName(driver.locators.getElementByName("textfield")); |
| 103 | + await allFields[1].sendKeys(PASSWORD); |
| 104 | + await allFields[0].sendKeys(USERNAME); |
| 105 | + const logInButton = await driver.findElementByClassName(driver.locators.button); |
| 106 | + await logInButton.click(); |
| 107 | + } else { |
| 108 | + const passField = await driver.findElementByClassName(driver.locators.getElementByName("securetextfield")); |
| 109 | + await passField.click(); |
| 110 | + await passField.sendKeys(PASSWORD); |
| 111 | + const usernameField = await driver.findElementByClassName(driver.locators.getElementByName("textfield")); |
| 112 | + await usernameField.click(); |
| 113 | + await usernameField.sendKeys(USERNAME); |
| 114 | + const logInButton = await driver.findElementByText("Log In"); |
| 115 | + await logInButton.click(); |
| 116 | + } |
| 117 | + |
| 118 | + const postButton = await driver.findElementByText("Post"); |
| 119 | + expect(postButton).to.exist; |
| 120 | + }); |
| 121 | +}); |
0 commit comments