I am trying to catch unexpected events in the background of a mobile app and decided to create a separate thread that would wait for that event to occur using the Mobile.waitForElementPresent keyword. I would start the application in the main thread, and then create a new thread right after that would wait for the events to occur. Whenever I run the program, I get this error.
Exception in thread "Thread-14" com.kms.katalon.core.exception.StepFailedException: No driver found
at com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords$waitForElementPresent$0.call(Unknown Source)
Is there any way I can use Mobile keywords on the application I already started, within the newly created separate thread?
Here is the run method for the thread I am creating.
I do not think that the Thread you newly created can get access to the Appium Driver instance created by your Test Case thread. The driver is only accessible for the current thread of the Test Case script itself. The driver is not accessible for other Threads.
How do I know it? I will tell you.
You can read the source code of MobileScreenCapter.getAnyAppiumDriver at
@kazurayam Thanks for the response, I thought that would be the case. Would there be any other way to run multiple Mobile keywords at the same time? E.g. Waiting for an element to show using Mobile.waitForElementPresent in the background of a test case while that test case continues on as normal. I basically need to check if an unexpected element appears while I am running a normal test case.
Are you concerned that Mobile.waitForElementPreset runs very slow?
Yes, there are many post about the slowness of Mobile keywords. For example,
The speed of keyword largely depends on how the locator expression in TestObject is written. In many cases you can find some alternative expressions that run much faster. How to write faster locators? — That is a question to be studied case-by-case. There is no silver bullet.
Sorry, I am not experienced with Mobile testing. If you want to find out a way to make your Mobile tests run faster, you should ask Mobile testing experts (@Chris_Trevarthen and others) for advices.
Do you mean by this “sharing an instance of driver by multiple threads”? As I wrote, it is NOT possible, as the KS stores the driver instance is ThreadLocal.
Alternative approach could be creating 2 instances of of drivers at the same time. I have ever demonstrated a test case for WebUI. See
I proved that I can open a single URL in 2 browser windows simultaneously and do 2 sets of assertions on each windows. This approach would help you organising codes packed per target web pages; a bit easier to read.
Please note this example does assertions sequentially, one by one. It does not perform parallel things at all. So this approach does not make processing faster.
Sorry, I do not know if it is possible for Mobile as well.
It seems you want Mobile.asyncWaitForElementPresent which works asynchronously. You want to register a Groovy Closure as a callback, and timeout. As you know, all of KS built-in keywords are synchronous. There is no async type of keyword. That is something completely new. I have no idea if its feasible in KS or not.
I suppose that Image comparison is an alternative approach to check if anything UNEXPECTED happened. You want to take screenshots twice: before “normal test case” and after “normal test case”. And then create “diff” between the 2 images, with which you would find unexpected things if any.