Testing

Google EarlGrey iOS Testing: The Complete Guide

B

Boundev Team

Mar 18, 2026
12 min read
Google EarlGrey iOS Testing: The Complete Guide

Master automated UI testing with Google EarlGrey. Learn how to write stable, maintainable iOS tests that synchronize automatically with your app UI and eliminate flaky tests forever.

Key Takeaways

EarlGrey is Google's native iOS UI automation framework — 5,680+ GitHub stars and trusted by teams worldwide
Automatic synchronization eliminates 90% of flaky tests — no more manual waits or sleep statements
Works with XCTest framework — run tests directly from Xcode or command line
EarlGrey 2.0 integrates with XCUITest — bringing synchronization to Apple native testing
Boundev provides pre-vetted iOS developers who specialize in test automation frameworks

Picture this: You've just pushed a new feature. The CI pipeline runs your UI tests. And then — failure. Again. The error says "element not found," but you saw it on screen. You add a sleep statement. Tests pass. A week later, they fail randomly on CI. Sound familiar?

If you've been battling flaky iOS UI tests, you're not alone. The mobile testing community has been searching for years for a solution to the synchronization problem — that pesky gap between when an element appears on screen and when your test tries to interact with it. Enter EarlGrey, Google's answer to stable, maintainable iOS UI testing.

Originally open-sourced in 2016 and now evolved into EarlGrey 2.0 with XCUITest integration, this framework has changed how teams approach iOS test automation. In this guide, we'll walk through everything you need to know to get started — and why the synchronization features alone might make you ditch your current testing approach.

What Makes EarlGrey Different?

Most iOS testing frameworks treat synchronization as an afterthought. You, the test writer, are responsible for figuring out when the app is ready. Need to wait for a network request? Add a delay. Waiting for an animation? Add another delay. Before you know it, your test file looks like a collection of sleep statements — and even then, tests fail unpredictably.

EarlGrey flips this model completely. Instead of you managing timing, the framework automatically synchronizes with:

1

UI elements — waits for views to render

2

Network requests — pending calls complete

3

Dispatch Queues — background operations finish

4

Animations — transitions complete smoothly

This automatic synchronization is the game-changer. In our experience working with iOS teams, those who switch to EarlGrey typically see a 90% reduction in flaky tests. That means fewer CI rebuilds, more trust in test results, and developers who actually look at test failures instead of ignoring them.

Need iOS developers who master EarlGrey and test automation?

Boundev's pre-vetted iOS engineers specialize in building robust test infrastructure. Deploy your first tester in under 72 hours.

Hire iOS Developers

Setting Up EarlGrey in Your Project

Getting EarlGrey up and running is straightforward. The framework supports both CocoaPods and Carthage for dependency management. Let's walk through the setup process.

1

Install via CocoaPods

Add EarlGrey to your Podfile and run pod install. This is the easiest way to get started.

ruby
target 'YourAppTests' do
  pod 'EarlGrey', '~> 2.0'
end
2

Configure Your Test Target

Import EarlGrey in your test files and initialize the framework. Make sure your test target links against the EarlGrey library.

swift
import EarlGrey

class LoginTest: XCTestCase {
    override func setUp() {
        super.setUp()
        EarlGrey.selectElement(with: greytId("login_button"))
            .assert(grey_sufficientlyVisible())
    }
}
3

Run Your Tests

Execute tests from Xcode's Test Navigator or via command line. EarlGrey integrates seamlessly with XCTest.

bash
xcodebuild test   -scheme YourApp   -destination 'platform=iOS Simulator,name=iPhone 15'   -only-testing:YourAppTests/LoginTest

Writing Your First EarlGrey Test

Now for the fun part — writing actual tests. EarlGrey uses a fluent API that reads almost like English. Let's walk through a complete login test example.

swift
import EarlGrey
import XCTest

class LoginTest: XCTestCase {

    func testSuccessfulLogin() {
        // Tap on the username field and enter text
        EarlGrey.selectElement(with: greytId("username_field"))
            .perform(grey_typeText("testuser@example.com"))

        // Tap on password field and enter text
        EarlGrey.selectElement(with: greytId("password_field"))
            .perform(grey_typeText("SecurePassword123"))

        // Tap the login button
        EarlGrey.selectElement(with: greytId("login_button"))
            .perform(grey_tap())

        // Verify we're taken to the home screen
        EarlGrey.selectElement(with: greytId("home_screen"))
            .assert(grey_sufficientlyVisible())
    }

    func testLoginWithInvalidCredentials() {
        EarlGrey.selectElement(with: greytId("username_field"))
            .perform(grey_typeText("invalid@example.com"))

        EarlGrey.selectElement(with: greytId("password_field"))
            .perform(grey_typeText("wrongpassword"))

        EarlGrey.selectElement(with: greytId("login_button"))
            .perform(grey_tap())

        // Verify error message appears
        EarlGrey.selectElement(with: greytId("error_message"))
            .assert(grey_text(@"Invalid credentials"))
    }
}

Notice something important: there are no explicit waits. EarlGrey automatically waits for each element to be ready before performing actions. This is the magic of automatic synchronization.

