Katalan Studio cannot see the notifications that appear on the screen as a toaster. I have tried all methods in various ways, but to no avail. What is the solution? Please help.
Hi,
Thank you for sharing your issue. Can you please help share any error log if you have and the ways you have tried? Thank you
I just want to add to Elly’s post above that to receive the best possible support from other members, and our team, here on the forum, you should include as much information in your topic as possible i.e. screenshots, videos, error log, information about your machine/OS, etc.
Please refer to the topic below for more information
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import static com.kms.katalon.core.testobject.ObjectRepository.findWindowsObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testng.keyword.TestNGBuiltinKeywords as TestNGKW
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.windows.keyword.WindowsBuiltinKeywords as Windows
import internal.GlobalVariable as GlobalVariable
import org.openqa.selenium.Keys as Keys
import io.appium.java_client.AppiumDriver as AppiumDriver
import com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactory as MobileDriverFactory
AppiumDriver<?> driver
try {
driver = MobileDriverFactory.getDriver()
}
catch (Exception startApp) {
Mobile.startExistingApplication(‘com.geniustags.geniusvoucher’, FailureHandling.STOP_ON_FAILURE)
driver = MobileDriverFactory.getDriver()
}
Mobile.tap(findTestObject(‘GV/BurgerMenu’), 0)
Mobile.tap(findTestObject(‘GVNew/Menu - Format card’), 0)
Mobile.waitForElementPresent(findTestObject(‘GVNew/Toast - cardChipUidPermission denied, you do not have access to this project’),
0)
Test Cases/Genius-Voucher-App-New/Format card/Format previously formatted card FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: Failed to wait for element present (Root cause: org.openqa.selenium.StaleElementReferenceException: Cached elements ‘By.xpath: //hierarchy/android.widget.Toast[1][count(. | //[@class = ‘android.widget.Toast’ and (@text = ‘{“cardChipUid”:[“Permission denied, you do not have access to this project.”]}’ or . = ‘{“cardChipUid”:[“Permission denied, you do not have access to this project.”]}’)]) = count(//[@class = ‘android.widget.Toast’ and (@text = ‘{“cardChipUid”:[“Permission denied, you do not have access to this project.”]}’ or . = ‘{“cardChipUid”:[“Permission denied, you do not have access to this project.”]}’)])]’ do not exist in DOM anymore
The first issue I see is you have never looked at your Task Manager because if you have, you would see that your machine is doing a LOT of other tasks beside just the one you want. Saying that, change your “int TIMEOUT” on all your statements to some number that is more appropriate than zero.
As an example, for the above quoted statement, you could try:
Mobile.tap(findTestObject('GV/BurgerMenu'), 5)
and carrying on:
Mobile.tap(findTestObject('GVNew/Menu - Format card'), 5)
Mobile.waitForElementPresent(findTestObject('GVNew/Toast - cardChipUidPermission denied, you do not have access to this project'), 5)
Edit: These statement will not take 5 seconds to run, but will time out after 5 seconds–so after 5 seconds, if the tap does not work, then you get an warning/error (whatever you have the default FailureHandling set at). This is what you want. Your statements as they are above time out immediately, which is probably why it/they don’t run.
Edit2: I personally set my “timeOut” at ten (10).
Thanks for helping
I attempted this solution, but the warning persisted: “Object ‘Object Repository/GVNew/Toast - cardChipUidPermission denied, you do not have access to this project’ not found,” even though this notification appeared.
In your previous post, you have the image on how you detect your object. May I suggest that you change it to have Condition as “contains” instead of “equal” and then shorten the text to something like “Permission denied” or “you do not have access”.
See if that does anything.
I would also use Rename and shorten the length of the element’s name to just “Object Repository/GVNew/Toast - cardChipUidPermission denied”
Edit: This is on the below element:
I tried all the solutions and it didn’t work unfortunately
VALIDATE THE TOAST MESSAGE PRESENTS!
def isToast= MobileDriverFactory.getDriver().findElementByXPath(('//android.widget.Toast[@text='’ + ToastMessage) + ‘']’)
Mobile.takeScreenshotAsCheckpoint(‘CheckToastMessage’, null)
Mobile.comment("Toast Message Presented ? $isToast ")
if (isToast == null)
{
KeywordUtil.markFailed(‘ERROR: Toast object not found!’)
}
Hope it helps!
I hope this block of code will help you to verify the notification return as a toast message
AppiumDriver driver = MobileDriverFactory.getDriver()
def Actual_ToastMessage = driver.findElementByXPath(‘//android.widget.Toast[1]’).getText()
def Expected_ToastMessage =“Permission denied, you do not have access to this project.”
Mobile.verifyMatch(Actual_ToastMessage, Expected_ToastMessage, false, FailureHandling.STOP_ON_FAILURE)
if there is multiple toast message in the activity use the following and give the exact notification you are receiving from the activity in the ToastMessage part
def Actual_ToastMessage= driver.findElementByXPath (('//android.widget.Toast[@text=‘’ + ToastMessage) + ‘’]’ )