类型 Session

API 文档由 Go 源码生成,内容为英文。

type Session struct {

	// config is the window the application opened with. It decides the window
	// chrome a screenshot carries over the scene (see drawWindowChrome).

}

Session is one application run without a window. It is not safe for concurrent use.

构造函数

Open#

func Open(config app.Config, canvas *ui.Canvas, options Options) (*Session, error)

Open starts config's application in a driver and paints its first frame. canvas may be nil.

方法

Click#

func (session *Session) Click(x, y float32) error

Click clicks at a logical-pixel point.

ClickLabel#

func (session *Session) ClickLabel(label string) error

ClickLabel clicks the center of the region labelled label.

Close#

func (session *Session) Close()

Close releases the session.

DoubleClick#

func (session *Session) DoubleClick(x, y float32) error

DoubleClick double-clicks at a logical-pixel point.

DoubleClickLabel#

func (session *Session) DoubleClickLabel(label string) error

DoubleClickLabel double-clicks the center of the region labelled label.

Driver#

func (session *Session) Driver() *app.Driver

Driver exposes the underlying driver for operations the session does not wrap.

Drop#

func (session *Session) Drop(event ui.FileDropEvent) (bool, error)

Drop delivers files dragged from the system onto a logical-pixel window point. With ui.FileDropOver it is the hover, with ui.FileDropDrop the drop; the result is whether the hit under the point takes files.

HasText#

func (session *Session) HasText(substring string) bool

HasText reports whether any painted text contains substring.

Hit#

func (session *Session) Hit(label string) (ui.Hit, bool)

Hit returns the front-most reachable region whose accessibility label is exactly label, or failing that contains it (case-insensitively).

Image#

func (session *Session) Image() (*image.RGBA, error)

Image renders the current frame at the session's scale, window chrome the platform draws over the scene included.

KeyDown#

func (session *Session) KeyDown(name string) error

KeyDown presses and holds one key named as Keys names it, without modifiers: a key such as "left" or "x", or a modifier such as "shift", "ctrl", "alt", "cmd" (left side; "rshift", "rctrl", "ralt", "rcmd" for the right). Modifiers stay held for every pointer, scroll and key until KeyUp.

KeyUp#

func (session *Session) KeyUp(name string) error

KeyUp releases a key KeyDown pressed.

Keys#

func (session *Session) Keys(spec string) error

Keys delivers a key chord written as plus-separated parts, for example "tab", "shift+tab", "enter", "backspace", "left", "cmd+a", or a single character such as "x". Command chords are editing shortcuts in text fields; Control and a terminal-configured Alt chord are raw application input. A bare character is typed into the focused text field.

LoseFocus#

func (session *Session) LoseFocus() error

LoseFocus makes the window lose the keyboard: held keys are released.

Move#

func (session *Session) Move(x, y float32) error

Move moves the pointer to a logical-pixel point.

Press#

func (session *Session) Press(x, y float32) error

Press presses the primary button at a point; Release releases it.

PressAt#

func (session *Session) PressAt(x, y float32) app.PressKind

PressAt reports what a press at a point would do in a custom-titlebar window (see app.Driver.PressAt).

Record#

func (session *Session) Record(dir string, options RecordOptions) (int, error)

Record plays options.Duration of animation and writes it to dir as a PNG sequence, frame-0000.png onwards, plus a manifest.json that says how long each frame is on screen. A frame whose pixels did not change is written once and its duration grows instead, so an application at rest records as one still frame rather than hundreds, and a recording costs disk only where something moved. The number of PNG files written is returned; when Record fails partway that is how many were written before the error.

Recording needs the offscreen renderer Image needs, and returns ErrNoRenderer without one. dir is created when it does not exist; use a fresh directory per recording, because a recording shorter than an earlier one in the same directory leaves that recording's frames behind (the manifest lists the ones this one wrote).

The manifest is:

{
  "version": 1,
  "width": 1400, "height": 900, "scale": 2, "fps": 60,
  "duration_ns": 700000000,
  "frames": [{"file": "frame-0000.png", "duration_ns": 16666666}, ...]
}

width and height are logical pixels; the PNG files are scale times that. The durations sum to duration_ns. ffmpeg assembles them with a concat script (file frame-0000.png, duration 0.016666666, and so on), or the frames can be reviewed one by one.

Release#

func (session *Session) Release(x, y float32) error

Release releases the primary button at a point.

Resize#

func (session *Session) Resize(width, height int) error

Resize changes the content size in logical pixels.

Rest#

func (session *Session) Rest() error

Rest advances the animation clock until no transition is in flight, so the frame shows the interface at rest: a dialog that has just been opened is in, not still fading. A slow display, such as a spinner, does not hold it. The clock moves at most five seconds.

RightClick#

func (session *Session) RightClick(x, y float32) error

RightClick presses and releases the secondary button at a logical-pixel point, which is what opens a context menu.

RightClickLabel#

func (session *Session) RightClickLabel(label string) error

RightClickLabel right-clicks the center of the region labelled label.

Screenshot#

func (session *Session) Screenshot(path string) error

Screenshot renders the current frame to a PNG file.

Scroll#

func (session *Session) Scroll(event ui.ScrollEvent) error

Scroll delivers a scroll gesture at a logical-pixel window point.

SetSystemAppearance#

func (session *Session) SetSystemAppearance(appearance app.Appearance)

SetSystemAppearance changes the system appearance the run reports, and tells whoever watches it, as the system would.

Settle#

func (session *Session) Settle(quiet, timeout time.Duration) error

Settle applies background wakes until none arrives for quiet, or timeout passes, so work that was kicked off has landed before the next look.

Snapshot#

func (session *Session) Snapshot() app.Snapshot

Snapshot captures the current frame.

Texts#

func (session *Session) Texts() []string

Texts returns every text the application painted, in paint order.

Type#

func (session *Session) Type(value string) error

Type inserts text into the focused text field.

Wait#

func (session *Session) Wait(duration time.Duration) error

Wait advances the animation clock.

WaitFor#

func (session *Session) WaitFor(condition func(app.Snapshot) bool, timeout time.Duration) error

WaitFor applies background wakes in real time until condition holds for the current frame, or timeout passes. It is for work that takes real time, such as a network connection. The real time it waits also passes for the application's timers: a frame the application asked for in 400 ms is due after 400 ms of waiting, as in a window, so a page that hands over after a delay does so here too. Animations that a script wants to step exactly are moved with Wait instead.