Bug 869277 - Intermittent testAddSearchEngine | The number of search results has increased - got 5, expected 10. r=jmaher
authorAdrian Tamas <adrian.tamas@softvision.ro>
Wed, 08 May 2013 15:21:47 +0300
changeset 142304 e82e0f27347ef46c9b1ba92b2e4f6b50b7d746d1
parent 142303 46a74e87779c99369b585b8b50f0ddf6099a2d78
child 142305 6fc3f280d0f6675be65bfc9e15ba134c9d5eac64
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher
bugs869277
milestone23.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 869277 - Intermittent testAddSearchEngine | The number of search results has increased - got 5, expected 10. r=jmaher
mobile/android/base/tests/testAddSearchEngine.java.in
--- a/mobile/android/base/tests/testAddSearchEngine.java.in
+++ b/mobile/android/base/tests/testAddSearchEngine.java.in
@@ -4,40 +4,40 @@ package @ANDROID_PACKAGE_NAME@.tests;
 import @ANDROID_PACKAGE_NAME@.*;
 import android.view.View;
 import android.widget.ListAdapter;
 import android.widget.ListView;
 import java.util.ArrayList;
 
 /**
  * Test adding a search engine from an input field context menu
- * Starting a test
- * expected values.
+ * 1. Get the number of existing search engines
+ * 2. Load a page with a text field, open the context menu and add a search engine from the page
+ * 3. Get the number of search engines after adding the new one
  */
 public class testAddSearchEngine extends BaseTest {
 
+    final int MAX_TRIES = 5;
+
     @Override
     protected int getTestType() {
         return TEST_MOCHITEST;
     }
 
     public void testAddSearchEngine() {
         int height,width;
         final int initialNumSearchEngines;
         String blank = getAbsoluteUrl("/robocop/robocop_blank_01.html");
         String url = getAbsoluteUrl("/robocop/robocop_search.html");
 
         blockForGeckoReady();
         loadUrl(blank);
         waitForText("Browser Blank Page 01");
-
-        initialNumSearchEngines = getNumSearchEngines();
-        mActions.sendSpecialKey(Actions.SpecialKey.BACK);
-        waitForText("Browser Blank Page 01");
-
+        initialNumSearchEngines = getNumSearchEngines("Browser Blank Page 01");
+        
         loadUrl(url);
         waitForText("Robocop Search Engine");
 
         // Open the context menu for the intput field
         height = mDriver.getGeckoTop() + 10;
         width = mDriver.getGeckoLeft() + 20;
         mAsserter.dumpLog("Long Clicking at width = " + String.valueOf(width) + " and height = " + String.valueOf(height));
         mSolo.clickLongOnScreen(width,height);
@@ -56,35 +56,49 @@ public class testAddSearchEngine extends
             // If the OS is ICS the vkb is opened when the popup is triggered so we need to close it in order to click the OK button
             mActions.sendSpecialKey(Actions.SpecialKey.BACK);
             waitForText("OK"); // Make sure the OK button is visible
         }
         mSolo.clickOnButton("OK");
         mAsserter.ok(!mSolo.searchText("Add Search Engine"), "Adding the search engine", "The add serach engine pop-up has been cloesed");
 
         // Check that the number of search results has increased
-        mAsserter.is(getNumSearchEngines() ,initialNumSearchEngines + 1 , "The number of search results has increased");
+        mAsserter.is(getNumSearchEngines("Robocop Search Engine") ,initialNumSearchEngines + 1 , "The number of search results has increased");
     }
 
-    public int getNumSearchEngines() {
+    public int getNumSearchEngines(String waitText) {
         ArrayList<ListView> views;
         int searchEngineCount = 0;
+        int oldSearchEngineCount = -1;
 
-        // Start a search and wait for the search engine data to be displayed
-        Actions.EventExpecter enginesEventExpecter = mActions.expectGeckoEvent("SearchEngines:Data");
-        clickOnAwesomeBar();
-        waitForText("Bookmarks");
-        mActions.sendKeys("Firefox for Android");
-        enginesEventExpecter.blockForEvent();
+        for (int i = 0; i < MAX_TRIES; i++ ) {
+            // Start a search and wait for the search engine data to be displayed
+            Actions.EventExpecter enginesEventExpecter = mActions.expectGeckoEvent("SearchEngines:Data");
+            clickOnAwesomeBar();
+            waitForText("Bookmarks");
+            mActions.sendKeys("Firefox for Android");
+            enginesEventExpecter.blockForEvent();
 
-        views = mSolo.getCurrentListViews();
-        for (ListView view : views) {
-             ListAdapter adapter = view.getAdapter();
-             if (adapter != null) {
-                 searchEngineCount = adapter.getCount();
-             } else {
-                 searchEngineCount = -1;
-             }
+            views = mSolo.getCurrentListViews();
+            for (ListView view : views) {
+                 ListAdapter adapter = view.getAdapter();
+                 if (adapter != null) {
+                     searchEngineCount = adapter.getCount();
+                 } else {
+                     searchEngineCount = -1;
+                 }
+            }
+            // Close the Awesomescreen
+            mActions.sendSpecialKey(Actions.SpecialKey.BACK);
+            waitForText(waitText);
+            if (searchEngineCount == oldSearchEngineCount) {
+                mAsserter.isnot(searchEngineCount, -1, "Search engine number could be determined correctly");
+                return searchEngineCount;
+            } else {
+                oldSearchEngineCount = searchEngineCount;
+            }
         }
-        mAsserter.isnot(searchEngineCount, -1, "There should be search engines displayed when text is entered");
-        return searchEngineCount;
+
+    // Since the number of Search Engine count was different on every try fail the test
+    mAsserter.is(searchEngineCount,oldSearchEngineCount, "The search engine count could not be established correctly");
+    return searchEngineCount;
     }
 }