webscenario

package
v0.0.0-...-f590a89 Latest Latest
Warning

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

Go to latest
Published: May 12, 2023 License: MIT Imports: 46 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SourceWidth = 600
	LineHeight  = 20
)

Variables

View Source
var (
	Version = "HEAD"
	Commit  = "UNKNOWN"
)
View Source
var (
	NoRecord = errors.New("no record")
)

Functions

func AsFileLikeMeta

func AsFileLikeMeta(L *lua.LState, r io.Reader) *lua.LTable

func AsyncRun

func AsyncRun[T any](env *Environment, L *lua.LState, f func() (T, error)) T

AsyncRun makes a chance to execute callback function while executing a heavy function.

func HandleError

func HandleError(L *lua.LState, err error)

func LValueToString

func LValueToString(v lua.LValue) string

func NewContext

func NewContext(arg Arg, debuglog *ayd.Logger) (context.Context, context.CancelFunc)

func NewElementsTable

func NewElementsTable(L *lua.LState, t *Tab, query string) *lua.LTable

func NewElementsTableByXPath

func NewElementsTableByXPath(L *lua.LState, t *Tab, query string) *lua.LTable

func NewExecAllocator

func NewExecAllocator(ctx context.Context, withHead bool) (context.Context, context.CancelFunc)

func PackFetchHeader

func PackFetchHeader(L *lua.LState, h http.Header) lua.LValue

func PackFetchResponse

func PackFetchResponse(env *Environment, L *lua.LState, resp *http.Response, body io.Reader) lua.LValue

func PackLValue

func PackLValue(L *lua.LState, value any) lua.LValue

func RegisterAssert

func RegisterAssert(L *lua.LState)

func RegisterElementType

func RegisterElementType(ctx context.Context, L *lua.LState)

func RegisterEncodings

func RegisterEncodings(env *Environment)

func RegisterFetch

func RegisterFetch(ctx context.Context, env *Environment)

func RegisterFileLike

func RegisterFileLike(L *lua.LState)

func RegisterKey

func RegisterKey(L *lua.LState)

func RegisterLogger

func RegisterLogger(L *lua.LState, logger *Logger)

func RegisterTabType

func RegisterTabType(ctx context.Context, env *Environment)

func RegisterTime

func RegisterTime(ctx context.Context, env *Environment)

func Run

func Run(arg Arg) ayd.Record

func URLToTable

func URLToTable(L *lua.LState, u *ayd.URL) *lua.LTable

func UnpackFetchHeader

func UnpackFetchHeader(L *lua.LState, lv lua.LValue) (http.Header, error)

func UnpackLValue

func UnpackLValue(v lua.LValue) any

Types

type Arg

type Arg struct {
	Mode      string
	Args      []string
	Target    *ayd.URL
	Alert     ayd.Record
	Timeout   time.Duration
	Debug     bool
	Head      bool
	Recording bool
}

func (Arg) ArtifactDir

func (a Arg) ArtifactDir(basedir string) string

func (Arg) Path

func (a Arg) Path() string

func (Arg) Register

func (a Arg) Register(L *lua.LState)

type CookieJar

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

func CheckCookieJar

func CheckCookieJar(L *lua.LState, n int) *CookieJar

func NewCookieJar

func NewCookieJar(id int) (*CookieJar, error)

func (*CookieJar) Cookies

func (j *CookieJar) Cookies(u *url.URL) []*http.Cookie

func (*CookieJar) CookiesAsLua

func (j *CookieJar) CookiesAsLua(L *lua.LState, u *url.URL) (*lua.LTable, bool)

func (*CookieJar) SetCookies

func (j *CookieJar) SetCookies(u *url.URL, cookies []*http.Cookie)

func (*CookieJar) ToLua

func (j *CookieJar) ToLua(L *lua.LState) lua.LValue

type DelayedReader

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

func NewDelayedReader

func NewDelayedReader(f func() io.Reader) *DelayedReader

