Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Textfield.typeText occasionally inputs wrong value #29

Open
Danbown opened this issue May 22, 2020 · 5 comments
Open

Textfield.typeText occasionally inputs wrong value #29

Danbown opened this issue May 22, 2020 · 5 comments

Comments

@Danbown
Copy link

Danbown commented May 22, 2020

Hi Chris
firstly, fantastic addition for Mobile testing, this has saved me a lot of hassle.
I have an issue where value entered from 'typeText' does not always match expected result though.

This result is not consistent - I would say about 20% of the time today it has given wrong result (I did restart mobile phone by the way).

My element by xpath is '//android.view.ViewGroup[@content-desc="Have previous survey details been reviewed?"]/android.view.View'.

I use the following code (I cannot implement your object repository layout with this project):

TestObject havePrevSurveys = findTestObject('SummaryPage/txtHavePreviousSurveysBeenReviewed')

TextField.typeText(havePrevSurveys, reviewPreviousSurveys, 0).

The variable 'reviewPreviousSurveys' takes a value of 'Yes'. For this example the picker has values of blank, Yes and No. Sometimes it skips past Yes to next value. I have also tried a delay of 2 seconds before this step. The element is clearly on the screen.

Would appreciate any advice. In the meantime I will repeat the step with If statement if I see an odd result.
Regards
Dan

@ctrevarthen
Copy link
Contributor

Hi Dan, thanks for reaching out.

typeText works best for typing text into a TextView, so I'm thinking that in your case, using a text field with a picker might be more applicable. Here's the section of the README that talks about that: https://github.com/detroit-labs/katalon-mobile-util#using-a-textfield-with-a-picker-list

If that doesn't work, there is some logging that you can turn on to see what's going on. Check out this section on logging in the util: https://github.com/detroit-labs/katalon-mobile-util#logging

If you can send me that log file, it might help troubleshoot further.

  • Chris

@Danbown
Copy link
Author

Danbown commented May 27, 2020

Hi Chris
I have the following code in my script:
import com.detroitlabs.katalonmobileutil.logging.Logger as Logger
import com.detroitlabs.katalonmobileutil.logging.Logger.LogLevel as LogLevel
Logger.initialize("tmp\katalon.log", LogLevel.DEBUG)
Logger.debug('This DEBUG message will be logged to the file.')
Logger.info('This INFO message will be logged to the file.')
Logger.warn('This WARN message will be logged to the file.')
Logger.error('This ERROR message will be logged to the file.')
Logger.fatal('This FATAL message will be logged to the file.')

I run the script but all I get is a file with this:
Initializing log: 2020-05-27 12:31:44 with logging level: DEBUG
[DEBUG] 2020-05-27 12:31:44: This DEBUG message will be logged to the file.
[INFO] 2020-05-27 12:31:44: This INFO message will be logged to the file.
[WARN] 2020-05-27 12:31:44: This WARN message will be logged to the file.
[ERROR] 2020-05-27 12:31:44: This ERROR message will be logged to the file.
[FATAL] 2020-05-27 12:31:44: This FATAL message will be logged to the file.
I am currently running KS, rather than KSE if this makes a difference.

A screenshot of the application is below:
image
The orange label points to the 'view.View' element I want to set to a value for eg 'Yes'.
The user would normally click the dropdown to see this picker.
They then move the picker to set focus on the value (between the lines shown). This is the green callout shown.
They then click the dropdown again to keep the selection, at which point the 'view.View' element changes to 'text'='Yes'.
The blue callout is the 'picker' xpath.

I used 'typeText' to try to set the value directly in the 'view.View' element. What this does is replicate clicking the dropdown (to see option), scroll, move the picker options to a choice. The problem that I faced was that choices made were inconsistent - the list would scroll but not always choose right value.
When I tried 'TextField.selectOption' instead of 'typeText', the picker options were displayed but no selection was made - the picker did not scroll at all.

I also tried to make the selection by changing the element indicated with the green callout. This did not scroll the list at all either. The green callout points to a 'widget.button' Android class.

I'm unsure whether I need to try to make the 'widget.button' value change, or the 'view.View' value.
Thanks Dan

@ctrevarthen
Copy link
Contributor

Hi Dan, thanks for the details!

Sorry if I missed this part, but have you tried creating the TestObject from //android.view.ViewGroup[@content-desc="Have previous survey details been reviewed?"]/android.widget.TextView (the text field specifically) and using TextField.typeText or even the Katalon built-in Mobile.setText on that? It might not work if the TextView is static text, but it could be worth a shot.

In the meantime, I'll look into ways to add more debugging to the calls you're trying, so we can log out what's going on.

@Danbown
Copy link
Author

Danbown commented May 28, 2020

Hi Chris
I think you have solved it! Thank you for the advice - I will also trial with a more complex page with more dropdown options but experimenting with using Textfield.typeText against what I assumed were just static labels (android.widget.TextView) has given the right result. Just to mention as well, Mobile.setText was tried but unsuccessful but I'm more than happy to use the custom option. Thanks again, Dan

@ctrevarthen
Copy link
Contributor

Glad to hear it, Dan!

Mobile.setText has been flaky in my experience, so I wasn't sure if it would work. Mobile.sendKeys is a little more reliable, but it requires the field to have been tapped and the keyboard to be open. The underlying code for TextField.typeText uses Mobile.sendKeys, and does those steps for you, if you provide a text input type of object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants