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

clear the value in webview element #53

Closed
atcrao opened this issue Jun 12, 2012 · 14 comments
Closed

clear the value in webview element #53

atcrao opened this issue Jun 12, 2012 · 14 comments

Comments

@atcrao
Copy link

atcrao commented Jun 12, 2012

Hi,

I had to clear the login name in the webview and then enter the valid name.

I created a step that invokes action(key) "set_text" or "enter_text_by_selector" and passed an empty string as "". But this doesn't clear the login element.

Should there be a new action defined in instrumentation_backend to clear the value for elements in webview similar to ClearTextByIndex.java or ClearTextFieldByContentDescription.java or can the existing set_text/enter_text_by_selector action be fixed to clear the value of an element.

Thanks.

@jonasmaturana
Copy link
Contributor

I will change the step so that it clears the input field before entering text. That means that if you enter an empty string it will only clear the field.

@jonasmaturana
Copy link
Contributor

I just released calabash-android-0.0.16.
It clears the input field before entering text. That means you can write the following steps.

Given /^I clear the first input field$/ do
  set_text "webView, css:input[type=text]", ''
end

Given /^I enter "([^"]*)" into the first input field$/ do |text|
  set_text "webView, css:input[type=text]", text
end

@atcrao
Copy link
Author

atcrao commented Jun 14, 2012

Please help me understand, I am also new to cucumber.
Looking at the above step, shouldn't I provide css locator as an input.

Given /^I enter "([^"])" into the input field "([^"])" $/ do |text, locator|
set_text "webView, css:locator", text
end

For example:- Given I enter "abc@gmail.com" into the input field "input#email"

@jonasmaturana
Copy link
Contributor

This should work if you want to give the css selector as an argument.

Given /^I enter "([^"])" into the input field "([^"])" $/ do |text, locator|
  set_text "webView, css:#{locator}", text
end

However, it is more readable to do something like:

Given /^I enter "([^"])" as email" $/ do |email|
  set_text "webView, css:input#email", email
end

That way you keep your test in a business language without exposing technical details.

@atcrao
Copy link
Author

atcrao commented Jun 15, 2012

Thank you . This works as desired
Given /^I enter "([^\"]*)" as email$/ do |email|
set_text "webView, css:input#email", email
end

But the below step doesn't clear the input field. I still see the old text exists in email field.
Given /^I clear the first input field$/ do
set_text "webView, css:input#email", ''
end

I did install the latest gem and I unpacked the gem and noticed the set_text(uiquery, txt) method is defined operations.rb.

@atcrao
Copy link
Author

atcrao commented Jun 15, 2012

Continuation...
Jonas, it will be great if the logic to clear the text field in web view works. Currently I am not able to test any end-to-end webview flows as the signin itself fails.
Thanks in advance.

@jonasmaturana
Copy link
Contributor

Did you update calabash-android to 0.0.17? It should clear the text field.

Run gem update calabash-android to update.

@atcrao
Copy link
Author

atcrao commented Jun 15, 2012

Yes, I do have 0.0.17.

The non-empty string works-
Given I enter "pp1@gmail.com" as email

The below empty string doesn't work-
Given I clear the first input field
Given I enter "" as email

The step definition are defined as you described:-
Given /^I clear the first input field$/ do
set_text "webView, css:input#email", ''
end

Given /^I enter "([^\"]*)" as email$/ do |email|
set_text "webView, css:input#email", email
end

@jonasmaturana
Copy link
Contributor

Does this work as expected?

Given I enter "foo" as email
Given I enter "bar" as email

@atcrao
Copy link
Author

atcrao commented Jun 16, 2012

Yes, it worked.
The only time it doesn't work is when I give ""

@jonasmaturana
Copy link
Contributor

Just to be sure. After you you run the to steps above the input field has the value "bar", right?

What about entering a single space into the field?

It might have something to do with a listener on the field in your app. Do you know if there is such a listener?

@atcrao
Copy link
Author

atcrao commented Jun 18, 2012

There is email-id already populated in the username field. When I enter the value "bar" then the "bar" is appended to the already existing text.
For example:- The username field is pre-populated with value "abc@yahoo.com", and when I invoked the step 'Given I enter "bar" as email', the value in username field is changed to "abc@yahoo.combar"

When I entered a single space into the field via the step 'Given I enter " " as email' then I noticed the username field is appended with single space "abc@yahoo.com "

My original request for filing this issue is to clear the content in the username field before entering a new username.

I will get back to you regarding the listener.

@jonasmaturana
Copy link
Contributor

There seem to have been a bug in 0.0.16 so that the text is not cleared. Could you try to update to 0.0.18?

@atcrao
Copy link
Author

atcrao commented Jun 19, 2012

Thanks a lot. It works after upgrading to 0.0.18.

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