Documentation
¶
Index ¶
- Constants
- func BuildDirectReactGlobalScript(prepare *PrepareSpec) (string, error)
- func CanonicalInspectFormat(format string) (string, error)
- func CleanCatalogRelativePath(path string) string
- func CloneJSON[T any](value T) (T, error)
- func EnsureInspectSelectorExists(page *driver.Page, req InspectRequest) error
- func InspectFormatRequiresExistingSelector(format string) bool
- func LoadAndPreparePage(page *driver.Page, target PageTarget) error
- func LocatorAttributes(page *driver.Page, locator LocatorSpec, attrs []string) (map[string]string, error)
- func LocatorComputedStyle(page *driver.Page, locator LocatorSpec, props []string) (map[string]string, error)
- func LocatorText(page *driver.Page, locator LocatorSpec, opts TextOptions) (string, error)
- func PrepareTarget(page *driver.Page, target PageTarget) error
- func RenderDiffMarkdown(diff SnapshotDiff) string
- func RootSelectorForTarget(target PageTarget) string
- func RunDirectReactGlobalPrepare(page *driver.Page, prepare *PrepareSpec) error
- func RunScriptPrepare(page *driver.Page, prepare *PrepareSpec) error
- func SanitizeCatalogSlug(slug string) string
- func SanitizeName(name string) string
- func WriteInspectCSSMarkdown(path string, req InspectRequest, style StyleSnapshot) error
- func WriteInspectIndex(outDir string, result InspectResult) error
- func WriteInspectJSON(page *driver.Page, selector, path string) error
- func WriteJSON(path string, data any) error
- func WritePreparedHTML(page *driver.Page, selector, path string) error
- type Bounds
- type BrowserService
- type Catalog
- func (c *Catalog) AddFailure(target CatalogTargetRecord, failure CatalogFailureRecord) CatalogFailureRecord
- func (c *Catalog) AddResult(target CatalogTargetRecord, result InspectResult) CatalogResultRecord
- func (c *Catalog) AddTarget(target CatalogTargetRecord) CatalogTargetRecord
- func (c *Catalog) ArtifactDir(slug string) string
- func (c *Catalog) Manifest() CatalogManifest
- func (c *Catalog) Options() CatalogOptions
- func (c *Catalog) RecordPreflight(target CatalogTargetRecord, statuses []SelectorStatus) CatalogPreflightRecord
- func (c *Catalog) Summary() CatalogSummary
- func (c *Catalog) WriteIndex() (string, error)
- func (c *Catalog) WriteManifest() (string, error)
- type CatalogFailureRecord
- type CatalogManifest
- type CatalogOptions
- type CatalogPreflightRecord
- type CatalogResultRecord
- type CatalogSummary
- type CatalogTargetRecord
- type DiffChange
- type DiffOptions
- type DirectReactGlobalPrepareResult
- type ElementHTML
- type ElementSnapshot
- type ExtractorKind
- type ExtractorSpec
- type InspectAllOptions
- type InspectArtifactResult
- type InspectMetadata
- type InspectRequest
- type InspectResult
- type LocatorSpec
- type PageService
- type PageSnapshot
- type PageTarget
- type PrepareSpec
- type ProbeSnapshot
- type ProbeSpec
- type SelectorStatus
- type SnapshotDiff
- type SnapshotProbeSpec
- type StyleEvalSpec
- type StyleSnapshot
- type TextOptions
- type Viewport
Constants ¶
View Source
const ( InspectFormatBundle = "bundle" InspectFormatPNG = "png" InspectFormatHTML = "html" InspectFormatCSSJSON = "css-json" InspectFormatCSSMarkdown = "css-md" InspectFormatInspectJSON = "inspect-json" InspectFormatMetadataJSON = "metadata-json" )
View Source
const CatalogSchemaVersion = "css-visual-diff.catalog.v1"
View Source
const DefaultPrepareAfterWait = 500 * time.Millisecond
View Source
const DefaultPrepareWaitTimeout = 30 * time.Second
Variables ¶
This section is empty.
Functions ¶
func BuildDirectReactGlobalScript ¶
func BuildDirectReactGlobalScript(prepare *PrepareSpec) (string, error)
func CanonicalInspectFormat ¶
func EnsureInspectSelectorExists ¶
func EnsureInspectSelectorExists(page *driver.Page, req InspectRequest) error
func LoadAndPreparePage ¶
func LoadAndPreparePage(page *driver.Page, target PageTarget) error
func LocatorAttributes ¶
func LocatorComputedStyle ¶
func LocatorText ¶
func LocatorText(page *driver.Page, locator LocatorSpec, opts TextOptions) (string, error)
func PrepareTarget ¶
func PrepareTarget(page *driver.Page, target PageTarget) error
func RenderDiffMarkdown ¶
func RenderDiffMarkdown(diff SnapshotDiff) string
func RootSelectorForTarget ¶
func RootSelectorForTarget(target PageTarget) string
func RunDirectReactGlobalPrepare ¶
func RunDirectReactGlobalPrepare(page *driver.Page, prepare *PrepareSpec) error
func RunScriptPrepare ¶
func RunScriptPrepare(page *driver.Page, prepare *PrepareSpec) error
func SanitizeCatalogSlug ¶
func SanitizeName ¶
func WriteInspectCSSMarkdown ¶
func WriteInspectCSSMarkdown(path string, req InspectRequest, style StyleSnapshot) error
func WriteInspectIndex ¶
func WriteInspectIndex(outDir string, result InspectResult) error
Types ¶
type Bounds ¶
type Bounds struct {
X float64 `json:"x"`
Y float64 `json:"y"`
Width float64 `json:"width"`
Height float64 `json:"height"`
}
func LocatorBounds ¶
func LocatorBounds(page *driver.Page, locator LocatorSpec) (*Bounds, error)
type BrowserService ¶
type BrowserService struct {
// contains filtered or unexported fields
}
func NewBrowserService ¶
func NewBrowserService(ctx context.Context) (*BrowserService, error)
func (*BrowserService) Browser ¶
func (s *BrowserService) Browser() *driver.Browser
func (*BrowserService) Close ¶
func (s *BrowserService) Close()
func (*BrowserService) NewPage ¶
func (s *BrowserService) NewPage() (*PageService, error)
type Catalog ¶
type Catalog struct {
// contains filtered or unexported fields
}
func NewCatalog ¶
func NewCatalog(opts CatalogOptions) (*Catalog, error)
func (*Catalog) AddFailure ¶
func (c *Catalog) AddFailure(target CatalogTargetRecord, failure CatalogFailureRecord) CatalogFailureRecord
func (*Catalog) AddResult ¶
func (c *Catalog) AddResult(target CatalogTargetRecord, result InspectResult) CatalogResultRecord
func (*Catalog) AddTarget ¶
func (c *Catalog) AddTarget(target CatalogTargetRecord) CatalogTargetRecord
func (*Catalog) ArtifactDir ¶
func (*Catalog) Manifest ¶
func (c *Catalog) Manifest() CatalogManifest
func (*Catalog) Options ¶
func (c *Catalog) Options() CatalogOptions
func (*Catalog) RecordPreflight ¶
func (c *Catalog) RecordPreflight(target CatalogTargetRecord, statuses []SelectorStatus) CatalogPreflightRecord
func (*Catalog) Summary ¶
func (c *Catalog) Summary() CatalogSummary
func (*Catalog) WriteIndex ¶
func (*Catalog) WriteManifest ¶
type CatalogFailureRecord ¶
type CatalogManifest ¶
type CatalogManifest struct {
SchemaVersion string `json:"schema_version"`
Title string `json:"title"`
OutDir string `json:"out_dir"`
ArtifactRoot string `json:"artifact_root"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Targets []CatalogTargetRecord `json:"targets"`
Preflights []CatalogPreflightRecord `json:"preflights,omitempty"`
Results []CatalogResultRecord `json:"results,omitempty"`
Failures []CatalogFailureRecord `json:"failures,omitempty"`
Summary CatalogSummary `json:"summary"`
}
type CatalogOptions ¶
type CatalogPreflightRecord ¶
type CatalogPreflightRecord struct {
Target CatalogTargetRecord `json:"target"`
Statuses []SelectorStatus `json:"statuses"`
RecordedAt time.Time `json:"recorded_at"`
}
type CatalogResultRecord ¶
type CatalogResultRecord struct {
Target CatalogTargetRecord `json:"target"`
Result InspectResult `json:"result"`
RecordedAt time.Time `json:"recorded_at"`
}
type CatalogSummary ¶
type CatalogTargetRecord ¶
type CatalogTargetRecord struct {
Slug string `json:"slug"`
Name string `json:"name,omitempty"`
URL string `json:"url,omitempty"`
Selector string `json:"selector,omitempty"`
Viewport Viewport `json:"viewport,omitempty"`
Description string `json:"description,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
}
func NormalizeCatalogTarget ¶
func NormalizeCatalogTarget(target CatalogTargetRecord) CatalogTargetRecord
type DiffChange ¶
type DiffOptions ¶
type DiffOptions struct {
IgnorePaths []string `json:"ignorePaths,omitempty"`
}
type ElementHTML ¶
func LocatorHTML ¶
func LocatorHTML(page *driver.Page, locator LocatorSpec, outer bool) (ElementHTML, error)
type ElementSnapshot ¶
type ElementSnapshot struct {
Selector string `json:"selector"`
Exists *bool `json:"exists,omitempty"`
Visible *bool `json:"visible,omitempty"`
Text string `json:"text,omitempty"`
Bounds *Bounds `json:"bounds,omitempty"`
Computed map[string]string `json:"computed,omitempty"`
Attributes map[string]string `json:"attributes,omitempty"`
}
func ExtractElement ¶
func ExtractElement(page *driver.Page, locator LocatorSpec, extractors []ExtractorSpec) (ElementSnapshot, error)
type ExtractorKind ¶
type ExtractorKind string
const ( ExtractorExists ExtractorKind = "exists" ExtractorVisible ExtractorKind = "visible" ExtractorText ExtractorKind = "text" ExtractorBounds ExtractorKind = "bounds" ExtractorComputedStyle ExtractorKind = "computedStyle" ExtractorAttributes ExtractorKind = "attributes" )
type ExtractorSpec ¶
type ExtractorSpec struct {
Kind ExtractorKind `json:"kind"`
Props []string `json:"props,omitempty"`
Attributes []string `json:"attributes,omitempty"`
Text TextOptions `json:"text,omitempty"`
}
type InspectAllOptions ¶
type InspectArtifactResult ¶
type InspectArtifactResult struct {
Metadata InspectMetadata `json:"metadata"`
Style *StyleSnapshot `json:"style,omitempty"`
Screenshot string `json:"screenshot,omitempty"`
HTML string `json:"html,omitempty"`
InspectJSON string `json:"inspect_json,omitempty"`
}
func WriteInspectArtifacts ¶
func WriteInspectArtifacts(page *driver.Page, target PageTarget, side string, req InspectRequest, format, outDir, outputFile string) (InspectArtifactResult, error)
func WriteSingleInspectArtifact ¶
func WriteSingleInspectArtifact(page *driver.Page, req InspectRequest, metadata InspectMetadata, format, path string) (InspectArtifactResult, error)
type InspectMetadata ¶
type InspectMetadata struct {
Side string `json:"side"`
TargetName string `json:"target_name"`
URL string `json:"url"`
Viewport Viewport `json:"viewport"`
Name string `json:"name"`
Selector string `json:"selector"`
SelectorSource string `json:"selector_source"`
RootSelector string `json:"root_selector,omitempty"`
PrepareType string `json:"prepare_type,omitempty"`
Format string `json:"format"`
CreatedAt time.Time `json:"created_at"`
}
type InspectRequest ¶
type InspectResult ¶
type InspectResult struct {
OutputDir string `json:"output_dir,omitempty"`
Results []InspectArtifactResult `json:"results"`
}
func InspectPreparedPage ¶
func InspectPreparedPage(page *driver.Page, target PageTarget, side string, requests []InspectRequest, opts InspectAllOptions) (InspectResult, error)
type LocatorSpec ¶
type LocatorSpec struct {
Name string `json:"name,omitempty"`
Selector string `json:"selector"`
Source string `json:"source,omitempty"`
}
LocatorSpec identifies one element on a loaded page.
type PageService ¶
type PageService struct {
// contains filtered or unexported fields
}
func (*PageService) Close ¶
func (p *PageService) Close()
func (*PageService) LoadAndPrepareTarget ¶
func (p *PageService) LoadAndPrepareTarget(target PageTarget) error
func (*PageService) Page ¶
func (p *PageService) Page() *driver.Page
type PageSnapshot ¶
type PageSnapshot struct {
Results []ProbeSnapshot `json:"results"`
}
func SnapshotPage ¶
func SnapshotPage(page *driver.Page, probes []SnapshotProbeSpec) (PageSnapshot, error)
type PageTarget ¶ added in v0.0.2
type PageTarget struct {
Name string `json:"name"`
URL string `json:"url"`
WaitMS int `json:"waitMs"`
Viewport Viewport `json:"viewport"`
RootSelector string `json:"rootSelector,omitempty"`
Prepare *PrepareSpec `json:"prepare,omitempty"`
}
PageTarget is what the browser service needs to load and prepare a page.
type PrepareSpec ¶ added in v0.0.2
type PrepareSpec struct {
Type string `json:"type"`
Script string `json:"script"`
ScriptFile string `json:"scriptFile"`
WaitFor string `json:"waitFor"`
WaitForTimeoutMS int `json:"waitForTimeoutMs"`
AfterWaitMS int `json:"afterWaitMs"`
Component string `json:"component"`
Props map[string]any `json:"props"`
RootSelector string `json:"rootSelector"`
Width int `json:"width"`
MinHeight int `json:"minHeight"`
Background string `json:"background"`
}
PrepareSpec describes optional page preparation after navigation.
type ProbeSnapshot ¶
type ProbeSnapshot struct {
Name string `json:"name"`
Selector string `json:"selector"`
Source string `json:"source,omitempty"`
Snapshot ElementSnapshot `json:"snapshot"`
Error string `json:"error,omitempty"`
}
type SelectorStatus ¶
type SelectorStatus struct {
Name string `json:"name,omitempty"`
Selector string `json:"selector"`
Source string `json:"source,omitempty"`
Exists bool `json:"exists"`
Visible bool `json:"visible"`
Bounds *Bounds `json:"bounds,omitempty"`
TextStart string `json:"text_start,omitempty"`
Error string `json:"error,omitempty"`
}
func LocatorStatus ¶
func LocatorStatus(page *driver.Page, locator LocatorSpec) (SelectorStatus, error)
func PreflightProbes ¶
func PreflightProbes(page *driver.Page, probes []ProbeSpec) ([]SelectorStatus, error)
type SnapshotDiff ¶
type SnapshotDiff struct {
Equal bool `json:"equal"`
ChangeCount int `json:"change_count"`
Changes []DiffChange `json:"changes"`
}
func DiffValues ¶
func DiffValues(before, after any, opts DiffOptions) (SnapshotDiff, error)
type SnapshotProbeSpec ¶
type SnapshotProbeSpec struct {
Name string `json:"name"`
Selector string `json:"selector"`
Source string `json:"source,omitempty"`
Required bool `json:"required,omitempty"`
Extractors []ExtractorSpec `json:"extractors"`
}
type StyleEvalSpec ¶ added in v0.0.2
type StyleEvalSpec struct {
Selector string
Props []string
Attributes []string
IncludeBounds bool
Report []string
}
StyleEvalSpec captures the inputs needed to evaluate computed styles for a selector.
type StyleSnapshot ¶
type StyleSnapshot struct {
Exists bool `json:"exists"`
Computed map[string]string `json:"computed"`
Bounds *Bounds `json:"bounds,omitempty"`
Attributes map[string]string `json:"attributes,omitempty"`
}
func EvaluateStyle ¶
func EvaluateStyle(page *driver.Page, spec StyleEvalSpec) (StyleSnapshot, error)
type TextOptions ¶
Click to show internal directories.
Click to hide internal directories.