Documentation ¶
Overview ¶
Package wpr manages a Web Page Replay (aka WPR) process and provides chrome.Options to configure Chrome to send all web traffic through the WPR process.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewFixture ¶
func NewFixture(wprAchiveName string, mode Mode) testing.FixtureImpl
NewFixture creates a new fixture that can launch Lacros chrome with the given wpr archive and mode.
func RecordMode ¶
func RecordMode(archive string) testing.Precondition
RecordMode returns a precondition similar to the ReplayMode above except WPR runs in record mode and all sites accessed by Chrome are recorded in the given archive path on the device.
Example usage:
func init() { testing.AddTest(&testing.Test{ Func: DoSomething ... Pre: wpr.RecordMode("/tmp/example_wpr_archive.wprgo"), }) } func DoSomething(ctx context.Context, s *testing.State) { // cr is a logged-in Chrome with net traffic redirected through WPR // and recorded. cr := s.PreValue().(*chrome.Chrome) ... }
func RemoteReplayMode ¶
func RemoteReplayMode() testing.Precondition
RemoteReplayMode returns a precondition that Chrome is logged in, preserving the state and redirects its traffic through a remote WPR.
Example usage:
func init() { testing.AddTest(&testing.Test{ Func: DoSomething ... Pre: wpr.RemoteReplayMode(), }) } func DoSomething(ctx context.Context, s *testing.State) { // cr is a logged-in Chrome with net traffic redirected through WPR // and recorded. cr := s.PreValue().(*chrome.Chrome) ... }
func ReplayMode ¶
func ReplayMode(archive string) testing.Precondition
ReplayMode returns a precondition that WPR is started in replay mode using the given archive as data file of the package and Chrome is logged in and redirects its traffic through WPR.
The precondition is keyed by pkg and archive. Tests of the same package and the same archive would use the same precondition instance and save the time to start WPR and Chrome. Pkg is determined by caller.Get(). Test must supply the name of the archive.
Example usage:
func init() { testing.AddTest(&testing.Test{ Func: DoSomething ... Data: []string{ ..., "example_wpr_archive.wprgo" }, Pre: wpr.ReplayMode("example_wpr_archive.wprgo"), }) } func DoSomething(ctx context.Context, s *testing.State) { // cr is a logged-in Chrome with net traffic redirected to WPR. cr := s.PreValue().(*chrome.Chrome) ... }
Types ¶
type FixtValue ¶
type FixtValue interface {
FOpt() chrome.OptionsCallback
}
FixtValue is an interface for accessing WPR FixtValue members.
type Mode ¶
type Mode int
Mode represents the mode to use in WPR
the mode to use in WPR
Replay is the mode to use when running WPR on local side, and WPR is set to replay all recorded web traffic. Record is the mode to use when running WPR on local side, and WPR is set to record web traffic. RemoteReplay is the mode to use when WPR is running on remote side, and WPR is set to replay all recorded web traffic.
type WPR ¶
type WPR struct { HTTPPort int HTTPSPort int ChromeOptions []chrome.Option // contains filtered or unexported fields }
WPR holds information about WPR process and chrome.Options to configure Chrome to send traffic through the WPR process.