mobile

package
v0.91.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2026 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const SessionDescriptorVersion = 1
View Source
const W3CElementKey = "element-6066-11e4-a52e-4f735466cecf"

Variables

View Source
var ErrLeaseHeld = errors.New("mobile resource lease is held")

Functions

func AppendHistory

func AppendHistory(path, entry string) error

func ChecksReady

func ChecksReady(checks []Check, required map[string]bool) bool

func ClearHistory

func ClearHistory(path string) error

func CompleteREPLLine

func CompleteREPLLine(line string, position int, additional []string) (string, int, []string)

CompleteREPLLine applies one completion at the current byte position and returns all matching candidates so an interactive terminal can display ambiguity without losing the partially typed command.

func LoadHistory

func LoadHistory(path string, maxEntries int) ([]string, error)

func RemoveSessionDescriptor

func RemoveSessionDescriptor(path string) error

func ResolveExecutable

func ResolveExecutable(name string, candidates ...string) (string, error)

func SortedDataLines

func SortedDataLines(values map[string]interface{}) []string

func SummarizeHierarchy

func SummarizeHierarchy(source, filter string, maxNodes int) (string, error)

SummarizeHierarchy converts Android UiAutomator or iOS WDA XML into a compact, grep-friendly tree. The filter is case-insensitive and maxNodes bounds output.

func ValidationFailureReason

func ValidationFailureReason(validations []*assertly.Validation) (string, bool)

func WriteSessionDescriptor

func WriteSessionDescriptor(path string, descriptor *SessionDescriptor) error

Types

type AppiumClient

type AppiumClient struct {
	Endpoint string
	HTTP     *http.Client
}

func NewAppiumClient

func NewAppiumClient(endpoint string, client *http.Client) (*AppiumClient, error)

func (*AppiumClient) AttachSession

func (c *AppiumClient) AttachSession(ctx context.Context, sessionID string) (*AppiumSession, error)

AttachSession reconnects a client to an existing W3C session without creating or taking ownership of it. The caller decides whether Close should eventually be issued for the returned session.

func (*AppiumClient) NewSession

func (c *AppiumClient) NewSession(ctx context.Context, capabilities map[string]interface{}) (*AppiumSession, error)

func (*AppiumClient) Status

func (c *AppiumClient) Status(ctx context.Context) (map[string]interface{}, error)

type AppiumServer

type AppiumServer struct {
	ID        string
	Endpoint  string
	Ownership string
	PID       int
	LogPath   string
	// contains filtered or unexported fields
}

func StartAppium

func StartAppium(ctx context.Context, runner Runner, options AppiumServerOptions) (*AppiumServer, error)

func (*AppiumServer) Stop

func (s *AppiumServer) Stop(ctx context.Context) error

type AppiumServerOptions

type AppiumServerOptions struct {
	Mode             string
	ServerURL        string
	Executable       string
	AppiumHome       string
	Address          string
	Port             int
	BasePath         string
	LogPath          string
	StartupTimeoutMs int
}

func (*AppiumServerOptions) Init

func (o *AppiumServerOptions) Init()

func (AppiumServerOptions) Validate

func (o AppiumServerOptions) Validate() error

type AppiumSession

type AppiumSession struct {
	ID           string
	Capabilities map[string]interface{}
	// contains filtered or unexported fields
}

func (*AppiumSession) AcceptAlert

func (s *AppiumSession) AcceptAlert(ctx context.Context) error

func (*AppiumSession) AlertText

func (s *AppiumSession) AlertText(ctx context.Context) (string, error)

func (*AppiumSession) Attribute

func (s *AppiumSession) Attribute(ctx context.Context, elementID, name string) (interface{}, error)

func (*AppiumSession) Back

func (s *AppiumSession) Back(ctx context.Context) error

func (*AppiumSession) Clear

func (s *AppiumSession) Clear(ctx context.Context, elementID string) error

func (*AppiumSession) Click

func (s *AppiumSession) Click(ctx context.Context, elementID string) error

func (*AppiumSession) Close

func (s *AppiumSession) Close(ctx context.Context) error

func (*AppiumSession) Contexts

func (s *AppiumSession) Contexts(ctx context.Context) ([]string, error)

