0

How to interact with the webactivity which launched from another activity ?

My test case is Launching my login activity, filling the user credentials on edit texts and performing click() action.

onView(withId(R.id.editTextUserId)).perform(typeText("username"),     closeSoftKeyboard());
onView(withId(R.id.editTextPassword)).perform(typeText("password"), closeSoftKeyboard()); 
onView(withId(R.id.loginButton)).perform(click());

the login button from main project is launching the webactivity there i have to fill another data in the text filed displaying on the webpage.

I have tried with onWebView().withElement(findElement(Locator.ID, "input")); but getting null reference error.

i am not sure about the following,

  1. how to wait for the webactivity to launch? as i am adding webview at runtime without id.
  2. how to execute the remaining test cases from web activity after it started.could anyone help me?

Thanks, J

Jey
  • 1

1 Answers1

0

1. You can add id to the View from code:

Create some xml file like:

res/values/ids.xml

Inside add WebView id:

<item name="form_webview" type="id"/>

Set it in code:

webView.setId(R.id.form_webview);

2. You need to execute all checks in current test

sswierczek
  • 810
  • 1
  • 12
  • 19
  • Yes it works. thanks sswierczek. but only problem is i have to add all the cases in current test. is there any other way ? – Jey Aug 16 '16 at 13:02
  • @Jey I think you have 2 options. First is to create separate test classes for each `Activity`, or create some test class which will test many `Activities`, you cannot and you shouldn't run test from other tests. You need to decide what is better for you. You can also try to reuse some test code in both test classes. Please vote up and accept answer if it is ok for you :) – sswierczek Aug 16 '16 at 14:27