11import {
2- AppiumDriver ,
3- createDriver ,
4- SearchOptions
2+ AppiumDriver ,
3+ createDriver ,
4+ SearchOptions
55} from "nativescript-dev-appium" ;
66import { isSauceLab , runType } from "nativescript-dev-appium/lib/parser" ;
77import { expect } from "chai" ;
@@ -10,98 +10,112 @@ import "mocha";
1010const isSauceRun = isSauceLab ;
1111const isAndroid : boolean = runType . includes ( "android" ) ;
1212
13- describe ( "Facebook tests" , async function ( ) {
14- const FACEBOOK_BUTTON = "fbLogin" ;
15- const USERNAME = "[email protected] " ; 16- const PASSWORD = "P@ssw0rd" ;
17- const CUSTOM_LOGOUT_BUTTON = "customLogOut" ;
18- const USER_NAME = "Nativescript User" ;
19- let driver : AppiumDriver ;
13+ describe ( "Facebook tests" , async function ( ) {
14+ const FACEBOOK_BUTTON = "fbLogin" ;
15+ const USERNAME = "[email protected] " ; 16+ const PASSWORD = "P@ssw0rd" ;
17+ const CUSTOM_LOGOUT_BUTTON = "customLogOut" ;
18+ const USER_NAME = "Nativescript User" ;
19+ let driver : AppiumDriver ;
2020
21- before ( async ( ) => {
22- driver = await createDriver ( ) ;
23- driver . defaultWaitTime = 20000 ;
24- } ) ;
21+ before ( async ( ) => {
22+ driver = await createDriver ( ) ;
23+ driver . defaultWaitTime = 20000 ;
24+ } ) ;
2525
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- } ) ;
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+ } ) ;
3535
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- }
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+ }
4242
43- const facebookButton = await driver . findElementByText (
44- "Custom" ,
45- SearchOptions . contains
46- ) ;
47- await facebookButton . click ( ) ;
43+ const facebookButton = await driver . findElementByText ( "Custom" , SearchOptions . contains ) ;
44+ await facebookButton . click ( ) ;
4845
49- if ( isAndroid ) {
50- const allFields = await driver . driver . waitForElementsByClassName (
51- driver . locators . getElementByName ( "textfield" ) ,
52- 10000
53- ) ;
54- const wd = driver . wd ( ) ;
55- const action = new wd . TouchAction ( driver . driver ) ;
56- action
57- . press ( { x : 52 , y : 499 } )
58- . moveTo ( { x : - 2 , y : - 294 } )
59- . release ( ) ;
60- await action . perform ( ) ;
61- await driver . wait ( 1000 ) ;
62- await allFields [ 1 ] . sendKeys ( PASSWORD ) ;
63- try {
64- await driver . driver . hideDeviceKeyboard ( ) ;
65- } catch ( error ) { }
66- await driver . wait ( 1000 ) ;
67- await allFields [ 0 ] . sendKeys ( USERNAME ) ;
68- } else {
69- const passField = await driver . driver . waitForElementByClassName (
70- driver . locators . getElementByName ( "securetextfield" ) ,
71- 10000
72- ) ;
73- await passField . click ( ) . sendKeys ( PASSWORD ) ;
74- const usernameField = await driver . driver . waitForElementByClassName (
75- driver . locators . getElementByName ( "textfield" ) ,
76- 10000
77- ) ;
78- await usernameField . click ( ) . sendKeys ( USERNAME ) ;
79- }
80- try {
81- await driver . driver . hideDeviceKeyboard ( "Done" ) ;
82- } catch ( error ) { }
83- if ( isAndroid ) {
84- const logInButton = await driver . findElementByClassName ( driver . locators . button ) ;
85- await logInButton . click ( ) ;
86- const okButton = await driver . findElementByClassName ( driver . locators . button ) ;
87- await okButton . click ( ) ;
88- } else {
89- const logInButton = await driver . findElementByText ( "Log In" ) ;
90- await logInButton . click ( ) ;
91- const continueButton = await driver . findElementByText ( "Continue" ) ;
92- await continueButton . click ( ) ;
93- }
94- const userNameLabel = await driver . findElementByXPath (
95- "//" + driver . locators . getElementByName ( "label" ) + userNameLabelElement
96- ) ;
97- const userName = await userNameLabel . text ( ) ;
98- expect ( userName ) . to . equal ( USER_NAME , "Not logged with the same user" ) ;
99- } ) ;
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+ } ) ;
10090
101- it ( "should log out via custom button" , async function ( ) {
102- const allButtons = await driver . findElementsByClassName ( driver . locators . button ) ;
103- await allButtons [ 1 ] . click ( ) ;
104- const facebookButton = await driver . findElementByAccessibilityId ( FACEBOOK_BUTTON ) ;
105- expect ( facebookButton ) . to . exist ;
106- } ) ;
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 . findElementByAccessibilityId ( FACEBOOK_BUTTON ) ;
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+ } ) ;
107121} ) ;
0 commit comments