66import { isSauceLab , runType } from "nativescript-dev-appium/lib/parser" ;
77import { expect } from "chai" ;
88import "mocha" ;
9+ const fs = require ( 'fs' ) ;
10+ const addContext = require ( 'mochawesome/addContext' ) ;
11+ const rimraf = require ( 'rimraf' ) ;
912
1013const isSauceRun = isSauceLab ;
1114const isAndroid : boolean = runType . includes ( "android" ) ;
@@ -21,6 +24,11 @@ describe("Facebook tests", async function () {
2124 before ( async ( ) => {
2225 driver = await createDriver ( ) ;
2326 driver . defaultWaitTime = 20000 ;
27+ let dir = "mochawesome-report" ;
28+ if ( ! fs . existsSync ( dir ) ) {
29+ fs . mkdirSync ( dir ) ;
30+ }
31+ rimraf ( 'mochawesome-report/*' , function ( ) { } ) ;
2432 } ) ;
2533
2634 after ( async ( ) => {
@@ -33,6 +41,19 @@ describe("Facebook tests", async function () {
3341 console . log ( "Driver successfully quit" ) ;
3442 } ) ;
3543
44+ afterEach ( async function ( ) {
45+ if ( this . currentTest . state && this . currentTest . state === "failed" ) {
46+ let png = await driver . logScreenshot ( this . currentTest . title ) ;
47+ fs . copyFile ( png , './mochawesome-report/' + this . currentTest . title + '.png' , function ( err ) {
48+ if ( err ) {
49+ throw err ;
50+ }
51+ console . log ( 'Screenshot saved.' ) ;
52+ } ) ;
53+ addContext ( this , './' + this . currentTest . title + '.png' ) ;
54+ }
55+ } )
56+
3657 it ( "should log in via custom button" , async function ( ) {
3758 if ( isAndroid ) {
3859 var userNameLabelElement = "[@text='Nativescript User']" ;
0 commit comments