func (*DelayedReader) Read

func (r *DelayedReader) Read(p []byte) (int, error)

type Element

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

func CheckElement

func CheckElement(L *lua.LState) Element

func NewElement

func NewElement(L *lua.LState, t *Tab, query string) Element

func (Element) Blur

func (e Element) Blur(L *lua.LState)

func (Element) Click

func (e Element) Click(L *lua.LState)

func (Element) Focus

func (e Element) Focus(L *lua.LState)

func (Element) GetAttribute

func (e Element) GetAttribute(L *lua.LState) int

func (Element) GetInnerHTML

func (e Element) GetInnerHTML(L *lua.LState) int

func (Element) GetOuterHTML

func (e Element) GetOuterHTML(L *lua.LState) int

func (Element) GetText

func (e Element) GetText(L *lua.LState) int

func (Element) GetValue

func (e Element) GetValue(L *lua.LState) int

func (Element) Screenshot

func (e Element) Screenshot(L *lua.LState)

func (Element) Select

func (e Element) Select(L *lua.LState, query string) Element

func (Element) SelectAll

func (e Element) SelectAll(L *lua.LState, query string) *lua.LTable

func (Element) SendKeys

func (e Element) SendKeys(L *lua.LState)

func (Element) SetValue

func (e Element) SetValue(L *lua.LState)

func (Element) Submit

func (e Element) Submit(L *lua.LState)

func (Element) ToLua

func (e Element) ToLua(L *lua.LState) *lua.LUserData

type Encodings

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

func (Encodings) FromCSV

func (e Encodings) FromCSV(L *lua.LState) int

func (Encodings) FromJSON

func (e Encodings) FromJSON(L *lua.LState) int

func (Encodings) FromXML

func (e Encodings) FromXML(L *lua.LState) int

func (Encodings) ToCSV

func (e Encodings) ToCSV(L *lua.LState) int

func (Encodings) ToJSON

func (e Encodings) ToJSON(L *lua.LState) int

func (Encodings) ToXML

func (e Encodings) ToXML(L *lua.LState) int

type Environment

type Environment struct {
	sync.Mutex // this mutex works like the GIL in Python.

	EnableRecording bool
	// contains filtered or unexported fields
}

func NewEnvironment

func NewEnvironment(ctx context.Context, logger *Logger, s *Storage, arg Arg) *Environment

func (*Environment) BuildTable

func (env *Environment) BuildTable(build func(L *lua.LState, tbl *lua.LTable)) *lua.LTable

func (*Environment) CallEventHandler

func (env *Environment) CallEventHandler(f *lua.LFunction, arg *lua.LTable, nret int) []lua.LValue

CallEventHandler calls an event callback function with GIL.

func (*Environment) Close

func (env *Environment) Close() error

func (*Environment) DoFile

func (env *Environment) DoFile(path string) error

func (*Environment) DoREPL

func (env *Environment) DoREPL(ctx context.Context) error

func (*Environment) DoStream

func (env *Environment) DoStream(r io.Reader, name string) error

func (*Environment) NewFunction

func (env *Environment) NewFunction(f lua.LGFunction) *lua.LFunction

func (*Environment) RecordOnAllTabs

func (env *Environment) RecordOnAllTabs(L *lua.LState, taskName string)

func (*Environment) RegisterFunction

func (env *Environment) RegisterFunction(name string, f lua.LGFunction)

func (*Environment) RegisterNewType

func (env *Environment) RegisterNewType(name string, methods map[string]lua.LGFunction, fields map[string]lua.LValue)

func (*Environment) RegisterTable

func (env *Environment) RegisterTable(name string, fields, meta map[string]lua.LValue)

func (*Environment) StartTask

func (env *Environment) StartTask(where, taskName string)

func (*Environment) Yield

func (env *Environment) Yield()

Yield makes a chance to execute callback function.

type EventHandleFunc

type EventHandleFunc func(*Tab, *lua.LFunction, *lua.LTable)

type EventHandler

type EventHandler struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewEventHandler

func NewEventHandler(handle EventHandleFunc) *EventHandler

func (*EventHandler) Close

func (h *EventHandler) Close() error

func (*EventHandler) Invoke

func (h *EventHandler) Invoke(tab *Tab, event *lua.LTable)

func (*EventHandler) IsFuncSet

func (h *EventHandler) IsFuncSet() bool

func (*EventHandler) SetFunc

func (h *EventHandler) SetFunc(f *lua.LFunction)

func (*EventHandler) Status

func (h *EventHandler) Status(L *lua.LState) *lua.LTable

func (*EventHandler) Wait

func (h *EventHandler) Wait(ctx context.Context) *lua.LTable

type LoadWaiter

type LoadWaiter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewLoadWaiter

func NewLoadWaiter() *LoadWaiter

func (*LoadWaiter) Complete

func (l *LoadWaiter) Complete(id network.RequestID)

func (*LoadWaiter) Wait

func (l *LoadWaiter) Wait(id network.RequestID)

type Logger

type Logger struct {
	sync.Mutex

	Stream     io.Writer
	Debug      bool
	Logs       []string
	Status     ayd.Status
	Latency    time.Duration
	LatencySet bool
	Extra      map[string]any
}

func (*Logger) AsRecord

func (l *Logger) AsRecord(timestamp time.Time, latency time.Duration) ayd.Record

func (*Logger) HandleError

func (l *Logger) HandleError(ctx context.Context, err error)

func (*Logger) Print

func (l *Logger) Print(values ...lua.LValue)

func (*Logger) SetExtra

func (l *Logger) SetExtra(k string, v any)

func (*Logger) SetLatency

func (l *Logger) SetLatency(milliseconds float64)

func (*Logger) SetStatus

func (l *Logger) SetStatus(status string)

func (*Logger) StartTask

func (l *Logger) StartTask(where, name string)

func (*Logger) UnsetLatency

func (l *Logger) UnsetLatency()

type RecordAction

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

func (RecordAction) Do

func (a RecordAction) Do(ctx context.Context) error

type Recorder

type Recorder struct {
	Done chan struct{}
	// contains filtered or unexported fields
}

func NewRecorder

func NewRecorder(ctx context.Context, width, height int) *Recorder

func (*Recorder) Record

func (r *Recorder) Record(where string, screenshot *[]byte) RecordAction

func (*Recorder) SaveTo

func (r *Recorder) SaveTo(f io.Writer) error

type SourceImager

type SourceImager struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewSourceImager

func NewSourceImager() (*SourceImager, error)

func (*SourceImager) Load

func (s *SourceImager) Load(path string) ([]string, error)

func (*SourceImager) LoadAsImage

func (s *SourceImager) LoadAsImage(img *image.Paletted, rect image.Rectangle, path string, line int)

func (*SourceImager) RecordStdin

func (s *SourceImager) RecordStdin(lines []string)

type SourceRecordReader

type SourceRecordReader struct {
	Upstream io.Reader
	// contains filtered or unexported fields
}

func (*SourceRecordReader) Read

func (r *SourceRecordReader) Read(b []byte) (int, error)

type Storage

type Storage struct {
	sync.Mutex

	Dir string
	// contains filtered or unexported fields
}

func NewStorage

func NewStorage(baseDir string, timestamp time.Time) (*Storage, error)

func (*Storage) Artifacts

func (s *Storage) Artifacts() []string

func (*Storage) CancelDownload

func (s *Storage) CancelDownload(guid string)

func (*Storage) CompleteDownload

func (s *Storage) CompleteDownload(guid string) string

func (*Storage) Open

func (s *Storage) Open(name string) (*os.File, error)

func (*Storage) Register

func (s *Storage) Register(env *Environment)

func (*Storage) Remove

func (s *Storage) Remove(path string) error

func (*Storage) Save

func (s *Storage) Save(name, ext string, data []byte) error

func (*Storage) StartDownload

func (s *Storage) StartDownload(guid, name string)

type Tab

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

func CheckTab

func CheckTab(L *lua.LState) *Tab

func NewTab

func NewTab(ctx context.Context, L *lua.LState, env *Environment, id int) *Tab

func (*Tab) Back

func (t *Tab) Back(L *lua.LState)

func (*Tab) Close

func (t *Tab) Close() error

func (*Tab) Eval

func (t *Tab) Eval(L *lua.LState) int

func (*Tab) Forward

func (t *Tab) Forward(L *lua.LState)

func (*Tab) GetDialogs

func (t *Tab) GetDialogs(L *lua.LState) int

func (*Tab) GetDownload

func (t *Tab) GetDownload(L *lua.LState) int

func (*Tab) GetRequest

func (t *Tab) GetRequest(L *lua.LState) int

func (*Tab) GetResponse

func (t *Tab) GetResponse(L *lua.LState) int

func (*Tab) GetTitle

func (t *Tab) GetTitle(L *lua.LState) int

func (*Tab) GetURL

func (t *Tab) GetURL(L *lua.LState) int

func (*Tab) GetViewport

func (t *Tab) GetViewport(L *lua.LState) int

func (*Tab) Go

func (t *Tab) Go(L *lua.LState)

func (*Tab) HandleDialog

func (t *Tab) HandleDialog(f *lua.LFunction, ev *lua.LTable)

func (*Tab) HandleEvent

func (t *Tab) HandleEvent(f *lua.LFunction, ev *lua.LTable)

func (*Tab) LClose

func (t *Tab) LClose(L *lua.LState)

func (*Tab) OnDialog

func (t *Tab) OnDialog(L *lua.LState)

func (*Tab) OnDownload

func (t *Tab) OnDownload(L *lua.LState)

func (*Tab) OnRequest

func (t *Tab) OnRequest(L *lua.LState)

func (*Tab) OnResponse

func (t *Tab) OnResponse(L *lua.LState)

func (*Tab) RecordOnce

func (t *Tab) RecordOnce(L *lua.LState, taskName string)

func (*Tab) Reload

func (t *Tab) Reload(L *lua.LState)

func (*Tab) Run

func (t *Tab) Run(L *lua.LState, taskName string, capture bool, timeout time.Duration, action ...chromedp.Action)

func (*Tab) RunInCallback

func (t *Tab) RunInCallback(actions ...chromedp.Action) error

RunCallback execute browser action without to release GIL.

func (*Tab) RunSelector

func (t *Tab) RunSelector(L *lua.LState, taskName string, action ...chromedp.Action)

func (*Tab) Save

func (t *Tab) Save(name, ext string, data []byte) error

func (*Tab) Screenshot

func (t *Tab) Screenshot(L *lua.LState)

func (*Tab) ToLua

func (t *Tab) ToLua(L *lua.LState) *lua.LUserData

func (*Tab) Wait

func (t *Tab) Wait(L *lua.LState)

func (*Tab) WaitDialog

func (t *Tab) WaitDialog(L *lua.LState) int

func (*Tab) WaitDownload

func (t *Tab) WaitDownload(L *lua.LState) int

func (*Tab) WaitEvent

func (t *Tab) WaitEvent(L *lua.LState, taskName string, h *EventHandler) int

func (*Tab) WaitRequest

func (t *Tab) WaitRequest(L *lua.LState) int

func (*Tab) WaitResponse

func (t *Tab) WaitResponse(L *lua.LState) int

func (*Tab) WaitVisible

func (t *Tab) WaitVisible(L *lua.LState)

func (*Tab) WaitXPath

func (t *Tab) WaitXPath(L *lua.LState)

func (*Tab) WaitXPathVisible

func (t *Tab) WaitXPathVisible(L *lua.LState)

Jump to

Keyboard shortcuts

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