Hi Community members,
With the recent release of Katalon Studio 10.0.0 which adopts Selenium 4 and Java client 9.2.3, we’ll be publishing several KShare articles to help you take advantage of this latest release in your projects.
For our first article relating to KS 10.0.0, we’ll show you how to ensure your mobile test scripts are aligned with the latest updates. Read more below
Enhancing the Swipe keyword
To resolve issues relating to Swipe in Katalon Studio 10.0.0, verify that the following mobile drivers are already installed on your system:
- Appium UiAutomator2 Driver (version 3.7.0 or higher) for Android
appium driver install uiautomator2
- Appium XCUITest Driver (version 7.21.1 or higher) for iOS
appium driver install xcuitest
To check the appium drivers installed in your machine, you can just run the command “appium driver list “ in a terminal/CMD
Java client v9 refactor
Appium Java Client v9.2.3 fully supports the W3C WebDriver standard. This means that the Previously JWP-based servers are no longer supported.
Actions required:
- Replace all uses of
JSON Wire Protocol
with the correspondingW3C Protocol
Method 1: AppiumDriver and AndroidDriver
Before (Katalon Studio 9.x):
- The way to initialize the AppiumDriver
import io.appium.java_client.AppiumDriver
AppiumDriver<?> driver = MobileDriverFactory.getDriver()
- The way to initialize the AndroidDriver
import io.appium.java_client.android.AndroidDriver
AndroidDriver<?> driver = MobileDriverFactory.getDriver()
After (Katalon Studio 10.x):
import io.appium.java_client.AppiumDriver
AppiumDriver driver = MobileDriverFactory.getDriver()
Method 2: Mobile Element
Before (Katalon Studio 9.x):
The use of MobileElement:
import io.appium.java_client.MobileElement
import io.appium.java_client.MobileBy
import io.appium.java_client.MobileDriver
MobileElement startelement = driver.findElementByXPath("xxx")
After (Katalon Studio 10.x):
- Using the WebElement method instead of the MobileElement
import org.openqa.selenium.WebElement
import org.openqa.selenium.By
WebElement startelement = driver.findElement(By.xpath("xxx"))
Method 3: Touch Action class
Before (Katalon Studio 9.x):
import io.appium.java_client.MultiTouchAction
import io.appium.java_client.TouchAction
import io.appium.java_client.touch.offset.PointOption
MultiTouchAction multiTouch = new MultiTouchAction(driver)
TouchAction action1 = new TouchAction(driver)
.press(PointOption.point(100, 500))
.waitAction(WaitOptions.waitOptions(Duration.ofMillis(500)))
.moveTo(PointOption.point(100, 100))
.release()
.perform();
After (Katalon Studio 10.x):
- Using the PointerInput method to perform the action
import org.openqa.selenium.interactions.Pause
import org.openqa.selenium.interactions.PointerInput
import org.openqa.selenium.interactions.Sequence
/* This line creates a new PointerInput object called finger.
* The Kind.TOUCH indicates that this input will simulate touch events (like a finger on a touchscreen).
* The second parameter, "finger", is an identifier for this input.
*/
PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, "finger");
/* A Sequence is created to define a series of actions that will be performed in order.
* The 2 indicates that this sequence is for the second pointer input (if there are multiple).
*/
Sequence sequence = new Sequence(finger, 2);
/*
* This action moves the pointer immediately (0 milliseconds delay) to the coordinates (100, 500) relative to the viewport.
*/
sequence.addAction(finger.createPointerMove(Duration.ofMillis(0), PointerInput.Origin.viewport(), 100, 500));
/*
* This action simulates pressing down on the screen at the current pointer location (100, 500).
*/
sequence.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg()));
/*
* This action moves the pointer to a new location (100, 100) over a duration of 500 milliseconds, simulating a drag gesture.
*/
sequence.addAction(finger.createPointerMove(Duration.ofMillis(500), PointerInput.Origin.viewport(), 100, 100));
/*
* This action simulates lifting the finger off the screen at the new location (100, 100).
*/
sequence.addAction(finger.createPointerUp(PointerInput.MouseButton.LEFT.asArg()));
/*
* Finally, the perform method is called on the driver (which represents a browser session).
* It executes the sequence of actions that were defined, simulating the touch interactions on the web page.
*/
driver.perform(Collections.singletonList(sequence));
References
Sample Project
If you find this article helpful, then don’t forget to leave a like or a heart and share it with your colleagues! Your support for the KShare series is greatly appreciated!