11import { browser , expect } from '@wdio/globals' ;
2+ import path from "path" ;
23
34async function performLogin ( userName = 'admin' , password = '1234' ) {
45 await browser . takeScreenshot ( ) ;
@@ -12,6 +13,14 @@ async function performLogin(userName = 'admin', password = '1234') {
1213 await browser . flutterByValueKey$ ( 'LoginButton' ) . click ( ) ;
1314}
1415
16+ function itForAndroidOnly ( description , fn ) {
17+ if ( browser . isIOS ) {
18+ it . skip ( description , fn ) ;
19+ } else {
20+ it ( description , fn ) ;
21+ }
22+ }
23+
1524async function openScreen ( screenTitle ) {
1625 const screenListElement = await browser . flutterScrollTillVisible ( {
1726 finder : await browser . flutterByText ( screenTitle ) ,
@@ -279,8 +288,9 @@ describe('My Login application', () => {
279288 . getText ( ) ;
280289 expect ( dropped ) . toEqual ( 'The box is dropped' ) ;
281290 } ) ;
282-
283- it ( 'should switch to webview context and validate the page title' , async ( ) => {
291+
292+ //TODO: Wbview is not inspectable on iOS demo app, need to fix it.
293+ itForAndroidOnly ( 'should switch to webview context and validate the page title' , async ( ) => {
284294 await performLogin ( ) ;
285295 await openScreen ( 'Web View' ) ;
286296 await switchToWebview ( ) ;
@@ -300,7 +310,7 @@ describe('My Login application', () => {
300310 ) ;
301311 } ) ;
302312
303- it ( 'should execute native commands correctly while in Webview context' , async ( ) => {
313+ itForAndroidOnly ( 'should execute native commands correctly while in Webview context' , async ( ) => {
304314 await performLogin ( ) ;
305315 await openScreen ( 'Web View' ) ;
306316 await switchToWebview ( ) ;
@@ -320,7 +330,7 @@ describe('My Login application', () => {
320330 expect ( typeof pageSource ) . toBe ( 'string' ) ;
321331 } ) ;
322332
323- it ( 'should switch back and forth between native and Webview contexts' , async ( ) => {
333+ itForAndroidOnly ( 'should switch back and forth between native and Webview contexts' , async ( ) => {
324334 await performLogin ( ) ;
325335 await openScreen ( 'Web View' ) ;
326336
@@ -334,3 +344,28 @@ describe('My Login application', () => {
334344 expect ( await browser . getContext ( ) ) . toContain ( 'WEBVIEW' ) ;
335345 } ) ;
336346} ) ;
347+
348+ describe ( 'Image mocking' , async ( ) => {
349+ afterEach ( async ( ) => {
350+ await handleAppManagement ( ) ;
351+ } ) ;
352+
353+ it ( 'Inject Image' , async ( ) => {
354+ const firstImageToMock = path . resolve ( 'test/qr.png' ) ;
355+ const secondImageToMock = path . resolve ( 'test/SecondImage.png' ) ;
356+ await performLogin ( ) ;
357+ await openScreen ( 'Image Picker' ) ;
358+ const firstInjectedImage = await browser . flutterInjectImage ( firstImageToMock ) ;
359+ await browser . flutterByValueKey$ ( 'capture_image' ) . click ( ) ;
360+ await browser . flutterByText$ ( 'PICK' ) . click ( ) ;
361+ expect ( await browser . flutterByText$ ( 'Success!' ) . isDisplayed ( ) ) . toBe ( true ) ;
362+ await browser . flutterInjectImage ( secondImageToMock ) ;
363+ await browser . flutterByValueKey$ ( 'capture_image' ) . click ( ) ;
364+ await browser . flutterByText$ ( 'PICK' ) . click ( ) ;
365+ expect ( await browser . flutterByText$ ( 'SecondInjectedImage' ) . isDisplayed ( ) ) . toBe ( true ) ;
366+ await browser . flutterActivateInjectedImage ( { imageId : firstInjectedImage } ) ;
367+ await browser . flutterByValueKey$ ( 'capture_image' ) . click ( ) ;
368+ await browser . flutterByText$ ( 'PICK' ) . click ( ) ;
369+ expect ( await browser . flutterByText$ ( 'Success!' ) . isDisplayed ( ) ) . toBe ( true ) ;
370+ } )
371+ } )
0 commit comments