1+ import { AppiumDriver , createDriver , SearchOptions } from "nativescript-dev-appium" ;
2+ import { isSauceLab , runType } from "nativescript-dev-appium/lib/parser" ;
3+ import { expect } from "chai" ;
4+ import "mocha" ;
5+
6+ const isSauceRun = isSauceLab ;
7+ const isAndroid : string = runType . includes ( "android" ) ;
8+
9+ describe ( "Facebook tests" , async function ( ) {
10+ const FACEBOOK_BUTTON = "fbLogin" ;
11+ const USERNAME = "nativescript_gctpjih_user@tfbnw.net" ;
12+ const PASSWORD = "P@ssw0rd" ;
13+ const CUSTOM_LOGOUT_BUTTON = "customLogOut" ;
14+ const USER_NAME = "Nativescript User" ;
15+ let driver : AppiumDriver ;
16+
17+ before ( async ( ) => {
18+ driver = await createDriver ( ) ;
19+ driver . defaultWaitTime = 15000 ;
20+ } ) ;
21+
22+ after ( async ( ) => {
23+ if ( isSauceRun ) {
24+ driver . sessionId ( ) . then ( function ( sessionId ) {
25+ console . log ( "Report: https://saucelabs.com/beta/tests/" + sessionId ) ;
26+ } ) ;
27+ }
28+ await driver . quit ( ) ;
29+ console . log ( "Driver successfully quit" ) ;
30+ } ) ;
31+
32+ it ( "should log in via original button" , async function ( ) {
33+ if ( isAndroid ) {
34+ var userNameLabelElement = "[@text='Nativescript User']" ;
35+ } else {
36+ var loginButtonElement = "[@name='Log In']" ;
37+ var continueButtonAttribute = "[@name='Continue']" ;
38+ var userNameLabelElement = "[@name='Nativescript User']" ;
39+ }
40+
41+ const facebookButton = await driver . findElementByAccessibilityId ( FACEBOOK_BUTTON ) ;
42+ await facebookButton . click ( ) ;
43+
44+ if ( isAndroid ) {
45+ const allFields = await driver . driver . waitForElementsByClassName ( driver . locators . getElementByName ( "textfield" ) , 10000 ) ;
46+ await allFields [ 1 ] . click ( ) . sendKeys ( PASSWORD ) ;
47+ await allFields [ 0 ] . click ( ) . sendKeys ( USERNAME ) ;
48+ } else {
49+ const passField = await driver . driver . waitForElementByClassName ( driver . locators . getElementByName ( "securetextfield" ) , 10000 ) ;
50+ await passField . click ( ) . sendKeys ( PASSWORD ) ;
51+ const usernameField = await driver . driver . waitForElementByClassName ( driver . locators . getElementByName ( "textfield" ) , 10000 ) ;
52+ await usernameField . click ( ) . sendKeys ( USERNAME ) ;
53+ }
54+ await driver . driver . hideDeviceKeyboard ( "Done" ) ;
55+ if ( isAndroid ) {
56+ const logInButton = await driver . findElementByClassName ( driver . locators . button ) ;
57+ await logInButton . click ( ) ;
58+ const okButton = await driver . findElementByClassName ( driver . locators . button ) ;
59+ await okButton . click ( ) ;
60+ } else {
61+ const logInButton = await driver . findElementByXPath ( "//" + driver . locators . button + loginButtonElement ) ;
62+ await logInButton . click ( ) ;
63+ const continueButton = await driver . findElementByXPath ( "//" + driver . locators . button + continueButtonAttribute ) ;
64+ await continueButton . click ( ) ;
65+ }
66+ const userNameLabel = await driver . findElementByXPath ( "//" + driver . locators . getElementByName ( "label" ) + userNameLabelElement ) ;
67+ const userName = await userNameLabel . text ( ) ;
68+ expect ( userName ) . to . equal ( USER_NAME , "Not logged with the same user" ) ;
69+
70+ } ) ;
71+
72+ it ( "should log out via custom button" , async function ( ) {
73+ const facebookLogoutButton = await driver . findElementByAccessibilityId ( CUSTOM_LOGOUT_BUTTON ) ;
74+ await facebookLogoutButton . click ( ) ;
75+ const facebookButton = await driver . findElementByAccessibilityId ( FACEBOOK_BUTTON ) ;
76+ expect ( facebookButton ) . to . exist ;
77+ } ) ;
78+ } ) ;
0 commit comments