Switch Fragment Android

Hi everyone,
I have a problem to do automation testing. I want to use scrollToText in mobile Android aps, but the part of scrolling is different fragment with parent page. How can I switch fragment and apply the scrollToText in the element?

1 Like

Hi there,

Thank you very much for your topic. Please note that it may take a little while before a member of our community or from Katalon team responds to you.

Thanks!

Hi there @poibematondang30, :wave:

Welcome to our forum!

Did you know, that we are currently running our quarterly Ask Katalon Anything (AKA) activity on the forum? From now till 2024-06-19T16:59:00Z, feel free to ask our Product Support team any Katalon-related questions about setting up & optimize Katalon for your projects, alongside best practices for Web/Mobile/API Testing.

Join AKA by visiting the thread below (simply copy and paste your question in the thread) :point_down:

Hi @poibematondang30,

Welcome to our community.

  1. you will need to choose a Fragment Switch way:
  • If using AndroidX Navigation, leverage Katalon Studio’s built-in navigation keywords like “Navigate Back” or specific navigation commands based on your app’s implementation.
  • If the app uses custom logic for fragment transitions, you might need to identify and interact with the elements triggering the fragment switch. Use Katalon Studio’s Mobile Keywords like “Tap” or “Click” on the appropriate UI elements that initiate the fragment change.
  1. Verify Fragment Switch (Optional)
  • Consider adding a verification step to ensure the fragment has transitioned successfully. Use Katalon Studio’s Mobile Keywords like “Verify Element Is Present” to check for specific elements that appear only in the new fragment.

Then you can start use scrollToText for your element

Example

// Navigate to the fragment that contains the scrollable content (if necessary)
MobileKeywords.navigateToYourFragment()

// Optional verification (replace with your element locator)
MobileKeywords.verifyElementIsPresent(FindTestObject('YourNewFragmentElement'))

// Find the scrollable container (replace with your element locator)
mobileElement = MobileKeywords.findElement(FindTestObject('ScrollableContainer'))

// Optional wait for element (adjust timeout as needed)
MobileKeywords.waitUntilNotStale(mobileElement, 5)

// Calculate scroll offset or use smaller swipes in a loop until target is visible
MobileKeywords.swipeVertical(mobileElement, 100) // Adjust swipe value as needed

// Verify target element is visible (replace with your element locator)
MobileKeywords.verifyElementIsVisible(FindTestObject('YourTargetTextElement'))

Thank you @Elly_Tran,

I have tried this code, but I got the same issue, the scroll feature doesn’t work yet…

Hi,

Please help provide the error log or screenshot