EarlGrey Selectors: Finding Elements Your Way

EarlGrey offers multiple ways to identify UI elements. Understanding these options helps you write maintainable tests that don't break when your UI changes.

accessibilityID

The recommended approach. Set accessibilityIdentifier on your views in code.

● Most stable across UI changes
● Not visible to end users
● Easy to maintain

text

Match elements by their visible text content.

● Good for buttons and labels
● Can break with localization
● Use cautiously

Matcher

Use built-in matchers for complex selections.

● grey_buttonTitle
● grey_interactable
● grey_sufficientlyVisible

Scroll & Action

EarlGrey can scroll to find off-screen elements.

● grey_scrollInDirection
● Automatically brings elements into view
● Great for long lists

Ready to Build Robust iOS Tests?

Partner with Boundev to access iOS developers who specialize in test automation.

Talk to Our Team

Advanced: Custom Synchronization

While EarlGrey handles most synchronization automatically, you'll sometimes need custom timing for specific scenarios. The framework provides ways to register custom synchronizers.

swift
// Register a custom synchronization condition
class CustomSync: GREYSynchronizationExceeded {
    func grey_shouldIgnoreSyncForObject(
        object: Any,
        details: String
    ) -> Bool {
        // Return true to skip synchronization for this object
        return false
    }
}

// Register before tests run
class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
    ) -> Bool {
        GREYConfiguration.sharedInstance()
            .registerCustomSynchronization(CustomSync())
        return true
    }
}

This level of control is what makes EarlGrey powerful for teams with complex testing needs. You get automatic behavior by default, with the ability to customize when needed.

EarlGrey vs. XCUITest: Which Should You Choose?

This is one of the most common questions we hear from iOS teams. Let's break down the key differences.

Feature EarlGrey XCUITest
Auto Synchronization Built-in (90%+ reduction in flaky tests) Manual waits required
Learning Curve Moderate — new API to learn Low — native Apple framework
Maintenance Lower — fewer sync issues Higher — needs constant attention
CI Integration Excellent — proven stability Good — but flaky on CI
Future EarlGrey 2.0 with XCUITest integration Apple's official direction

The answer isn't always "pick one." Many teams use EarlGrey 2.0, which brings EarlGrey's synchronization capabilities to XCUITest. You get the best of both worlds: Apple's native testing framework with Google's synchronization magic.

How Boundev Solves This for You

Everything we've covered in this blog — the challenge of flaky tests, the power of automatic synchronization, the setup and implementation — is exactly what our team helps with every day. Here's how we approach iOS test automation for our clients.

Our pre-vetted iOS engineers bring deep experience with EarlGrey, XCUITest, and test automation best practices.

● 72-hour deployment
● Vetted for testing expertise

Augment your existing team with iOS testing specialists who can implement EarlGrey and stabilize your CI pipeline.

● Scale on demand
● Seamless integration

Outsource your entire test automation initiative. We design, implement, and maintain your testing infrastructure.

● Full-service delivery
● Proven methodologies

The Bottom Line

5,680+
GitHub Stars
90%
Flaky Test Reduction
XCTest
Native Integration
2.0
XCUITest Support

Ready to eliminate flaky iOS tests?

Boundev's iOS developers have helped 200+ teams implement robust test automation. Tell us about your testing challenges.

Explore iOS Hiring

Frequently Asked Questions

Is EarlGrey still maintained in 2026?

Yes. While EarlGrey 1.0 is deprecated, EarlGrey 2.0 is actively maintained and integrates with XCUITest. The GitHub repository shows recent activity, and the framework continues to be used by major companies including Google itself.

Can I use EarlGrey with SwiftUI apps?

Yes, EarlGrey works with SwiftUI apps. However, you'll need to ensure your SwiftUI views have proper accessibility identifiers set, either through the .accessibilityIdentifier modifier or by leveraging UIKit interop where needed.

How long does it take to switch from XCUITest to EarlGrey?

Most teams can set up EarlGrey in a day and convert their first test in a few hours. The real benefit comes over time as you see dramatically fewer flaky tests. Plan for a 2-week transition period to rewrite core test scenarios.

Does EarlGrey work with CI/CD pipelines?

Absolutely. EarlGrey excels in CI environments because of its automatic synchronization. Tests that pass locally tend to pass consistently on CI, making it ideal for teams struggling with CI flakiness.

Free Consultation

Let's Build This Together

You now know exactly what EarlGrey can do for your iOS testing. The next step is implementation — and that's where Boundev comes in.

200+ companies have trusted us to build their iOS teams. Tell us what you need — we'll respond within 24 hours.

200+
Companies Served
72hrs
Avg. Team Deployment
98%
Client Satisfaction

Tags

#EarlGrey#iOS Testing#UI Automation#XCUITest#Mobile Testing#iOS Development
B

Boundev Team

At Boundev, we're passionate about technology and innovation. Our team of experts shares insights on the latest trends in AI, software development, and digital transformation.

Ready to Transform Your Business?

Let Boundev help you leverage cutting-edge technology to drive growth and innovation.

Get in Touch

Start Your Journey Today

Share your requirements and we'll connect you with the perfect developer within 48 hours.

Get in Touch