Closed GoogleCodeExporter closed 9 years ago
ClickOnButton() is used with index. What you want to do is clickOnView(button);
Please keep this tracker for issues only.
Original comment by renasr...@gmail.com
on 9 May 2013 at 5:37
this didn't work too:
Button msButton = (Button) solo.getCurrentActivity().findViewById(
com.example.simplecalculator.R.id.addBtnID);
solo.clickOnView(msButton);
in the manifest xml, i also added
<uses-sdk android:targetSdkVersion="YOUR_VERSION" />
<supports-screens android:anyDensity="true"/>
i still get the same error.
Original comment by khelifa....@gmail.com
on 10 May 2013 at 9:34
Please paste your test case.
Original comment by renasr...@gmail.com
on 10 May 2013 at 9:37
package com.example.simplecalculator.test;
import org.junit.Test;
import com.example.simplecalculator.MainActivity;
import com.jayway.android.robotium.solo.Solo;
import android.app.Instrumentation;
import android.test.ActivityInstrumentationTestCase2;
import android.view.KeyEvent;
import android.widget.Button;
import android.widget.EditText;
public class testAddButton extends
ActivityInstrumentationTestCase2<MainActivity> {
private Solo solo;
public testAddButton() {
super(MainActivity.class);
}
protected void setUp() throws Exception {
super.setUp();
solo = new Solo(getInstrumentation(), getActivity());
}
protected void tearDown() throws Exception {
super.tearDown();
}
@Test public void testAddBtn(){
Button msButton = (Button) solo.getCurrentActivity().findViewById(
com.example.simplecalculator.R.id.addBtnID);
solo.clickOnView(msButton);
}
}
Original comment by khelifa....@gmail.com
on 10 May 2013 at 9:46
Do this:
Button msButton = (Button) solo.getView(
com.example.simplecalculator.R.id.addBtnID);
solo.clickOnView(msButton);
Original comment by renasr...@gmail.com
on 10 May 2013 at 9:48
now i'm getting:
junit.framework.AssertionFailedError: Click can not be completed!
at com.jayway.android.robotium.solo.Clicker.clickOnScreen(Clicker.java:85)
at com.jayway.android.robotium.solo.Clicker.clickOnScreen(Clicker.java:157)
at com.jayway.android.robotium.solo.Clicker.clickOnScreen(Clicker.java:131)
at com.jayway.android.robotium.solo.Solo.clickOnView(Solo.java:879)
at
com.example.simplecalculator.test.testAddButton.testAddBtn(testAddButton.java:36
)
at java.lang.reflect.Method.invokeNative(Native Method)
at
android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at
android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at
android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTes
tCase2.java:192)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175)
at
android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:55
5)
at
android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1661)
does that mean the the button is beeing clicked on & there is another problem.
the expected result when i click on the button is a TextView takes "Hello".
What exactly can go wrong.
Original comment by khelifa....@gmail.com
on 10 May 2013 at 10:14
You need to follow the tutorial "Test Android Calculator Application with
Robotium" :
http://code.google.com/p/robotium/wiki/RobotiumTutorials
Original comment by renasr...@gmail.com
on 10 May 2013 at 10:16
Also see: "Why do text and button clicks get wrong?"
http://code.google.com/p/robotium/wiki/QuestionsAndAnswers
/Renas
Original comment by renasr...@gmail.com
on 10 May 2013 at 10:31
by the way i'm using 4.2.2, API17
i downloaded the 2 projects AndroidCalsulator & AndroidCalculatorTest.
when u run the AndroidCalculatorTest.
i get the error:
junit.framework.AssertionFailedError: EditText is not found!
at com.jayway.android.robotium.solo.Waiter.waitForAndGetView(Waiter.java:492)
at com.jayway.android.robotium.solo.Solo.enterText(Solo.java:1488)
at com.calculator.test.TestMain.testDisplayBlackBox(TestMain.java:26)
at java.lang.reflect.Method.invokeNative(Native Method)
at
android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at
android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at
android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTes
tCase2.java:192)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175)
at
android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:55
5)
at
android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1661)
the problem happens in 1st
EditText FirsteditText = (EditText) solo.getView(R.id.EditText01);
solo.enterText(FirsteditText, String.valueOf(firstNumber));
i think the problem is more than how to create the test case
could it be a framework issue?
should i use an older API?
Original comment by khelifa....@gmail.com
on 10 May 2013 at 11:30
Hi i've got couple of things
1. In case of your main problem
//solo.assertCurrentActivity("Check on startup", MainActivity.class);
String appName = solo.getCurrentActivity().getClass().getSimpleName();
solo.assertCurrentActivity("Check on startup", appName);
solo.waitForActivity(appName);
EditText editText1 = (EditText) solo.getView(com.example.simplecalculator.R.id.EDtxt1);
EditText editText2 = (EditText) solo.getView(com.example.simplecalculator.R.id.EDtxt2);
//Button button = (Button) solo.getView(com.example.simplecalculator.R.id.addBtnID);
solo.enterText(editText1, String.valueOf("10"));
solo.enterText(editText2, String.valueOf("5"));
solo.goBack();
solo.clickOnButton(com.example.simplecalculator.R.id.addBtnID);
}
why are you using "solo.goBack()" ? , it is the one cause of issue.
Original comment by luckynav...@gmail.com
on 10 May 2013 at 12:15
2. Secondly
solo.clickOnButton() need index not the id of view.
Original comment by luckynav...@gmail.com
on 10 May 2013 at 12:19
About
junit.framework.AssertionFailedError: EditText is not found!
Issues with AndroidCalculatorTest, I've just run it on Galaxy S4 with 4.2.2,
its working fine here.
Can you please tell me are you using on real device ? what is the device info?
Original comment by luckynav...@gmail.com
on 10 May 2013 at 12:24
Thank you both so much for your help,
i figure out the issue & it's not related to the code itself
when i change the android device to Nexus S it worked.
on other devices, lower performnce, it didn't work. it didn't find the button.
which could be understandable because maybe the button is too big for the
screen itself or something like that.
thank you so much again.
my problem is officially solved.
kais.
Original comment by khelifa....@gmail.com
on 10 May 2013 at 12:25
yes luckynav, that was the problem exactly
Original comment by khelifa....@gmail.com
on 10 May 2013 at 12:32
Original issue reported on code.google.com by
khelifa....@gmail.com
on 9 May 2013 at 2:28