func (*AppiumSession) CurrentContext

func (s *AppiumSession) CurrentContext(ctx context.Context) (string, error)

func (*AppiumSession) DismissAlert

func (s *AppiumSession) DismissAlert(ctx context.Context) error

func (*AppiumSession) ElementBool

func (s *AppiumSession) ElementBool(ctx context.Context, elementID, property string) (bool, error)

func (*AppiumSession) ElementRect

func (s *AppiumSession) ElementRect(ctx context.Context, elementID string) (Rect, error)

func (*AppiumSession) Execute

func (s *AppiumSession) Execute(ctx context.Context, script string, args ...interface{}) (interface{}, error)

func (*AppiumSession) FindElement

func (s *AppiumSession) FindElement(ctx context.Context, using, value string) (string, error)

func (*AppiumSession) FindElements

func (s *AppiumSession) FindElements(ctx context.Context, using, value string) ([]string, error)

func (*AppiumSession) HideKeyboard

func (s *AppiumSession) HideKeyboard(ctx context.Context) error

func (*AppiumSession) Orientation

func (s *AppiumSession) Orientation(ctx context.Context) (string, error)

func (*AppiumSession) PageSource

func (s *AppiumSession) PageSource(ctx context.Context) (string, error)

func (*AppiumSession) PerformActions

func (s *AppiumSession) PerformActions(ctx context.Context, actions []map[string]interface{}) error

func (*AppiumSession) PointerGesture

func (s *AppiumSession) PointerGesture(ctx context.Context, points []PointerPoint) error

func (*AppiumSession) ReleaseActions

func (s *AppiumSession) ReleaseActions(ctx context.Context) error

func (*AppiumSession) Screenshot

func (s *AppiumSession) Screenshot(ctx context.Context) ([]byte, error)

func (*AppiumSession) SendKeys

func (s *AppiumSession) SendKeys(ctx context.Context, elementID, text string) error

func (*AppiumSession) SetContext

func (s *AppiumSession) SetContext(ctx context.Context, name string) error

func (*AppiumSession) SetLocation

func (s *AppiumSession) SetLocation(ctx context.Context, latitude, longitude, altitude float64) error

func (*AppiumSession) SetOrientation

func (s *AppiumSession) SetOrientation(ctx context.Context, orientation string) error

func (*AppiumSession) Text

func (s *AppiumSession) Text(ctx context.Context, elementID string) (string, error)

func (*AppiumSession) WindowRect

func (s *AppiumSession) WindowRect(ctx context.Context) (Rect, error)

type Call

type Call struct {
	Name string
	Args []interface{}
}

type Check

type Check struct {
	Name        string
	Status      string
	Path        string
	Version     string
	Detail      string
	Remediation string
}

type CleanupError

type CleanupError struct {
	Name  string
	Error string
}

type CleanupStack

type CleanupStack struct {
	// contains filtered or unexported fields
}

CleanupStack provides the LIFO, continue-on-error behavior that Endly's FIFO Context.Deffer list does not provide by itself.

func (*CleanupStack) Close

func (s *CleanupStack) Close(ctx context.Context) []CleanupError

func (*CleanupStack) Push

func (s *CleanupStack) Push(name string, cleanup func(context.Context) error) bool

type Command

type Command struct {
	Name string
	Args []string
	Dir  string
	Env  map[string]string
}

Command is an argv-safe local command. Name and Args are never joined into a shell expression.

type DSLCommand

type DSLCommand struct {
	Key         string
	Namespace   string
	Calls       []Call
	Expectation bool
}

func ParseDSL

func ParseDSL(source string) (*DSLCommand, error)

func ParseInstruction

func ParseInstruction(candidate interface{}) (*DSLCommand, string, error)

type DeviceExecutor

type DeviceExecutor func(ctx context.Context, session *AppiumSession, call Call) (interface{}, error)

type Evidence

type Evidence struct {
	Kind      string
	URL       string
	Size      int
	Sensitive bool
}

func CopyEvidenceFile

func CopyEvidenceFile(ctx context.Context, fs afs.Service, directory, name, kind, sourcePath string, maxBytes int64, tail, sensitive bool) (*Evidence, error)

