clean up uses of Run in the tests

Many consecutive calls to Run can be collapsed into a single call. While
at it, make the error handling style more consistent. Overall removes 70
lines of repetitive code.
This commit is contained in:
Daniel Martí 2019-04-01 19:46:47 +01:00
parent 120628a01c
commit e482cdfc4d
5 changed files with 121 additions and 190 deletions

View File

@ -40,8 +40,7 @@ func MouseClickXY(x, y int64, opts ...MouseOption) Action {
me = o(me) me = o(me)
} }
err := me.Do(ctx, h) if err := me.Do(ctx, h); err != nil {
if err != nil {
return err return err
} }

View File

@ -38,12 +38,11 @@ func TestMouseClickXY(t *testing.T) {
} }
for i, test := range tests { for i, test := range tests {
if err := Run(ctx, MouseClickXY(test.x, test.y)); err != nil {
t.Fatalf("test %d got error: %v", i, err)
}
var xstr, ystr string var xstr, ystr string
if err := Run(ctx, Value("#input1", &xstr, ByID)); err != nil { if err := Run(ctx,
MouseClickXY(test.x, test.y),
Value("#input1", &xstr, ByID),
); err != nil {
t.Fatalf("test %d got error: %v", i, err) t.Fatalf("test %d got error: %v", i, err)
} }
@ -96,16 +95,14 @@ func TestMouseClickNode(t *testing.T) {
if err := Run(ctx, Nodes(test.sel, &nodes, test.by)); err != nil { if err := Run(ctx, Nodes(test.sel, &nodes, test.by)); err != nil {
t.Fatalf("got error: %v", err) t.Fatalf("got error: %v", err)
} }
if len(nodes) != 1 { if len(nodes) != 1 {
t.Fatalf("expected nodes to have exactly 1 element, got: %d", len(nodes)) t.Fatalf("expected nodes to have exactly 1 element, got: %d", len(nodes))
} }
if err := Run(ctx, MouseClickNode(nodes[0], test.opt)); err != nil {
t.Fatalf("got error: %v", err)
}
var value string var value string
if err := Run(ctx, Value("#input3", &value, ByID)); err != nil { if err := Run(ctx,
MouseClickNode(nodes[0], test.opt),
Value("#input3", &value, ByID),
); err != nil {
t.Fatalf("got error: %v", err) t.Fatalf("got error: %v", err)
} }
@ -204,10 +201,10 @@ func TestKeyAction(t *testing.T) {
if len(nodes) != 1 { if len(nodes) != 1 {
t.Fatalf("expected nodes to have exactly 1 element, got: %d", len(nodes)) t.Fatalf("expected nodes to have exactly 1 element, got: %d", len(nodes))
} }
if err := Run(ctx, Focus(test.sel, test.by)); err != nil { if err := Run(ctx,
t.Fatalf("got error: %v", err) Focus(test.sel, test.by),
} KeyAction(test.exp),
if err := Run(ctx, KeyAction(test.exp)); err != nil { ); err != nil {
t.Fatalf("got error: %v", err) t.Fatalf("got error: %v", err)
} }
@ -254,12 +251,11 @@ func TestKeyActionNode(t *testing.T) {
if len(nodes) != 1 { if len(nodes) != 1 {
t.Fatalf("expected nodes to have exactly 1 element, got: %d", len(nodes)) t.Fatalf("expected nodes to have exactly 1 element, got: %d", len(nodes))
} }
if err := Run(ctx, KeyActionNode(nodes[0], test.exp)); err != nil {
t.Fatalf("got error: %v", err)
}
var value string var value string
if err := Run(ctx, Value(test.sel, &value, test.by)); err != nil { if err := Run(ctx,
KeyActionNode(nodes[0], test.exp),
Value(test.sel, &value, test.by),
); err != nil {
t.Fatalf("got error: %v", err) t.Fatalf("got error: %v", err)
} }

View File

@ -21,15 +21,13 @@ func TestNavigate(t *testing.T) {
ctx, cancel := testAllocate(t, "image.html") ctx, cancel := testAllocate(t, "image.html")
defer cancel() defer cancel()
if err := Run(ctx, WaitVisible(`#icon-brankas`, ByID)); err != nil {
t.Fatal(err)
}
var urlstr string var urlstr string
if err := Run(ctx, Location(&urlstr)); err != nil { if err := Run(ctx,
Location(&urlstr),
WaitVisible(`#icon-brankas`, ByID),
); err != nil {
t.Fatal(err) t.Fatal(err)
} }
if !strings.HasSuffix(urlstr, "image.html") { if !strings.HasSuffix(urlstr, "image.html") {
t.Errorf("expected to be on image.html, at: %s", urlstr) t.Errorf("expected to be on image.html, at: %s", urlstr)
} }
@ -265,13 +263,10 @@ func TestCaptureScreenshot(t *testing.T) {
defer cancel() defer cancel()
var scriptID page.ScriptIdentifier var scriptID page.ScriptIdentifier
err = Run(ctx, AddOnLoadScript(`window.alert("TEST")`, &scriptID)) if err := Run(ctx,
if err != nil { AddOnLoadScript(`window.alert("TEST")`, &scriptID),
t.Fatal(err) Navigate(testdataDir+"/form.html"),
} ); err != nil {
err = Run(ctx, Navigate(testdataDir+"/form.html"))
if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -288,22 +283,17 @@ func TestRemoveOnLoadScript(t *testing.T) {
defer cancel() defer cancel()
var scriptID page.ScriptIdentifier var scriptID page.ScriptIdentifier
err = Run(ctx, AddOnLoadScript(`window.alert("TEST")`, &scriptID)) if err := Run(ctx, AddOnLoadScript(`window.alert("TEST")`, &scriptID)); err != nil {
if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if scriptID == "" { if scriptID == "" {
t.Fatal("got empty script ID") t.Fatal("got empty script ID")
} }
err = Run(ctx, RemoveOnLoadScript(scriptID)) if err := Run(ctx,
if err != nil { RemoveOnLoadScript(scriptID),
t.Fatal(err) Navigate(testdataDir+"/form.html"),
} ); err != nil {
err = Run(ctx, Navigate(testdataDir+"/form.html"))
if err != nil {
t.Fatal(err) t.Fatal(err)
} }
}*/ }*/

View File

@ -95,28 +95,26 @@ func TestFocusBlur(t *testing.T) {
{"#input1", ByID}, {"#input1", ByID},
} }
err := Run(ctx, Click("#input1", ByID)) if err := Run(ctx, Click("#input1", ByID)); err != nil {
if err != nil {
t.Fatal(err) t.Fatal(err)
} }
for i, test := range tests { for i, test := range tests {
if err := Run(ctx, Focus(test.sel, test.by)); err != nil {
t.Fatalf("test %d got error: %v", i, err)
}
var value string var value string
if err := Run(ctx, Value(test.sel, &value, test.by)); err != nil { if err := Run(ctx,
Focus(test.sel, test.by),
Value(test.sel, &value, test.by),
); err != nil {
t.Fatalf("test %d got error: %v", i, err) t.Fatalf("test %d got error: %v", i, err)
} }
if value != "9999" { if value != "9999" {
t.Errorf("test %d expected value is '9999', got: '%s'", i, value) t.Errorf("test %d expected value is '9999', got: '%s'", i, value)
} }
if err := Run(ctx, Blur(test.sel, test.by)); err != nil { if err := Run(ctx,
t.Fatalf("test %d got error: %v", i, err) Blur(test.sel, test.by),
} Value(test.sel, &value, test.by),
if err := Run(ctx, Value(test.sel, &value, test.by)); err != nil { ); err != nil {
t.Fatalf("test %d got error: %v", i, err) t.Fatalf("test %d got error: %v", i, err)
} }
@ -218,20 +216,18 @@ func TestClear(t *testing.T) {
defer cancel() defer cancel()
var val string var val string
err := Run(ctx, Value(test.sel, &val, test.by)) if err := Run(ctx, Value(test.sel, &val, test.by)); err != nil {
if err != nil {
t.Fatalf("got error: %v", err) t.Fatalf("got error: %v", err)
} }
if val == "" { if val == "" {
t.Errorf("expected `%s` to have non empty value", test.sel) t.Errorf("expected `%s` to have non empty value", test.sel)
} }
if err := Run(ctx, Clear(test.sel, test.by)); err != nil { if err := Run(ctx,
Clear(test.sel, test.by),
Value(test.sel, &val, test.by),
); err != nil {
t.Fatalf("got error: %v", err) t.Fatalf("got error: %v", err)
} }
if err := Run(ctx, Value(test.sel, &val, test.by)); err != nil {
t.Fatalf("got error: %v", err)
}
if val != "" { if val != "" {
t.Errorf("expected empty value for `%s`, got: %s", test.sel, val) t.Errorf("expected empty value for `%s`, got: %s", test.sel, val)
} }
@ -262,16 +258,12 @@ func TestReset(t *testing.T) {
ctx, cancel := testAllocate(t, "form.html") ctx, cancel := testAllocate(t, "form.html")
defer cancel() defer cancel()
err := Run(ctx, SetValue(test.sel, test.value, test.by))
if err != nil {
t.Fatalf("got error: %v", err)
}
if err := Run(ctx, Reset(test.sel, test.by)); err != nil {
t.Fatalf("got error: %v", err)
}
var value string var value string
if err := Run(ctx, Value(test.sel, &value, test.by)); err != nil { if err := Run(ctx,
SetValue(test.sel, test.value, test.by),
Reset(test.sel, test.by),
Value(test.sel, &value, test.by),
); err != nil {
t.Fatalf("got error: %v", err) t.Fatalf("got error: %v", err)
} }
@ -331,13 +323,11 @@ func TestSetValue(t *testing.T) {
ctx, cancel := testAllocate(t, "form.html") ctx, cancel := testAllocate(t, "form.html")
defer cancel() defer cancel()
err := Run(ctx, SetValue(test.sel, "FOOBAR", test.by))
if err != nil {
t.Fatalf("got error: %v", err)
}
var value string var value string
if err := Run(ctx, Value(test.sel, &value, test.by)); err != nil { if err := Run(ctx,
SetValue(test.sel, "FOOBAR", test.by),
Value(test.sel, &value, test.by),
); err != nil {
t.Fatalf("got error: %v", err) t.Fatalf("got error: %v", err)
} }
@ -506,8 +496,7 @@ func TestSetAttributes(t *testing.T) {
ctx, cancel := testAllocate(t, "image.html") ctx, cancel := testAllocate(t, "image.html")
defer cancel() defer cancel()
err := Run(ctx, SetAttributes(test.sel, test.attrs, test.by)) if err := Run(ctx, SetAttributes(test.sel, test.attrs, test.by)); err != nil {
if err != nil {
t.Fatalf("got error: %v", err) t.Fatalf("got error: %v", err)
} }
@ -550,11 +539,9 @@ func TestAttributeValue(t *testing.T) {
if err := Run(ctx, AttributeValue(test.sel, test.attr, &value, &ok, test.by)); err != nil { if err := Run(ctx, AttributeValue(test.sel, test.attr, &value, &ok, test.by)); err != nil {
t.Fatalf("test %d got error: %v", i, err) t.Fatalf("test %d got error: %v", i, err)
} }
if !ok { if !ok {
t.Fatalf("test %d failed to get attribute %s on %s", i, test.attr, test.sel) t.Fatalf("test %d failed to get attribute %s on %s", i, test.attr, test.sel)
} }
if value != test.exp { if value != test.exp {
t.Errorf("test %d expected %s to be %s, got: %s", i, test.attr, test.exp, value) t.Errorf("test %d expected %s to be %s, got: %s", i, test.attr, test.exp, value)
} }
@ -584,8 +571,7 @@ func TestSetAttributeValue(t *testing.T) {
ctx, cancel := testAllocate(t, "form.html") ctx, cancel := testAllocate(t, "form.html")
defer cancel() defer cancel()
err := Run(ctx, SetAttributeValue(test.sel, test.attr, test.exp, test.by)) if err := Run(ctx, SetAttributeValue(test.sel, test.attr, test.exp, test.by)); err != nil {
if err != nil {
t.Fatalf("got error: %v", err) t.Fatalf("got error: %v", err)
} }
@ -597,11 +583,9 @@ func TestSetAttributeValue(t *testing.T) {
if err := Run(ctx, AttributeValue(test.sel, test.attr, &value, &ok, test.by)); err != nil { if err := Run(ctx, AttributeValue(test.sel, test.attr, &value, &ok, test.by)); err != nil {
t.Fatalf("got error: %v", err) t.Fatalf("got error: %v", err)
} }
if !ok { if !ok {
t.Fatalf("failed to get attribute %s on %s", test.attr, test.sel) t.Fatalf("failed to get attribute %s on %s", test.attr, test.sel)
} }
if value != test.exp { if value != test.exp {
t.Errorf("expected %s to be %s, got: %s", test.attr, test.exp, value) t.Errorf("expected %s to be %s, got: %s", test.attr, test.exp, value)
} }
@ -631,8 +615,7 @@ func TestRemoveAttribute(t *testing.T) {
ctx, cancel := testAllocate(t, "image.html") ctx, cancel := testAllocate(t, "image.html")
defer cancel() defer cancel()
err := Run(ctx, RemoveAttribute(test.sel, test.attr)) if err := Run(ctx, RemoveAttribute(test.sel, test.attr)); err != nil {
if err != nil {
t.Fatalf("got error: %v", err) t.Fatalf("got error: %v", err)
} }
@ -644,7 +627,6 @@ func TestRemoveAttribute(t *testing.T) {
if err := Run(ctx, AttributeValue(test.sel, test.attr, &value, &ok, test.by)); err != nil { if err := Run(ctx, AttributeValue(test.sel, test.attr, &value, &ok, test.by)); err != nil {
t.Fatalf("got error: %v", err) t.Fatalf("got error: %v", err)
} }
if ok || value != "" { if ok || value != "" {
t.Fatalf("expected attribute %s removed from element %s", test.attr, test.sel) t.Fatalf("expected attribute %s removed from element %s", test.attr, test.sel)
} }
@ -673,16 +655,12 @@ func TestClick(t *testing.T) {
ctx, cancel := testAllocate(t, "form.html") ctx, cancel := testAllocate(t, "form.html")
defer cancel() defer cancel()
err := Run(ctx, Click(test.sel, test.by))
if err != nil {
t.Fatalf("got error: %v", err)
}
if err := Run(ctx, WaitVisible("#icon-brankas", ByID)); err != nil {
t.Fatalf("got error: %v", err)
}
var title string var title string
if err := Run(ctx, Title(&title)); err != nil { if err := Run(ctx,
Click(test.sel, test.by),
WaitVisible("#icon-brankas", ByID),
Title(&title),
); err != nil {
t.Fatalf("got error: %v", err) t.Fatalf("got error: %v", err)
} }
@ -714,13 +692,11 @@ func TestDoubleClick(t *testing.T) {
ctx, cancel := testAllocate(t, "js.html") ctx, cancel := testAllocate(t, "js.html")
defer cancel() defer cancel()
err := Run(ctx, DoubleClick(test.sel, test.by))
if err != nil {
t.Fatalf("got error: %v", err)
}
var value string var value string
if err := Run(ctx, Value("#input1", &value, ByID)); err != nil { if err := Run(ctx,
DoubleClick(test.sel, test.by),
Value("#input1", &value, ByID),
); err != nil {
t.Fatalf("got error: %v", err) t.Fatalf("got error: %v", err)
} }
@ -756,13 +732,11 @@ func TestSendKeys(t *testing.T) {
ctx, cancel := testAllocate(t, "visible.html") ctx, cancel := testAllocate(t, "visible.html")
defer cancel() defer cancel()
err := Run(ctx, SendKeys(test.sel, test.keys, test.by))
if err != nil {
t.Fatalf("got error: %v", err)
}
var val string var val string
if err := Run(ctx, Value(test.sel, &val, test.by)); err != nil { if err := Run(ctx,
SendKeys(test.sel, test.keys, test.by),
Value(test.sel, &val, test.by),
); err != nil {
t.Fatalf("got error: %v", err) t.Fatalf("got error: %v", err)
} }
@ -841,16 +815,12 @@ func TestSubmit(t *testing.T) {
ctx, cancel := testAllocate(t, "form.html") ctx, cancel := testAllocate(t, "form.html")
defer cancel() defer cancel()
err := Run(ctx, Submit(test.sel, test.by))
if err != nil {
t.Fatalf("got error: %v", err)
}
if err := Run(ctx, WaitVisible("#icon-brankas", ByID)); err != nil {
t.Fatalf("got error: %v", err)
}
var title string var title string
if err := Run(ctx, Title(&title)); err != nil { if err := Run(ctx,
Submit(test.sel, test.by),
WaitVisible("#icon-brankas", ByID),
Title(&title),
); err != nil {
t.Fatalf("got error: %v", err) t.Fatalf("got error: %v", err)
} }
@ -883,8 +853,7 @@ func TestComputedStyle(t *testing.T) {
defer cancel() defer cancel()
var styles []*css.ComputedProperty var styles []*css.ComputedProperty
err := Run(ctx, ComputedStyle(test.sel, &styles, test.by)) if err := Run(ctx, ComputedStyle(test.sel, &styles, test.by)); err != nil {
if err != nil {
t.Fatalf("got error: %v", err) t.Fatalf("got error: %v", err)
} }
@ -895,11 +864,10 @@ func TestComputedStyle(t *testing.T) {
} }
} }
} }
if err := Run(ctx, Click("#input1", ByID)); err != nil { if err := Run(ctx,
t.Fatalf("got error: %v", err) Click("#input1", ByID),
} ComputedStyle(test.sel, &styles, test.by),
); err != nil {
if err := Run(ctx, ComputedStyle(test.sel, &styles, test.by)); err != nil {
t.Fatalf("got error: %v", err) t.Fatalf("got error: %v", err)
} }
@ -936,8 +904,7 @@ func TestMatchedStyle(t *testing.T) {
defer cancel() defer cancel()
var styles *css.GetMatchedStylesForNodeReturns var styles *css.GetMatchedStylesForNodeReturns
err := Run(ctx, MatchedStyle(test.sel, &styles, test.by)) if err := Run(ctx, MatchedStyle(test.sel, &styles, test.by)); err != nil {
if err != nil {
t.Fatalf("got error: %v", err) t.Fatalf("got error: %v", err)
} }

View File

@ -13,19 +13,17 @@ func TestWaitReady(t *testing.T) {
defer cancel() defer cancel()
var nodeIDs []cdp.NodeID var nodeIDs []cdp.NodeID
err := Run(ctx, NodeIDs("#input2", &nodeIDs, ByID)) if err := Run(ctx, NodeIDs("#input2", &nodeIDs, ByID)); err != nil {
if err != nil {
t.Fatalf("got error: %v", err) t.Fatalf("got error: %v", err)
} }
if len(nodeIDs) != 1 { if len(nodeIDs) != 1 {
t.Errorf("expected to have exactly 1 node id: got %d", len(nodeIDs)) t.Errorf("expected to have exactly 1 node id: got %d", len(nodeIDs))
} }
if err := Run(ctx, WaitReady("#input2", ByID)); err != nil {
t.Fatalf("got error: %v", err)
}
var value string var value string
if err := Run(ctx, Value(nodeIDs, &value, ByNodeID)); err != nil { if err := Run(ctx,
WaitReady("#input2", ByID),
Value(nodeIDs, &value, ByNodeID),
); err != nil {
t.Fatalf("got error: %v", err) t.Fatalf("got error: %v", err)
} }
} }
@ -37,19 +35,17 @@ func TestWaitVisible(t *testing.T) {
defer cancel() defer cancel()
var nodeIDs []cdp.NodeID var nodeIDs []cdp.NodeID
err := Run(ctx, NodeIDs("#input2", &nodeIDs, ByID)) if err := Run(ctx, NodeIDs("#input2", &nodeIDs, ByID)); err != nil {
if err != nil {
t.Fatalf("got error: %v", err) t.Fatalf("got error: %v", err)
} }
if len(nodeIDs) != 1 { if len(nodeIDs) != 1 {
t.Errorf("expected to have exactly 1 node id: got %d", len(nodeIDs)) t.Errorf("expected to have exactly 1 node id: got %d", len(nodeIDs))
} }
if err := Run(ctx, WaitVisible("#input2", ByID)); err != nil {
t.Fatalf("got error: %v", err)
}
var value string var value string
if err := Run(ctx, Value(nodeIDs, &value, ByNodeID)); err != nil { if err := Run(ctx,
WaitVisible("#input2", ByID),
Value(nodeIDs, &value, ByNodeID),
); err != nil {
t.Fatalf("got error: %v", err) t.Fatalf("got error: %v", err)
} }
} }
@ -61,22 +57,18 @@ func TestWaitNotVisible(t *testing.T) {
defer cancel() defer cancel()
var nodeIDs []cdp.NodeID var nodeIDs []cdp.NodeID
err := Run(ctx, NodeIDs("#input2", &nodeIDs, ByID)) if err := Run(ctx, NodeIDs("#input2", &nodeIDs, ByID)); err != nil {
if err != nil {
t.Fatalf("got error: %v", err) t.Fatalf("got error: %v", err)
} }
if len(nodeIDs) != 1 { if len(nodeIDs) != 1 {
t.Errorf("expected to have exactly 1 node id: got %d", len(nodeIDs)) t.Errorf("expected to have exactly 1 node id: got %d", len(nodeIDs))
} }
if err := Run(ctx, Click("#button2", ByID)); err != nil {
t.Fatalf("got error: %v", err)
}
if err := Run(ctx, WaitNotVisible("#input2", ByID)); err != nil {
t.Fatalf("got error: %v", err)
}
var value string var value string
if err := Run(ctx, Value(nodeIDs, &value, ByNodeID)); err != nil { if err := Run(ctx,
Click("#button2", ByID),
WaitNotVisible("#input2", ByID),
Value(nodeIDs, &value, ByNodeID),
); err != nil {
t.Fatalf("got error: %v", err) t.Fatalf("got error: %v", err)
} }
} }
@ -89,32 +81,27 @@ func TestWaitEnabled(t *testing.T) {
var attr string var attr string
var ok bool var ok bool
err := Run(ctx, AttributeValue("#select1", "disabled", &attr, &ok, ByID)) if err := Run(ctx, AttributeValue("#select1", "disabled", &attr, &ok, ByID)); err != nil {
if err != nil {
t.Fatalf("got error: %v", err) t.Fatalf("got error: %v", err)
} }
if !ok { if !ok {
t.Fatal("expected element to be disabled") t.Fatal("expected element to be disabled")
} }
if err := Run(ctx, Click("#button3", ByID)); err != nil { if err := Run(ctx,
Click("#button3", ByID),
WaitEnabled("#select1", ByID),
AttributeValue("#select1", "disabled", &attr, &ok, ByID),
); err != nil {
t.Fatalf("got error: %v", err) t.Fatalf("got error: %v", err)
} }
if err := Run(ctx, WaitEnabled("#select1", ByID)); err != nil {
t.Fatalf("got error: %v", err)
}
if err := Run(ctx, AttributeValue("#select1", "disabled", &attr, &ok, ByID)); err != nil {
t.Fatalf("got error: %v", err)
}
if ok { if ok {
t.Fatal("expected element to be enabled") t.Fatal("expected element to be enabled")
} }
if err := Run(ctx, SetAttributeValue(`//*[@id="select1"]/option[1]`, "selected", "true")); err != nil {
t.Fatalf("got error: %v", err)
}
var value string var value string
if err := Run(ctx, Value("#select1", &value, ByID)); err != nil { if err := Run(ctx,
SetAttributeValue(`//*[@id="select1"]/option[1]`, "selected", "true"),
Value("#select1", &value, ByID),
); err != nil {
t.Fatalf("got error: %v", err) t.Fatalf("got error: %v", err)
} }
@ -129,11 +116,10 @@ func TestWaitSelected(t *testing.T) {
ctx, cancel := testAllocate(t, "js.html") ctx, cancel := testAllocate(t, "js.html")
defer cancel() defer cancel()
err := Run(ctx, Click("#button3", ByID)) if err := Run(ctx,
if err != nil { Click("#button3", ByID),
t.Fatalf("got error: %v", err) WaitEnabled("#select1", ByID),
} ); err != nil {
if err := Run(ctx, WaitEnabled("#select1", ByID)); err != nil {
t.Fatalf("got error: %v", err) t.Fatalf("got error: %v", err)
} }
@ -142,17 +128,14 @@ func TestWaitSelected(t *testing.T) {
if err := Run(ctx, AttributeValue(`//*[@id="select1"]/option[1]`, "selected", &attr, &ok)); err != nil { if err := Run(ctx, AttributeValue(`//*[@id="select1"]/option[1]`, "selected", &attr, &ok)); err != nil {
t.Fatalf("got error: %v", err) t.Fatalf("got error: %v", err)
} }
if ok { if ok {
t.Fatal("expected element to be not selected") t.Fatal("expected element to be not selected")
} }
if err := Run(ctx, SetAttributeValue(`//*[@id="select1"]/option[1]`, "selected", "true")); err != nil { if err := Run(ctx,
t.Fatalf("got error: %v", err) SetAttributeValue(`//*[@id="select1"]/option[1]`, "selected", "true"),
} WaitSelected(`//*[@id="select1"]/option[1]`),
if err := Run(ctx, WaitSelected(`//*[@id="select1"]/option[1]`)); err != nil { AttributeValue(`//*[@id="select1"]/option[1]`, "selected", &attr, nil),
t.Fatalf("got error: %v", err) ); err != nil {
}
if err := Run(ctx, AttributeValue(`//*[@id="select1"]/option[1]`, "selected", &attr, nil)); err != nil {
t.Fatalf("got error: %v", err) t.Fatalf("got error: %v", err)
} }
@ -167,14 +150,11 @@ func TestWaitNotPresent(t *testing.T) {
ctx, cancel := testAllocate(t, "js.html") ctx, cancel := testAllocate(t, "js.html")
defer cancel() defer cancel()
err := Run(ctx, WaitVisible("#input3", ByID)) if err := Run(ctx,
if err != nil { WaitVisible("#input3", ByID),
t.Fatalf("got error: %v", err) Click("#button4", ByID),
} WaitNotPresent("#input3", ByID),
if err := Run(ctx, Click("#button4", ByID)); err != nil { ); err != nil {
t.Fatalf("got error: %v", err)
}
if err := Run(ctx, WaitNotPresent("#input3", ByID)); err != nil {
t.Fatalf("got error: %v", err) t.Fatalf("got error: %v", err)
} }
} }
@ -186,8 +166,7 @@ func TestAtLeast(t *testing.T) {
defer cancel() defer cancel()
var nodes []*cdp.Node var nodes []*cdp.Node
err := Run(ctx, Nodes("//input", &nodes, AtLeast(3))) if err := Run(ctx, Nodes("//input", &nodes, AtLeast(3))); err != nil {
if err != nil {
t.Fatalf("got error: %v", err) t.Fatalf("got error: %v", err)
} }
if len(nodes) < 3 { if len(nodes) < 3 {