Skip to main content

Start · Quit · Sessions

This tool on every surface: CLI · MCP · Python · JavaScript · Go · Java · .NET

Start or end the session on a device. These call app_session.

Start​

func Start(ctx context.Context, opts ...Option) (*Device, error)

Start connects and opens the session on the device: the device-side server is started now, and the app, if one was named with WithApp, launched and in front. End it with Quit.

Nothing requires it — every call opens a session on first use — but it puts the slow first start (installing UiAutomator2, building WebDriverAgent on an iPhone) where it was asked for, and says which device it got.

Quit​

func (d *Device) Quit(ctx context.Context) error

Quit ends the session on the device and closes the connection. The session's teardown is the daemon's own: accessibility settings put back, a recording or route stopped, WebViews detached, the device-side server stopped, and the app Start launched, if any, stopped too. Quitting a session that is not open succeeds, and a second Quit — a deferred one after an explicit one, say — does nothing.

A program that exits without Quit or Close has the sessions it started ended for it, the same way: mobium sees the client go.

Sessions​

func (d *Device) Sessions(ctx context.Context) ([]Session, error)

Sessions lists the sessions open on the daemon: device, platform, driver.

Examples​

Start a session and launch the app fresh​

dev, err := mobium.Start(ctx, mobium.WithApp("com.android.settings"))
if err != nil {
return err
}
defer dev.Quit(ctx)
fmt.Println(dev.Session().Device, dev.Session().Driver)

The same call from the command line, mobium session start --app com.android.settings, printed on an Android 15 emulator:

session already open on emulator-5554 (android, uiautomator2); com.android.settings was launched fresh and is in the foreground

End it, putting back what it changed​

if err := dev.Quit(ctx); err != nil {
return err
}

The same call from the command line, mobium session end, printed on an Android 15 emulator:

session ended on emulator-5554; anything it changed for the session is put back; com.android.settings, which the session launched, was stopped

More examples​

Start a session on Android and launch an app​

dev, err := mobium.Start(ctx, mobium.WithPlatform("android"), mobium.WithApp("com.example.shop"))
if err != nil {
log.Fatal(err)
}
defer dev.Quit(ctx)

Start on an iOS simulator and see what you got​

dev, err := mobium.Start(ctx, mobium.WithPlatform("ios"))
if err != nil {
return err
}
defer dev.Quit(ctx)
s := dev.Session()
fmt.Println(s.Device, s.Platform, s.Driver, s.Reused)

End the session, even when the test fails​

dev, err := mobium.Start(ctx)
if err != nil {
return err
}
defer dev.Quit(ctx) // a second Quit does nothing

List the sessions open on the daemon​

sessions, err := dev.Sessions(ctx)
if err != nil {
return err
}
for _, s := range sessions {
fmt.Println(s.Device, s.Platform, s.Driver)
}