CopyEvidenceFile streams a stable local capture into an AFS artifact. A tail copy is useful for bounded logs; non-tail files are rejected rather than truncated when they exceed maxBytes so videos remain valid containers.

func WriteEvidence

func WriteEvidence(ctx context.Context, fs afs.Service, directory, name, kind string, data []byte, sensitive bool) (*Evidence, error)

type ExecutionResult

type ExecutionResult struct {
	Data        map[string]interface{}
	Steps       []ExecutionStep
	Validations []*assertly.Validation
	Failures    []*FailureEvidence
}

type ExecutionStep

type ExecutionStep struct {
	Command    string
	Key        string
	Actual     interface{}
	Attempts   int
	DurationMs int
}

type Executor

type Executor struct {
	Session       *AppiumSession
	Resolve       LocatorResolver
	ExecuteDevice DeviceExecutor
	ActionTimeout time.Duration
	PollInterval  time.Duration
}

func (*Executor) Run

func (e *Executor) Run(ctx context.Context, commands []string) (*ExecutionResult, error)

func (*Executor) RunAny

func (e *Executor) RunAny(ctx context.Context, commands []interface{}) (*ExecutionResult, error)

type FailureArtifactFile

type FailureArtifactFile struct {
	Path     string
	Kind     string
	MaxBytes int64
	Tail     bool
}

type FailureArtifactOptions

type FailureArtifactOptions struct {
	Directory        string
	Screenshot       *bool
	PageSource       *bool
	MaxSourceBytes   int
	Files            []FailureArtifactFile
	CollectionErrors []string
}

type FailureEvidence

type FailureEvidence struct {
	Timestamp time.Time
	Reason    string
	Artifacts []*Evidence
	Errors    []string
}

func CaptureAppiumFailure

func CaptureAppiumFailure(ctx context.Context, fs afs.Service, session *AppiumSession, prefix, reason string, options *FailureArtifactOptions) *FailureEvidence

type LeaseHandle

type LeaseHandle struct {
	Key       string
	Token     string
	Fence     uint64
	PID       int
	Path      string
	CreatedAt time.Time
	ExpiresAt time.Time
}

type LeaseStore

type LeaseStore struct {
	Directory string
	TTL       time.Duration
	// contains filtered or unexported fields
}

func NewLeaseStore

func NewLeaseStore(directory string) *LeaseStore

func (*LeaseStore) Acquire

func (s *LeaseStore) Acquire(ctx context.Context, key string) (*LeaseHandle, error)

func (*LeaseStore) Refresh

func (s *LeaseStore) Refresh(handle *LeaseHandle) error

func (*LeaseStore) Release

func (s *LeaseStore) Release(handle *LeaseHandle) error

func (*LeaseStore) Validate

func (s *LeaseStore) Validate(handle *LeaseHandle) error

type Locator

type Locator struct {
	Using string
	Value string
}

type LocatorResolver

type LocatorResolver func(call Call) (Locator, bool, error)

type LoggedProcess

type LoggedProcess struct {
	PID  int
	Path string
	// contains filtered or unexported fields
}

func StartLoggedProcess

func StartLoggedProcess(ctx context.Context, runner Runner, command Command, logPath string) (*LoggedProcess, error)

func (*LoggedProcess) Stop

func (p *LoggedProcess) Stop(ctx context.Context) error

type OSRunner

type OSRunner struct{}

func (OSRunner) Run

func (OSRunner) Run(ctx context.Context, command Command) (Result, error)

func (OSRunner) Start

func (OSRunner) Start(ctx context.Context, command Command, stdout, stderr io.Writer) (*Process, error)

type PointerPoint

type PointerPoint struct {
	X          int
	Y          int
	DurationMs int
	Down       bool
	Up         bool
}

type Process

type Process struct {
	PID  int
	Done <-chan error
	Stop func(ctx context.Context) error
}

type REPLCallbacks

type REPLCallbacks struct {
	Execute    func(context.Context, string) (*ExecutionResult, error)
	Source     func(context.Context) (string, error)
	Screenshot func(context.Context) (*Evidence, error)
	Status     func(context.Context) interface{}
	Close      func(context.Context) error
}

type REPLConfig

