Table of contents
1.
Introduction
2.
What is Katalon?
3.
Background Details
4.
Setting up Appium Flutter Driver
5.
Run a Flutter-based application test with the custom SetText keyword
6.
How to switch contexts?
7.
Frequently Asked Questions
7.1.
What is Katalon Studio?
7.2.
Is Katalon easy to learn?
7.3.
Does Katalon use Selenium?
7.4.
Is Katalon Studio free to use?
8.
Conclusion
Last Updated: Mar 27, 2024
Easy

Flutter-Based Application Testing with Custom SetText Keyword in Katalon

Author Shubham Das
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Katalon is an automation testing software tool developed by Katalon, Inc. It helps to create and reuse automated test scripts without coding. We often use Katalon for API testing. This article will deal with flutter-based application testing with the custom SetText keyword in Katalon.

Flutter Based Application Testing with Custom SetText Keyword in Katalon

But before we dive into the topic, let us first see what Katalon is.

What is Katalon?

katalon

Katalon Studio is a software for automation testing created by Katalon, Inc. The software was initially released in January 2015. It is built on top of the open-source automation frameworks Selenium and Appium with a specialised IDE interface to test desktop, mobile, web and APIs.

Now let us look into some background details before we start with the topic.

Background Details

Many applications are built daily for different platforms, such as Android, Windows, macOS, iOS, Linux and the web. But have you ever wondered how they are coded, which language is used to code them, and which code editors are used for this purpose? Don't worry! You are at the right place, and you will get the answer to these questions in this article. Today, we are going to have a look into a UI software development kit which Google created, known as Flutter.

In this tutorial, we will have a workaround to test the Flutter-based applications automatically. We can use Mobile keywords to automate our Flutter-based application. We need to use Appium Flutter Driver in order to set up Katalon Studio for Flutter-based app mobile automated testing.

Setting up Appium Flutter Driver

We need Appium Flutter Driver to set up Katalon Studio for Flutter-based application's mobile automated testing. This driver is part of the Appium mobile test automation tool, which is maintained by the community.

We can download or clone Appium Flutter Driver at Appium's repository on GitHub: Appium Flutter Driver.

We need to follow these instructions to use Appium Flutter Driver at Katalon Studio:

  • Flutter App Under Test (AUT) should be compiled in profile or debug mode because Flutter Driver doesn't support running in release mode.
  • Before runApp in the source code, your Flutter AUT has enableFlutterDriverExtension().


Follow these steps to let Katalon Studio run with Appium Flutter Driver:

1. Go to Project Settings > Desired Capabilities > Mobile.

mobile


2. Select iOS or Android, then create any desired capabilities whose value is Flutter.

android

Run a Flutter-based application test with the custom SetText keyword

1. Open the project and create a new test case.

new test case

2. Now, Record the mobile testing script. Use the Tap keyword on the elements EditText - Email and EditText - Password, and click Save.

mobile recorder

3. Navigate to the Keywords folder creating a new keyword package.

keyword

4. Give the name to the package. Create a new keyword named SetTextKeyword after right-clicking on the created package.

package

 

5. Copy and paste the following code and save it in SetTextKeyword.groovy file.


SetTextKeyword.groovy -> Snippet

package ...
import ...
.
.
.
@Action(value = "setText")
public class SetTextKeyword extends MobileAbstractKeyword {

	@CompileStatic
	@Override
	public SupportLevel getSupportLevel(Object ...params) {
		return super.getSupportLevel(params)
	}

	@CompileStatic
	@Override
	public Object execute(Object ...params) {
		TestObject testObjectVar = getTestObject(params[0])
		String textVar = (String) params[1]
		int timeout = (int) params[2]
		FailureHandling flowControl = (FailureHandling)(params.length > 3 && params[3] instanceof FailureHandling ? params[3] : RunConfiguration.getDefaultFailureHandling())
		setText(testObjectVar,textVar,timeout,flowControl)
	}

	@CompileStatic
	public void setText(TestObject testObjectVar, String textVar, int timeout, FailureHandling flowControl) throws StepFailedException {
		MobileKeywordMain.runKeyword({
			KeywordHelper.checkTestObjectParameter(testObjectVar)
			timeout = KeywordHelper.checkTimeout(timeout)
			WebElement elementVar = findElement(testObjectVar, timeout * 1000)
			if (elementVar == null) {
				MobileKeywordMain.stepFailed(MessageFormat.format(StringConstants.KW_MSG_OBJ_NOT_FOUND, testObjectVar.getObjectId()), flowControl, null, true)
				return
			}
			elementVar.clear()
			try {
				elementVar.sendKeys(textVar.toString())
			} catch (InvalidElementStateException e) {
				AppiumDriver driver = MobileDriverFactory.getDriver()
				elementVar.click()
				KeyInput keyInVar = new KeyInput("keyboard");
				Sequence sendKeys = new Sequence(keyInVar, 0);

				for (int loopVar = 0; loopVar < textVar.length(); loopVar++) {
					String c = textVar.charAt(loopVar).toString()

					sendKeys.addAction(keyInVar.createKeyDown(c.codePointAt(0)));
				}

				driver.perform(Arrays.asList(sendKeys));
			}
			String stringReadableText = SeleniumKeysUtil.getReadableText(textVar)
			logger.logPassed(MessageFormat.format(StringConstants.KW_LOG_PASSED_TEXT_HAS_BEEN_SET_TO_ELEMENT, [stringReadableText, testObjectVar.getObjectId()] as Object[]))
		}, flowControl, true, testObjectVar != null ? MessageFormat.format(StringConstants.KW_MSG_FAILED_TO_SET_ELEMENT_TEXT, testObjectVar.getObjectId()) : StringConstants.KW_MSG_FAILED_TO_SET_ELEMENT_TEXT)
	}
}

 

6. Select Window and then click on Reset Perspective in the toolbar.

reset perspective


7. Create a Test Case and change to Script mode. Enter "Mobile." and select as shown in the image below, and run the test case.

select

How to switch contexts?

Katalon gives us two keywords that help to switch contexts:

  • Switch to Native
  • Switch to WebView


Sample code for automating the elements of the application:

Mobile.switchToWebView()
DriverFactory.changeWebDriver(MobileDriverFactory.getDriver())
TestObject cdmDetails = new TestObject()
cdmDetails.addProperty("id", ConditionType.EQUALS, "100")
WebUI.setText(cdmDetails, "999")
Mobile.switchToNative()

Frequently Asked Questions

What is Katalon Studio?

Katalon Studio is an automation testing tool created by Katalon. The software is an open-source automation framework.

Is Katalon easy to learn?

Katalon Studio is an automation tool that does not require any advanced knowledge of programming. It offers a scripting mode for advanced automation.

Does Katalon use Selenium?

Katalon Studio is a test automation kit that uses Selenium's core engine. 

Is Katalon Studio free to use?

Yes, Katalon has a free version for use. Katalon also provides a paid version.

Conclusion

In this article, we discussed the Flutter-based application testing with the custom SetText keyword in Katalon. We hope this blog on Flutter-based application testing with the custom SetText keyword in Katalon was helpful. You can also refer to other similar articles.


You may refer to our Guided Path on Code Studios for enhancing your skill set on DSACompetitive ProgrammingSystem Design, etc. Check out essential interview questions, practice our available mock tests, look at the interview bundle for interview preparations, and so much more!

Happy Learning Ninja!

Live masterclass