SetText/SendKeys

Hi, I’m hoping that perhaps someone could guide me in the direction of overcoming my current issue. Still relatively new to automated testing, I’m trying to get a simple log in, log out script working. However, when running the test case in Katalon, Appium is not able to recognize an element/object and enter text into it appropriately. When recording it is able to do so, but not when ran in a test. Is there a suggestible method I could use?

Captured Object Name: android.widget.EditText1 - Password

Object Properties:

class android.widget.EditText

instance 1

text Password

checkable false

checked false

clickable true

enabled true

focusable true

focused false

scrollable false

long-clickable true

password true

selected false

x 81

y 449

width 917

height 118

Hi Kyle, can you share your test code as well?

Thanks,

Chris

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 com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint

import com.kms.katalon.core.checkpoint.CheckpointFactory as CheckpointFactory

import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as MobileBuiltInKeywords

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.testcase.TestCaseFactory as TestCaseFactory

import com.kms.katalon.core.testdata.TestData as TestData

import com.kms.katalon.core.testdata.TestDataFactory as TestDataFactory

import com.kms.katalon.core.testobject.ObjectRepository as ObjectRepository

import com.kms.katalon.core.testobject.TestObject as TestObject

import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WSBuiltInKeywords

import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUiBuiltInKeywords

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

import internal.GlobalVariable as GlobalVariable

import org.openqa.selenium.Keys as Keys

import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW

Mobile.startApplication(‘Downloads\\app.apk’, false)

Mobile.tap(findTestObject(‘android.widget.Button0 - ALREADY HAVE AN ACCOUNT’), 40)

Mobile.setText(findTestObject(‘android.widget.EditText0 - Email’), ‘e-mail@mail.com’, 40)

Mobile.setText(findTestObject(‘android.widget.EditText0 - Password’), ‘password’, 0)

Mobile.tap(findTestObject(‘android.widget.ImageView7’), 40)

Mobile.tap(findTestObject(‘android.widget.Switch0 - OFF’), 40)

Mobile.tap(findTestObject(‘android.widget.Button3 - LOGIN’), 40)

Mobile.tap(findTestObject('android.widget.Button0 - '), 40)

Mobile.tap(findTestObject(‘android.widget.TextView12 - Logout’), 40)

Mobile.closeApplication()

I’ve also tried using Mobile.tap at location to get the cursor to appear in the Password field and then sending SendKeys, but that didn’t work either. Coincidentally enough, recently my test did go through at the part that it keeps failing at, however, it then got stuck on the Login button.

Test Cases/LILO FAILED because (of) (Stack trace: com.kms.katalon.core.exception.StepFailedException: Failed to set text into element (Root cause: Object Object Repository/android.widget.EditText1 - Password not found)

at com.kms.katalon.core.keyword.internal.KeywordMain.stepFailed(KeywordMain.groovy:36)

at com.kms.katalon.core.mobile.keyword.internal.MobileKeywordMain.stepFailed(MobileKeywordMain.groovy:40)

at com.kms.katalon.core.mobile.keyword.internal.MobileKeywordMain.runKeyword(MobileKeywordMain.groovy:23)

at com.kms.katalon.core.mobile.keyword.builtin.SetTextKeyword.setText(SetTextKeyword.groovy:83)

at com.kms.katalon.core.mobile.keyword.builtin.SetTextKeyword.execute(SetTextKeyword.groovy:66)

at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:53)

at com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords.setText(MobileBuiltInKeywords.groovy:456)

at com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords$setText$1.call(Unknown Source)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:141)

at Script1541680637330.run(Script1541680637330.groovy:30)

at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:183)

at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:108)

at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:294)

at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:285)

at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:264)

at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:256)

at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:200)

at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:99)

at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:90)

at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:149)

at TempTestCase1542377797229.run(TempTestCase1542377797229.groovy:22)

at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:263)

at groovy.lang.GroovyShell.run(GroovyShell.java:518)

at groovy.lang.GroovyShell.run(GroovyShell.java:507)

at groovy.ui.GroovyMain.processOnce(GroovyMain.java:653)

at groovy.ui.GroovyMain.run(GroovyMain.java:384)

at groovy.ui.GroovyMain.process(GroovyMain.java:370)

at groovy.ui.GroovyMain.processArgs(GroovyMain.java:129)

at groovy.ui.GroovyMain.main(GroovyMain.java:109)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:109)

at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:131)

)

Test Cases/LILO.run:30

And this is a copy of the error text I receive when this particular step fails in the test case.

Failed to set text into element (Root cause: Object Object Repository/android.widget.EditText1 - Password not found)

Please share the definition of the Test Object ‘android.widget.EditText0 - Password’

What do you mean by the definition?

I mean the screenshot of the Test Object like this:

スクリーンショット 2018-11-19 23.34.18.png

Here you are. The strange thing is all of the commands go through fine when Recording and saving the test case. However, when I go to run the test case it can’t get past entering the password. It can’t seem to find the element.

screenshot1.PNG

Mobile.setText(findTestObject('android.widget.EditText0 - Email'),     'e-mail@mail.com', 40)
Mobile.setText(findTestObject('android.widget.EditText0 - Password'),    'password', 0)

You set the timeout for ‘android.widget.EditText0 - Password’ to be 0. Any reason?

Please try setting it to be 40.

Hi Kyle,

Although it can be flaky at times, I’ve don’t often see Katalon lying about things on the screen. I wonder if this a case where your keyboard is covering the password field? If it doesn’t appear to be the case, we’d need to know a bit more about what Katalon/Appium think is on your screen at the time.

Could you log out the XML contents of the screen and share them (strip out anything proprietary/confidential first)? You should be able to do that by putting the following import statements at the top of your test case:

import com.kms.katalon.core.logging.KeywordLogger
import com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactoryimport io.appium.java_client.AppiumDriver

Then in the code for your test, add the following right before finding the password field:

AppiumDriver<?> driver = MobileDriverFactory.getDriver()
KeywordLogger log = new KeywordLogger()
log.logInfo(driver.getPageSource())

When the test runs, you should see an entry in the Log Viewer for “Statement - log.logInfo(driver.getPageSource())” that shows the start of the XML for the screen. If you tap on it, you’ll see all of the XML for the screen on the right-hand pane. If you could copy and share that, I can help troubleshoot why the scrolling isn’t working. (I recommend putting it into a text editor first to remove any sensitive data, like package names, etc.)

Thanks,

Chris