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
|
package chromedp_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/chromedp/chromedp"
|
"github.com/chromedp/chromedp"
|
||||||
)
|
)
|
||||||
|
@ -59,21 +61,18 @@ func ExampleExecAllocatorOption() {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
files, err := ioutil.ReadDir(dir)
|
path := filepath.Join(dir, "DevToolsActivePort")
|
||||||
|
bs, err := ioutil.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
fmt.Println("Files in UserDataDir:")
|
lines := bytes.Split(bs, []byte("\n"))
|
||||||
for _, file := range files {
|
fmt.Printf("DevToolsActivePort has %d lines\n", len(lines))
|
||||||
fmt.Println(file.Name())
|
|
||||||
}
|
|
||||||
|
|
||||||
// wait for the resources to be cleaned up
|
// wait for the resources to be cleaned up
|
||||||
cancel()
|
cancel()
|
||||||
chromedp.FromContext(allocCtx).Allocator.Wait()
|
chromedp.FromContext(allocCtx).Allocator.Wait()
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// Files in UserDataDir:
|
// DevToolsActivePort has 2 lines
|
||||||
// Default
|
|
||||||
// DevToolsActivePort
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user