         // Type the URL to make the search controller appear.
         tester().tapViewWithAccessibilityIdentifier("url")
         tester().clearTextFromAndThenEnterTextIntoCurrentFirstResponder("foobar")
-        let browserViewController = UIApplication.sharedApplication().keyWindow!.rootViewController!
+        tester().waitForTimeInterval(0.1) // Wait to make sure that input has propagated through delegate methods
+        let browserViewController = getTopViewController()
         weak var searchViewController = getChildViewController(browserViewController, childClass: "SearchViewController")
         XCTAssertNotNil(searchViewController, "Got search controller reference")
 

        XCTAssertNil(webView, "webView disposed")
    }


    private func getChildViewController(parent: UIViewController, childClass: String) -> UIViewController {
        let childControllers = parent.childViewControllers.filter { child in


    func testAboutHomeDisposed() {
        // about:home is already active on startup; grab a reference to it.
        let browserViewController = getTopViewController()
        weak var aboutHomeController = getChildViewController(browserViewController, childClass: "HomePanelViewController")

        // Change the page to make about:home go away.
        tester().tapViewWithAccessibilityIdentifier("url")
        let url = "\(webRoot)/numberedPage.html?page=1"

        // Work around potential KIF bug. The nillification does not seem to propagate unless we use and explicit autorelease pool.
        // https://github.com/kif-framework/KIF/issues/739
        autoreleasepool {
            tester().clearTextFromAndThenEnterTextIntoCurrentFirstResponder("\(url)\n")
        }

        tester().waitForWebViewElementWithAccessibilityLabel("Page 1")


        tester().runBlock { _ in
            return (aboutHomeController == nil) ? KIFTestStepResult.Success : KIFTestStepResult.Wait