type REPLConfig struct {
	Prompt         string
	MaxSourceBytes int
	MaxTreeNodes   int
	FailOnError    bool
	HistoryPath    string
	MaxHistory     int
	Completions    []string
}

type REPLResult

type REPLResult struct {
	Commands  int
	Errors    int
	ExitedBy  string
	History   []string
	Data      map[string]interface{}
	Artifacts []*Evidence
}

func RunREPL

func RunREPL(ctx context.Context, input io.Reader, output io.Writer, config REPLConfig, callbacks REPLCallbacks) (*REPLResult, error)

type Rect

type Rect struct {
	X      float64 `json:"x"`
	Y      float64 `json:"y"`
	Width  float64 `json:"width"`
	Height float64 `json:"height"`
}

type Result

type Result struct {
	Stdout     string
	Stderr     string
	ExitCode   int
	DurationMs int
}

type Runner

type Runner interface {
	Run(ctx context.Context, command Command) (Result, error)
	Start(ctx context.Context, command Command, stdout, stderr io.Writer) (*Process, error)
}

Runner is intentionally small so platform lifecycle code can be tested without an installed SDK or a real emulator.

type SegmentFinalizer

type SegmentFinalizer func(context.Context, int) (string, error)

type SegmentStarter

type SegmentStarter func(context.Context, int) (*Process, error)

type SegmentedCapture

type SegmentedCapture struct {
	// contains filtered or unexported fields
}

func StartSegmentedCapture

func StartSegmentedCapture(duration time.Duration, start SegmentStarter, finish SegmentFinalizer) (*SegmentedCapture, error)

func (*SegmentedCapture) Checkpoint

func (s *SegmentedCapture) Checkpoint(ctx context.Context) ([]string, []string)

Checkpoint finalizes the segment currently being recorded and immediately starts the next one. It does not transfer ownership or stop the capture.

func (*SegmentedCapture) Snapshot

func (s *SegmentedCapture) Snapshot() ([]string, []string)

func (*SegmentedCapture) Stop

func (s *SegmentedCapture) Stop() ([]string, []string)

type SessionDescriptor

type SessionDescriptor struct {
	Version          int       `json:"version"`
	Platform         string    `json:"platform"`
	SessionID        string    `json:"sessionId"`
	BackendSessionID string    `json:"backendSessionId"`
	Endpoint         string    `json:"endpoint"`
	TargetID         string    `json:"targetId,omitempty"`
	TestIDStrategy   string    `json:"testIdStrategy,omitempty"`
	CreatedAt        time.Time `json:"createdAt"`
}

SessionDescriptor is the portable, non-secret information needed by another Endly process to reconnect to an existing Appium session.

func ReadSessionDescriptor

func ReadSessionDescriptor(path, expectedPlatform string) (*SessionDescriptor, error)

func (*SessionDescriptor) Init

func (d *SessionDescriptor) Init()

func (*SessionDescriptor) Validate

func (d *SessionDescriptor) Validate(expectedPlatform string) error

type TypedCall

type TypedCall struct {
	Name string        `json:"name"`
	Args []interface{} `json:"args,omitempty"`
}

type TypedCommand

type TypedCommand struct {
	Key     string            `json:"key,omitempty"`
	Locator *TypedLocator     `json:"locator,omitempty"`
	Action  *TypedCall        `json:"action,omitempty"`
	Device  *TypedCall        `json:"device,omitempty"`
	Expect  *TypedExpectation `json:"expect,omitempty"`
}

TypedCommand is the structured alternative to the textual DSL. Exactly one of Locator+Action, Device, or Expect must be configured.

func (*TypedCommand) DSL

func (c *TypedCommand) DSL() (*DSLCommand, string, error)

type TypedExpectation

type TypedExpectation struct {
	Locator   *TypedLocator `json:"locator,omitempty"`
	Device    *TypedCall    `json:"device,omitempty"`
	Matcher   TypedCall     `json:"matcher"`
	TimeoutMs int           `json:"timeoutMs,omitempty"`
}

type TypedLocator

type TypedLocator struct {
	Strategy  string `json:"strategy"`
	Value     string `json:"value"`
	Selection string `json:"selection,omitempty"`
	Index     int    `json:"index,omitempty"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL