11import { AppiumDriver , createDriver , SearchOptions } from "nativescript-dev-appium" ;
22import { isSauceLab , runType } from "nativescript-dev-appium/lib/parser" ;
33import { expect } from "chai" ;
4-
4+ const fs = require ( 'fs' ) ;
5+ const addContext = require ( 'mochawesome/addContext' ) ;
6+ const rimraf = require ( 'rimraf' ) ;
57const isSauceRun = isSauceLab ;
68const isAndroid : boolean = runType . includes ( "android" ) ;
79
@@ -14,6 +16,11 @@ describe("Imagepicker", async function () {
1416 before ( async ( ) => {
1517 driver = await createDriver ( ) ;
1618 driver . defaultWaitTime = 10000 ;
19+ let dir = "mochawesome-report" ;
20+ if ( ! fs . existsSync ( dir ) ) {
21+ fs . mkdirSync ( dir ) ;
22+ }
23+ rimraf ( 'mochawesome-report/*' , function ( ) { } ) ;
1724 } ) ;
1825
1926 after ( async ( ) => {
@@ -26,6 +33,19 @@ describe("Imagepicker", async function () {
2633 console . log ( "Driver quits!" ) ;
2734 } ) ;
2835
36+ afterEach ( async function ( ) {
37+ if ( this . currentTest . state && this . currentTest . state === "failed" ) {
38+ let png = await driver . logScreenshot ( this . currentTest . title ) ;
39+ fs . copyFile ( png , './mochawesome-report/' + this . currentTest . title + '.png' , function ( err ) {
40+ if ( err ) {
41+ throw err ;
42+ }
43+ console . log ( 'Screenshot saved.' ) ;
44+ } ) ;
45+ addContext ( this , './' + this . currentTest . title + '.png' ) ;
46+ }
47+ } ) ;
48+
2949 it ( "should pick one image" , async function ( ) {
3050 // await driver.driver.resetApp();
3151 const pickSingleButtonText = "Pick Single" ;
0 commit comments