Robotium: searchText - android

I have a strange situation I can't explain myself.
The following code works well:
solo.sleep(1000);
assertTrue(solo.searchText("Banking"));
but the following code fails:
assertTrue(solo.waitForText("Banking", 1, 1000));
Can someone can explain me this?
Kind regards,
Alban.

The problem is that '1000' in waitForText isn't setting a delay, it's setting how long to keep looking. If it doesn't find the text within that time, it returns false. See Robotium source
Try the second version like this and see if it doesn't work:
assertTrue(solo.waitForText("Banking", 1, 10000)); // Take up to 10 seconds
Also, the delay before the first one probably doesn't change anything. I think the first example would work just as well if it was only:
assertTrue(solo.searchText("Banking"));

Before robotium-1.7.1 there were some issues with searchText(). It was definetely not always finding the text even when it should. You might want to try again with simple code without timing.

Related

Doing calculation in android edtitext on lostfocus

I'm writing an app the is does a lot of calculating and I'd like to accomplish some calc when I leave an EditText. Nothing fancy, things like entering 7/16 and having 0.4375 as the result or 1.0259 * 7 and having 7.1813 as the result. The function wouldn't be used all the time but would eliminate a couple of steps when needed.
Thanks Steve
I asked the wrong question, but the comment posted got me thinking, needed to look at substrings.
I've figured out what I need.

Getting NoMatchingViewException during perform(...), but not the preceding check(...)

I have this simple Espresso interaction:
onView(atIndex(withId(R.id.editTextTextWidget), 0)).inRoot(authViewRootMatcher)
.check(matches(allOf(isDisplayed(), isEnabled())))
.perform(typeText("1"));
The check(matches(allOf(isDisplayed(), isEnabled()))) passes as expected, but the following perform(typeText("1")) does not. I cannot figure out why, for the life of me.
So, I can't believe I'm asking this, but how in the name of Android do I use Espresso to type text into my EditText whose ID is R.id.editTextTextWidget?
I fixed the problem by splitting the check(...) call and perform(...) call:
onView(atIndex(withId(R.id.editTextTextWidget), 0)).inRoot(authViewRootMatcher)
.check(matches(allOf(isDisplayed(), isEnabled())));
onView(atIndex(withId(R.id.editTextTextWidget), 0)).inRoot(authViewRootMatcher)
.perform(typeText("1"));
For some reason this works, and the original doesn't. #GooglePlz

Finding an element by id in Appium

I have got id associated with the element, but when tried locating this using findElement(By.id()) it doesn't work.
Also, I had gone through few blogs with the same question as given here, but I saw the resource-id in there was prefixed with packagename and :id. In my case, these aren't associated. Screenshot for the element details is below :
I have used the below code to locate the element by id.
- driver.findElement(By.id("loginHome"));
- driver.findElement(By.id("com.packagename:id/loginHome"));
- driver.findElement(By.id("android:id/loginHome"));
- driver.findElement(By.xpath(//*[#id='loginHome']));
But none of the above code snippets worked. Can someone please help me get through with this. Thanks in Advance.
Not exactly answering your question, but providing an alternative method for you to complete the test.
I follow this link https://github.com/appium/appium-dot-app and it works.
You don't need to code everything. The application provides some easy ways to record your clicks and gestures.
For example, when I click something, it will print out the script automatically.
wd.find_element_by_xpath("//android.view.View[1]/android.widget.FrameLayout[2]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[2]/android.widget.RelativeLayout[1]").click()
And you just need to choose your favorite programming language and save it after testing is done.
One thing that I have to point out is that the swipe function is corrupted. Use the following code to perform swipe gestures
wd.swipe(421, 424, 70, 424, 500)
You can try other options as well. Try this:
//add some wait command before the element
Thread.sleep(2000);
driver.findElementsByXPath("//*[#class='android.widget.Button' and #index='4']");
Try adding explicit sleep for page to load before clicking usind ID.
First try to wait for the particular element
MobileElement expelement=(MobileElement) (new WebDriverWait(driver, 15)).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//android.widget.Button[#index='4']")));
Then try to do the click(or the activity you suppose to do)
driver.findElement(By.xpath("//android.widget.Button[#index='4']")).click();

If statement in App Inventor

I'm designing a spaceship game in App Inventor. I have a label (lblScore) update when the ship is hit each time. When the ship is hit 3 times, I want the code inside that to execute yet it doesn't work. I've tried multiple variations of this, such as setting it to lblScore.Text instead. Any idea's on how I can address the issue?
Is the lblscore a label?
If it is all you need to do is have a collision block saying whenever the spaceship gets hit, set lblscore = lblscore + 1
This should fix your issue but I would like to see all of your blocks
Do you increment your lblScore in the Ship.CollidedWith event?
If yes, you should move your if statement there, but instead of using the lblScore component as currently, you should better use the lblScore.Text property instead.
Probably it would help us to help you, if you provide a screenshot of your Ship.CollidedWith event...

Android set last modified time for the file

I have been using " public boolean setLastModified (long time) " for setting the file modified time but it always return false. I have seen few similar posts related to this but none of them could work for me. can someone give me solution for this?
Please do not post me any URL's, I have already seen them :
file.lastModified() is never what was set with file.setLastModified()
Is it possible to reset the last modified date of an Android file?
http://www.mkyong.com/java/how-to-change-the-file-last-modified-date-in-java/
setLastModified() is apparently unreliable on Android, perhaps working on some devices and not on others.
You are told to test the return value, false if it is fail.
Disappointed to find out about that...

Categories

Resources