3d3bf22ccc
First, we want all of the functionality in a single package; this means collapsing whatever is useful into the root chromedp package. The runner package is being replaced by the Allocator interface, with a default implementation which starts browser processes. The client package doesn't really have a place in the new design. The context, allocator, and browser types will handle the connection with each browser. Finally, the new API is context-based, hence the addition of context.go. The tests have been modified to build and run against the new API.
44 lines
849 B
Go
44 lines
849 B
Go
package chromedp
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestExecAllocator(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
poolCtx, cancel := NewAllocator(context.Background(), WithExecAllocator(allocOpts...))
|
|
defer cancel()
|
|
|
|
// TODO: test that multiple child contexts are run in different
|
|
// processes and browsers.
|
|
|
|
taskCtx, cancel := NewContext(poolCtx)
|
|
defer cancel()
|
|
|
|
want := "insert"
|
|
var got string
|
|
if err := Run(taskCtx, Tasks{
|
|
Navigate(testdataDir + "/form.html"),
|
|
Text("#foo", &got, ByID),
|
|
}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got != want {
|
|
t.Fatalf("wanted %q, got %q", want, got)
|
|
}
|
|
|
|
tempDir := FromContext(taskCtx).browser.UserDataDir
|
|
pool := FromContext(taskCtx).Allocator
|
|
|
|
cancel()
|
|
pool.Wait()
|
|
|
|
if _, err := os.Lstat(tempDir); os.IsNotExist(err) {
|
|
return
|
|
}
|
|
t.Fatalf("temporary user data dir %q not deleted", tempDir)
|
|
}
|