How to combine mobile and web test cases

Hi,

I have been using Katalon for a couple days now for both writing mobile and web tests. Most of my use cases depend on a combination of the two, where a user logs in on mobile device, does some actions that generate a CTA for an admin user to approve/reject via web. I can run both test cases independently and all goes well, but I’m looking for a way to combine them. I can think of 2 options how to do so:

  1. Have 1 test that first runs the mobile part, followed by the webui test.
  2. have 2 separate tests and place them in a test suite so first test A runs and after that test B

The problem is that I need some way to configure the testcases to appoint how to run them (Mobile is running on emulator in android studio and webui is running on chrome).

Any idea’s on how I can achieve this?

Thanks in advance,
Ronald

1 Like

Hi @ronald1,

Welcome to our community. There are a lot of experienced people here willing to help you

@ronald1

Possibly you can make a Test Case of option1 type that first runs the mobile part followed by the webui test.

  1. You would create a Test Case TC0 for mobile part only, without any webui part

  2. You would choose “Android emulator” to run the TC0 with

  3. Later you want to edit the TC0. You want to add the webui part.

  4. You should know a thing: You do not necessarily have to use WebUI.openBrowser() to open a browser. There is an alternative way to open a browser programatically

  5. The only question is how the TC0 can instanciate a ChromeDriver = how it can open Chrome browser and continue interating with the Chrome browser using WebUI.* keywords.

You can do it. See the following post:

You would call new ChromeDriver(options) in the TC0. TC0 will open a Chrome browser window. You want to call DriverFactory.changeWebDriver(driver). This will make all successive calls to WebUI.* keywords to interact with the Chrome opened by new ChromeDriver() call.

Please note: You would run the TC0 with choosing Android emulater. You can forget Chrome when you start the TC0. Regardless which Driver type you chose in the Katalon Stuio GUI, TC0 will launch Chrome by calling new ChromeDriver() explicitly.

Possibly you want to create another Test Case TC1 that does all the webui part.

The TC0 can invoke TC1 as soon as it finishes the mobile part. TC0 will use WebUI.callTestCase() keyword.

You should modularize your code as much as possible, as it will make your life easier.

I have made a demo project and published it in GitHub:


This project shows a single Test Case script that executes a Mobile test first followed by a WebUI test in a sequence.

This project was derived from the Katalon’s sample project

This project was developed using Katalon Studio v9.3.1.

Problem to solve

The original poster wanted to write a Test Case script that execute a Mobile test first followed a WebUI test. However he wondered:

  • How to choose Android rather than iPhone to run his Mobile test.

  • How to choose Chrome on PC rather than Firefox or Edge to run his WebUI test.

Katalon Studio is not designed with such usecases in mind. Katalon Studio requires us choose a single browser to run a Test Case with. We can choose Chrome for a WebUI test; we can choose Android for a Moble test. But the original poster wants both of Chrome and Android for a single Test Case.

choosing browser

How is it possible?

Solution proposed

A Test Case should open a Chrome browser using the WebDriver API without calling the Katlaon built-in WebUI.openBrowser keyword.

Description

Combinator test case

I made a Test Case Combinator:

// run Mobile test
Mobile.callTestCase(findTestCase("Verify Last Items In List"), null)

// run WebUI test while launching PC Chrome browser explicitly without calling WebUI.openBrowser('')
WebUI.callTestCase(findTestCase("Verify Login CURA System - PC Chrome Browser"), null)

The Combinator combines two scripts in a sequence. It calls a Mobile test first, and soon after that it calls a WebUI test.

I would launch the Combinator while choosing Android. I would not mind Chrome here.

choose Android

The Combinator Test Case successfully worked for me. It ran a Mobile App on my Android phone, and after that it opened Chrome browser and visited http://demoaut.katalon.com .

Mobile test

The Verify Last Items In List is just the same as the Katalon’s demo project. I made no change.

WebUI test

The Verify Login CURA System - PC Chrome Browser is derived from Verify Login CURA System Successfully - Mobile Browser. I modified the script as follows:


//WebUI.openBrowser(GlobalVariable.G_SiteURL)

// We want to launch PC Chrome browser explicity
System.setProperty("webdriver.chrome.driver", "/Applications/Katalon Studio.app/Contents/Eclipse/configuration/resources/drivers/chromedriver_mac/chromedriver")
WebDriver driver = new ChromeDriver()
DriverFactory.changeWebDriver(driver)
WebUI.navigateToUrl(GlobalVariable.G_SiteURL)

  1. I commented out the line of WebUI.openBrowser keyword.

  2. I launched Chrome browser using ChromeDriver API.

By this change, the Verify Login CURA System - PC Chrome Browser script will ALWAYS run with Chrome browser regardles which type of browser I chose when I start the test case. Even if I chose Android, the Verify Login CURA System - PC Chrome Browser will run with PC Chrome.

The problem is resolved.

Applicability

This project proved that we can write a Test Case that performs Mobile testing and WebUI testing combined. Katalon Studio is not designed to support such unusual cases. The trick is that the Test Case should open a PC browser using the WebDriver’s native API without using WebUI.openBrowser keyword.

I could find other topics in the Katalon forum that wants a way to combine WebUI testing and Mobiel/Desktop testing.

The same solution will apply to these cases as well.

I can imagin a code Test Cases/CombinatorUsingExtendedKeyword which uses callTestCase with a new method signature:

(Please note, the following code will NEVER work! I just hoped it.)

import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase

import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.webui.driver.WebUIDriverType as DriverType
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

/**
 * "Test Cases/CombinatorUsingExtendedKeyword"
 */

// run Mobile test
Mobile.callTestCase(findTestCase("Verify Last Items In List"), null)

// run WebUI test with Chrome
WebUI.callTestCase(DriverType.CHROME_DRIVER, findTestCase("Verify Login CURA System Successfully - Mobile Browser"), null)

Please find that WebUI.callTestCase(DriverType.CHROME_DRIVER, ..." accepts the type of WebDriver as the 1st argument. In the above code snippet, I specified DriverType.CHROME_DRIVER for the Test Case “Verify Login CURA System Successfully - Mobile Browser”. The first argument DriverType.CHROME_DRIVER would play a role just the same as the case where I chose Chrome in the Katalon GUI to run the test case script with.

I hope this code to work. This code looks clean. It clearly illustrates what I want to do.

@kazurayam

Thanks, that did the trick. Had to change the path and variable names, but in the end it worked perfectly!