Image Injection from Katalon Studio to sauce labs for automated Tests

Hi All,

Scenario : To upload/provide an input such as an image from the local device to sauce labs with the image injection feature to perform automated tests

i’m trying to perform an action such as image injection, i.e providing an local image path in Katalon and supplying that as an input to the remote device in sauce labs,

link - Camera Image Injection | Sauce Labs Documentation

As per the above link from sauce labs, if we configure the code like this, we can achieve image injection but even though we have written the code, we are getting an error(Attached file)

Can you please suggest how the code can be changed or any alternate scenario which provides image injection from Katalon studio to sauce labs remote devices?

Please let me know in case you need any other details, Below is the groovy code written in Katalon studio by creating a method:

import java.util.Base64 as Base64

import java.nio.file.Files as Files

import java.nio.file.Paths as Paths

import org.openqa.selenium.JavascriptExecutor as JavascriptExecutor

import java.io.FileInputStream as FileInputStream

import static org.apache.commons.io.IOUtils.toByteArray

Mobile.startExistingApplication('cargill.com.digitalsaathi')
Mobile.scrollToText(GlobalVariable.homeHeading, FailureHandling.OPTIONAL)
Mobile.tap(findTestObject('Object Repository/Application/Object_Collection/My Chat/Home Icon - Chat withExpert(paid)'), 0)
Mobile.waitForElementPresent(findTestObject('Application/Object_Collection/My Chat/Chat - Camera Icon (1)'), 0)


// Use executeScript with sauce:inject-image command to inject the image

def imagePath = '/Users/pathFolder/Execute_Test_case.png'

String base64ImageString = Base64.getEncoder().encodeToString(Files.readAllBytes(Paths.get(imagePath)))

  ((Mobile) as JavascriptExecutor).executeScript('sauce:inject-image=' + base64ImageString, findTestObject('Application/Object_Collection/My Chat/Chat - Camera Icon (1)'))



Mobile.waitForElementPresent(findTestObject('Application/Object_Collection/My Chat/Chat - Camera Icon (1)'), 0)
Mobile.tap(findTestObject('Application/Object_Collection/My Chat/Chat - Camera Icon (1)'), 0)
Mobile.waitForElementPresent(findTestObject('Application/Object_Collection/My Chat/Chat - Camera Capture option'), 0)
not_run: Mobile.closeApplication()

Error Log:

07-20-2023 03:42:14 PM Test Cases/Digital_Saathi_V4.2/Chat with Expert/Chat_new

Elapsed time: 32.961s

Test Cases/Digital_Saathi_V4.2/Chat with Expert/Chat_new FAILED.

Reason:

groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords.executeScript() is applicable for argument types: (java.lang.String, [Ljava.lang.Object;) values: [sauce:inject-image=iVBORw0KGgoAAAANSUhEUgAABpAAAAG6CAYAAAAPswUfAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAqduSURBVHgB7J0HYBRFG4bfq0kuvRdqQgmh996kg4B0sYAgYBdBEQv2BioKPxYsKE1URERBLID03nuHAAmk955r/

Thanks,
Sudarshan

The above error means you either have the wrong parameter data type(s) or the wrong number of parameters for the method. In the above, I believe you have the “wrong” parameter data type for the method.

It seems the method does not like:

sauce:inject-image=iVBORw0KGgoAAAANSUhEUgAABpAAAAG6CAYAAAAPswUfAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAqduSURBVHgB7J0HYBRFG4bfq0kuvRdqQgmh996kg4B0sYAgYBdBEQv2BioKPxYsKE1URERBLID03nuHAAmk955r/

Hi @sudarshan_narayanamu,
Are you sure you have the correct base64 format? You can check here:

  • Open Base64 Image Encoder / Decoder Online - AppDevTools
  • Click the ‘Encode’ button/link.
  • Click ‘Browse’ > Search for and open your test file.
  • Click ‘Copy’ to copy the encoded data.
  • Click the ‘Decode’ button/link.
  • Paste the encoded data into ‘Input Base64’ input field.
    You should see your resulting image.

Do you need upload a encoded image?
Why not just inject the image file as it is?

I also noticed your wait times are zero (0) not sure if that is intentional?

Mobile.waitForElementPresent(findTestObject('Application/Object_Collection/My Chat/Chat - Camera Icon (1)'), 0)
Mobile.tap(findTestObject('Application/Object_Collection/My Chat/Chat - Camera Icon (1)'), 0)
Mobile.waitForElementPresent(findTestObject('Application/Object_Collection/My Chat/Chat - Camera Capture option'), 0)

I don’t think so. I find a different problem as follows.

The error was raised at the following line in the script source:

  ((Mobile) as JavascriptExecutor).executeScript( ... )

Simply this line is wrong. Here a symbol (Mobile) refers to the class com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords. You should check the javadoc of Katalon Studio;

https://api-docs.katalon.com/com/kms/katalon/core/mobile/keyword/MobileBuiltInKeywords.html

You can easily find that the class com.kms.katalon.core.mobile.keyword.MobileBuiltinKeywords des not implement the org.openqa.selenium.JavascriptExecutor interface. That is the reason why you got that error.

1 Like

Can we use JavascriptExecutor with Appium? If yes, how can we get a reference to the JavascriptExecutor object?

I don’t know. I am not experienced with Mobile testing using Appium.

Could somebody advise us?

Thanks all for your reply,

local image path added is correctly converted to Base64 as i confirmed it online as well,

And i’m following this process of converting because that’s what sauce labs is expected me to do in their automation documentation - Camera Image Injection | Sauce Labs Documentation

And as @kazurayam said, even i’m not sure if adding JavascriptExecutor to execute this code in groovy or for mobile automation is correct or not, but i also don’t know what else to add,

I found a link in youtube (How to Test and Deliver Secure Mobile Apps in the New Era of Finance - YouTube , Timestamp - 32:51), where image injection is being tried with Appium, but not sure how we can pick that up to make Katalon understand