All webview methods must be called on the UI thread error

4,351 views
Skip to first unread message

androidnewbie

unread,
Jul 20, 2012, 1:28:39 PM7/20/12
to calabash...@googlegroups.com
Hi,
I keep running into "All webview methods must be called on the UI thread" error in my predefined steps. Anyone knows what the cause could be ?

Jonas Maturana Larsen

unread,
Jul 21, 2012, 4:25:20 PM7/21/12
to calabash...@googlegroups.com
Which predefined steps are causing that error?

androidnewbie

unread,
Jul 22, 2012, 5:16:01 PM7/22/12
to calabash...@googlegroups.com
I was trying this out below. Somehow the dump_body_html works without problems, but I keep getting the must be called from UIThread error from click_by_selector:


Then
/^I press the button with id "([^\"]*)"$/ do | css|
  performAction('click_by_selector',css)
end

Then /^show the html source code$/ do
  performAction('dump_body_html')
end

androidnewbie

unread,
Jul 22, 2012, 5:17:20 PM7/22/12
to calabash...@googlegroups.com
P.S. I was using android4.0.3

Jonas Maturana Larsen

unread,
Jul 22, 2012, 5:19:23 PM7/22/12
to calabash...@googlegroups.com
Alright. I have to look into that.

Could you try a 2.3 emulator just to see if the problem is 4.0 related?

Thanks for the report,
Jonas

androidnewbie

unread,
Jul 23, 2012, 1:32:55 PM7/23/12
to calabash...@googlegroups.com
Hi, I found some java code under src/sh/calaba/instrumentationbackend/actions/webview. some have actions that are run under uithread, some dont.
I could try by changing some of the java code if I know what to change as well as how to rebuild...


thanks

Jonas Maturana Larsen

unread,
Jul 24, 2012, 4:50:40 PM7/24/12
to calabash...@googlegroups.com
It would be great if you want to give it a shot. I'm on vacation right now and that's why the response time is a bit high.

To build your own version of calabash-android follow the instructions here:

Sampo Niskanen

unread,
Aug 1, 2012, 4:06:20 AM8/1/12
to calabash...@googlegroups.com
Hi,

I ran into the same issue, getting the error message:

      Only the original thread that created a view hierarchy can touch its views. (RuntimeError)
      /home/samniska/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/timeout.rb:68:in `timeout'
      ./features/step_definitions/login.rb:22:in `/^I log in$/'
      features/my_first.feature:5:in `When I log in'

I modified PressByCssSelector.java and got it working by simply wrapping the webView.loadUrl call around

    InstrumentationBackend.solo.getCurrentActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
             // ...
        }
    });

This was copied from EnterTextByCssSelector.java.  I guess every action that uses the WebView should be wrapped like that.

Regards,
   Sampo N.

Jonas Maturana Larsen

unread,
Aug 1, 2012, 2:47:18 PM8/1/12
to calabash...@googlegroups.com
I'm fixing this right now.

Will test it tomorrow and probably release a new gem or at least push the changes to GitHub.

Are you guys all running on 4.0 devices or emulators?

- Jonas

Rama

unread,
Dec 18, 2012, 7:44:52 AM12/18/12
to calabash...@googlegroups.com
Hi

I ran into the same problem on my Galaxy Ace 2.3.6.  Need to post card details to submit the payment, but the test is failing to fill the test data with the below error.  but the same test is passing on Galaxy SIII 4.1.1.  could you please help me to sort out this issue

Thanks
Rama

Step unsuccessful: android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. (RuntimeError)
      /usr/lib/ruby/1.8/timeout.rb:67:in `timeout'
      ./features/screens/webview.rb:62:in `enter_postcode'
      ./features/screens/webview.rb:78:in `payment_details'
      ./features/screens/webview.rb:83:in `make_card_payment'
      ./features/screens/webview.rb:127:in `make_payment'
      ./features/step_definitions/in_app_purchases.rb:3
      ./features/support/env.rb:16:in `call'
      ./features/support/env.rb:16:in `on'
      ./features/step_definitions/in_app_purchases.rb:2:in `/^I pay for the album successfully by (.+)$/'
      features/album_view.feature:42:in `Then I can buy the album'

Jonas Maturana Larsen

unread,
Dec 18, 2012, 8:07:09 AM12/18/12
to calabash...@googlegroups.com
Which version of calabash-android are you using?

