1+ "use strict" ;
2+ var nsAppium = require ( "nativescript-dev-appium" ) ;
3+ var isAndroid = process . env . npm_config_runtype . includes ( "android" ) ;
4+ describe ( "facebook tests" , function ( ) {
5+ this . timeout ( 100000 ) ;
6+ var driver ;
7+ const FACEBOOK_BUTTON = "fbLogin" ;
8+ const USERNAME = "open_qgonlya_user@tfbnw.net" ;
9+ const PASSWORD = "P@ssw0rd" ;
10+ const CUSTOM_LOGOUT_BUTTON = "customLogOut" ;
11+ const USER_ID = "UserId: 132396757312450" ;
12+
13+ before ( function ( ) {
14+ driver = nsAppium . createDriver ( ) ;
15+ } ) ;
16+
17+ after ( function ( ) {
18+ return driver
19+ . quit ( )
20+ . finally ( function ( ) {
21+ console . log ( "Driver quit successfully" ) ;
22+ } ) ;
23+ } ) ;
24+ //=============================== ANDROID TESTS ==========================
25+ if ( isAndroid ) {
26+ describe ( "android tests" , function ( ) {
27+
28+ it ( "should log in via original button" , function ( ) {
29+ return driver
30+ . elementByAccessibilityId ( FACEBOOK_BUTTON )
31+ . should . eventually . exist
32+ . click ( )
33+ . waitForElementsByClassName ( nsAppium . getXPathElement ( "textfield" ) , 10000 ) . first ( )
34+ . setText ( USERNAME )
35+ . elementsByClassName ( nsAppium . getXPathElement ( "textfield" ) ) . last ( ) //Password field
36+ . setText ( PASSWORD )
37+ . elementsByClassName ( nsAppium . getXPathElement ( "button" ) ) . first ( ) //Log in button
38+ . click ( )
39+ . sleep ( 3000 )
40+ . waitForElementsByClassName ( nsAppium . getXPathElement ( "button" ) , 10000 ) . last ( ) // OK button
41+ . click ( )
42+ . waitForElementsByClassName ( nsAppium . getXPathElement ( "label" ) , 10000 ) . last ( )
43+ . text ( ) . should . eventually . equal ( USER_ID )
44+ } ) ;
45+
46+ it ( "should log out via custom button" , function ( ) {
47+ return driver
48+ . elementByAccessibilityId ( CUSTOM_LOGOUT_BUTTON )
49+ . should . eventually . exist
50+ . tap ( )
51+ . waitForElementByAccessibilityId ( FACEBOOK_BUTTON )
52+ . text ( ) . should . eventually . equal ( "Log in with Facebook" )
53+ } ) ;
54+ } ) ;
55+ } else {
56+ //=========================================== IOS TESTS ======================================
57+ describe ( "ios tests" , function ( ) {
58+
59+ it ( "should log in via original button" , function ( ) {
60+ return driver
61+ . elementByAccessibilityId ( FACEBOOK_BUTTON )
62+ . should . eventually . exist
63+ . click ( )
64+ // Needed for IOS because IfExists does not have timeout
65+ . sleep ( 5000 )
66+ . elementByClassNameIfExists ( nsAppium . getXPathElement ( "textfield" ) )
67+ . then ( function ( el ) {
68+ if ( el ) {
69+ return driver
70+ . elementsByClassName ( nsAppium . getXPathElement ( "textfield" ) ) . first ( )
71+ . sendKeys ( USERNAME )
72+ . elementsByClassName ( nsAppium . getXPathElement ( "securetextfield" ) ) . last ( ) // Password field
73+ . sendKeys ( PASSWORD )
74+ . elementsByClassName ( nsAppium . getXPathElement ( "button" ) ) . nth ( 4 ) //Log in button
75+ . click ( )
76+ }
77+ } )
78+ . waitForElementsByClassName ( nsAppium . getXPathElement ( "button" ) , 10000 ) . nth ( 5 ) // OK button
79+ . click ( )
80+ . sleep ( 2000 ) // Take time to change label value
81+ . elementByClassName ( nsAppium . getXPathElement ( "label" ) )
82+ . text ( ) . should . eventually . equal ( USER_ID )
83+ } ) ;
84+
85+ it ( "should log out via original button" , function ( ) {
86+ return driver
87+ . elementByAccessibilityId ( FACEBOOK_BUTTON )
88+ . should . eventually . exist
89+ . click ( )
90+ . elementsByClassName ( nsAppium . getXPathElement ( "button" ) ) . first ( ) //Log out confirmation button
91+ . click ( )
92+ . sleep ( 2000 ) // Take time to change label value
93+ . elementByClassName ( nsAppium . getXPathElement ( "label" ) )
94+ . text ( ) . should . eventually . equal ( "not logged in" )
95+ } ) ;
96+ } )
97+ }
98+ } ) ;
0 commit comments