1+ import { AppiumDriver , createDriver , SearchOptions } from "nativescript-dev-appium" ;
2+ import { isSauceLab , runType , capabilitiesName } from "nativescript-dev-appium/lib/parser" ;
3+ import { expect } from "chai" ;
4+
5+ const isSauceRun = isSauceLab ;
6+ const isAndroid : string = runType . includes ( "android" ) ;
7+
8+ describe ( "Imagepicker" , async function ( ) {
9+ const imagesFolderName = "Images" ;
10+ const imagesFolderNameIos = "Camera Roll" ;
11+ const doneButtonText = "Done" ;
12+ let driver : AppiumDriver ;
13+
14+ before ( async ( ) => {
15+ driver = await createDriver ( ) ;
16+ driver . defaultWaitTime = 10000 ;
17+ } ) ;
18+
19+ after ( async ( ) => {
20+ if ( isSauceRun ) {
21+ driver . sessionId ( ) . then ( function ( sessionId ) {
22+ console . log ( "Report: https://saucelabs.com/beta/tests/" + sessionId ) ;
23+ } ) ;
24+ }
25+ await driver . quit ( ) ;
26+ console . log ( "Driver quits!" ) ;
27+ } ) ;
28+
29+ it ( "should pick one image" , async function ( ) {
30+ const pickSingleButtonText = "Pick Single" ;
31+ let confirmButtonText = isAndroid ? "Allow" : "OK" ;
32+ let uploadPicVerification ;
33+ if ( isAndroid ) {
34+ uploadPicVerification = isSauceRun ? "sauce_logo.png" : "pic1.jpeg" ;
35+ } else {
36+ uploadPicVerification = "IMG_0001.JPG" ;
37+ }
38+
39+ const pickSingleButton = await driver . findElementByText ( pickSingleButtonText , SearchOptions . contains ) ;
40+ await pickSingleButton . click ( ) ;
41+ const confirmButton = await driver . findElementByText ( confirmButtonText ) ;
42+ await confirmButton . click ( ) ;
43+
44+ if ( isAndroid ) {
45+ if ( isSauceRun ) {
46+ const imagesFolder = await driver . findElementByText ( imagesFolderName ) ;
47+ await imagesFolder . click ( ) ;
48+ const downloadFolder = await driver . findElementByClassName ( driver . locators . image ) ;
49+ await downloadFolder . click ( ) ;
50+ }
51+ } else {
52+ const cameraRollFolder = await driver . findElementByText ( imagesFolderNameIos ) ;
53+ await cameraRollFolder . click ( ) ;
54+ }
55+
56+ const pickedImage = await driver . findElementByClassName ( driver . locators . image ) ;
57+ await pickedImage . click ( ) ;
58+
59+ if ( ! isAndroid ) {
60+ const doneButton = await driver . findElementByText ( doneButtonText ) ;
61+ await doneButton . click ( ) ;
62+ }
63+
64+ const result = await driver . findElementByText ( uploadPicVerification , SearchOptions . contains ) ;
65+ expect ( result ) . to . exist ;
66+ } ) ;
67+
68+ it ( "should pick multiple images" , async function ( ) {
69+ let openImagesButtonText = isAndroid ? "Sort by" : doneButtonText ;
70+ let uploadPicVerification ;
71+ if ( isAndroid ) {
72+ uploadPicVerification = isSauceRun ? "sauce_logo_red.png" : "pic2.jpeg" ;
73+ } else {
74+ uploadPicVerification = "IMG_0001.JPG" ;
75+ }
76+ let uploadPicVerification2 ;
77+ if ( isAndroid ) {
78+ uploadPicVerification2 = isSauceRun ? "saucelabs_sauce.png" : "pic3.jpeg" ;
79+ } else {
80+ uploadPicVerification2 = "IMG_0002.JPG" ;
81+ }
82+ const pickMultipleButtonText = "Pick Multiple" ;
83+ const pickMultipleButton = await driver . findElementByText ( pickMultipleButtonText , SearchOptions . contains ) ;
84+ await pickMultipleButton . click ( ) ;
85+
86+ if ( ! isAndroid ) {
87+ const cameraRollFolder = await driver . findElementByText ( imagesFolderNameIos ) ;
88+ await cameraRollFolder . click ( ) ;
89+ }
90+
91+ const allImages = await driver . findElementsByClassName ( driver . locators . image ) ;
92+
93+ if ( isAndroid ) {
94+ await allImages [ 8 ] . hold ( ) ; //third image
95+ await allImages [ 4 ] . click ( ) ; //second image
96+ } else {
97+ await allImages [ 0 ] . click ( ) ; //first image
98+ await allImages [ 1 ] . click ( ) ; //second image
99+ }
100+
101+ const openImagesButton = await driver . findElementByText ( openImagesButtonText , SearchOptions . contains ) ;
102+ await openImagesButton . click ( ) ;
103+ const img = await driver . findElementByText ( uploadPicVerification , SearchOptions . contains ) ;
104+ expect ( img ) . to . exist ;
105+ const img1 = await driver . findElementByText ( uploadPicVerification2 , SearchOptions . contains ) ;
106+ expect ( img1 ) . to . exist ;
107+ } ) ;
108+ } ) ;
0 commit comments