make ExampleExecAllocatorOption less flaky
The Default folder is created asynchronously to Chrome starting to listen on the debugging protocol port. So we can't expect it to exist. Instead, base the example on DevToolsActivePort, which we can rely on.
This commit is contained in:
parent
32d4bae280
commit
0e92de5e65
|
@ -1,10 +1,12 @@
|
|||
package chromedp_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/chromedp/chromedp"
|
||||
)
|
||||
|
@ -59,21 +61,18 @@ func ExampleExecAllocatorOption() {
|
|||
panic(err)
|
||||
}
|
||||
|
||||
files, err := ioutil.ReadDir(dir)
|
||||
path := filepath.Join(dir, "DevToolsActivePort")
|
||||
bs, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("Files in UserDataDir:")
|
||||
for _, file := range files {
|
||||
fmt.Println(file.Name())
|
||||
}
|
||||
lines := bytes.Split(bs, []byte("\n"))
|
||||
fmt.Printf("DevToolsActivePort has %d lines\n", len(lines))
|
||||
|
||||
// wait for the resources to be cleaned up
|
||||
cancel()
|
||||
chromedp.FromContext(allocCtx).Allocator.Wait()
|
||||
|
||||
// Output:
|
||||
// Files in UserDataDir:
|
||||
// Default
|
||||
// DevToolsActivePort
|
||||
// DevToolsActivePort has 2 lines
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user