matchInOrder is a chromedp.Action that fetches the text of the first node that matched query and checks that the supplied sequence of strings occur in order in the text.
(t *testing.T, query string, sequence ...string)
| 158 | // node that matched query and checks that the supplied sequence of |
| 159 | // strings occur in order in the text. |
| 160 | func matchInOrder(t *testing.T, query string, sequence ...string) chromedp.ActionFunc { |
| 161 | return func(ctx context.Context) error { |
| 162 | var value string |
| 163 | err := chromedp.Text(query, &value, chromedp.ByQuery).Do(ctx) |
| 164 | if err != nil { |
| 165 | return fmt.Errorf("text %s: %v", query, err) |
| 166 | } |
| 167 | t.Logf("text %s:\n%s", query, value) |
| 168 | remaining := value |
| 169 | for _, s := range sequence { |
| 170 | pos := strings.Index(remaining, s) |
| 171 | if pos < 0 { |
| 172 | return fmt.Errorf("%s: did not find %q in expected order %v in\n%s", query, s, sequence, value) |
| 173 | } |
| 174 | remaining = remaining[pos+len(s):] |
| 175 | } |
| 176 | return nil |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | // eval runs the specified javascript in the browser. The javascript must |
| 181 | // return an [][]any, where each of the []any starts with either "LOG" or |
no outgoing calls
no test coverage detected
searching dependent graphs…