Rama

unread,
Dec 18, 2012, 8:31:21 AM12/18/12
to calabash...@googlegroups.com
I am using calabash-android version 0.3.8

Rama

unread,
Dec 18, 2012, 11:26:13 AM12/18/12
to calabash...@googlegroups.com
Hi Jonas

could you please help me on this, all my tests are failing due to purchase failing.  Any help would be appreciated

Thanks in Advance
Rama

Jonas Larsen

unread,
Dec 18, 2012, 5:06:40 PM12/18/12
to calabash...@googlegroups.com

Which action are  you calling when you get the exception?

Are you using other actions on webviews that works?

Rama

unread,
Dec 19, 2012, 5:57:43 AM12/19/12
to calabash...@googlegroups.com
Hi Jonas,

There are few actions on webview, few of them are working like typing email, choosing payment method and then on next screen its entering the name also but failing to enter the card number.   methods and step definitions are as below

Then /^I pay for the album successfully by (.+)$/ do |pay_method|
  on Webview do |page|
    page.make_payment(user, pay_method)
  end
end

def make_payment(user, pay_method)
    enter_email(user)
    pay_by(pay_method)
    case
      when pay_method =~ /card/
        make_card_payment(user)
      end
    start_downloading
  end

def make_card_payment(user)
    payment_details(user)
    confirm_payment
  end

def payment_details(user)
    enter_name_on_card(user)
    enter_card_number(user)    #failing at this step
    enter_postcode(user)
    enter_security_number(user)
  end

def enter_name_on_card(user)
    sleep 3
    performAction("set_text", "css", "input[id=\"id_transaction[credit_card][cardholder_name]\"]", "#{user.name}")
  end

  def enter_card_number(user)
    sleep 5
    performAction("set_text", "css", "input[id=\"id_transaction[credit_card][number]\"]", "#{user.card_number}")
  end

  def enter_postcode(user)
    sleep 3
    performAction("set_text", "css", "input[id=\"id_transaction[billing][postal_code]\"]", "#{user.postcode}")
  end

  def enter_security_number(user)
    sleep 3
    performAction("set_text", "css", "input[id=\"id_transaction[credit_card][cvv]\"]", "#{user.security_code}")
  end

  def confirm_payment
    wait_for(20){element_exists("webView css:input[id=card_pay_submit]")}
    performAction("touch",'css','#creditcard input[id="card_pay_submit"]')
  end


Regards
Rama

Rama

unread,
Dec 19, 2012, 11:55:59 AM12/19/12
to calabash...@googlegroups.com
Hi Jonas

I hope the previous information will be sufficient if not please let me know

Thanks in advance
Rama

Rama

unread,
Dec 19, 2012, 4:25:23 PM12/19/12
to calabash...@googlegroups.com
can anyone help on this?

Jonas Larsen

unread,
Dec 20, 2012, 12:46:17 AM12/20/12
to calabash...@googlegroups.com

Please stop bumping your question. Every time you bump a lot of people gets an email.
It is had manners and will only annoy people. It probably have the opposite effect that you hope for.

Gabriel Daleson

unread,
Jan 2, 2013, 6:48:48 PM1/2/13
to calabash...@googlegroups.com
I believe I've found the problem stemming from the changes introduced in commit bbf68a72e887bd3d6af744bc74787698601f28c8. I noticed that version 0.3.2 worked without generating this error, but more recent versions caused this error on several different versions of Android that I tested.

I've also noticed that EnterTextByCssSelector works, but PressByCssSelector does not. (At least, I can call perform('set_text', 'css', '#foo' 'bar'), but not perform('click_by_selector', 'css', '#foo') from calabash_steps.rb.) I'm not sure why this might be, given that this commit shows that the runOnUiThread call has been removed from both places, but the suggestion to restore it seems appropriate to my untrained eye.

Thank you, of course, for an outstanding piece of software and for your help on this group.

Gabriel Daleson

Jonas Maturana Larsen

unread,
Jan 3, 2013, 12:55:22 AM1/3/13
to calabash...@googlegroups.com
Hi Gabriel,

Welcome to the group and thank you for the kind words.

I just made this fix for the problem.

Will have to test that and some other webview related things today and then I'll release a pre-release of calabash-android.

Cheers,
Jonas
Reply all
Reply to author
Forward
0 new messages