Best Rod code snippet using rod.MustDescribe
element_test.go
Source:element_test.go
...185}186func (t T) Contains() {187 p := t.page.MustNavigate(t.srcFile("fixtures/click.html"))188 a := p.MustElement("button")189 b := p.MustElementFromNode(a.MustDescribe())190 t.True(a.MustContainsElement(b))191 pt := a.MustShape().OnePointInside()192 el := p.MustElementFromPoint(int(pt.X), int(pt.Y))193 t.True(a.MustContainsElement(el))194 t.mc.stubErr(1, proto.RuntimeCallFunctionOn{})195 t.Err(a.ContainsElement(el))196}197func (t T) ShadowDOM() {198 p := t.page.MustNavigate(t.srcFile("fixtures/shadow-dom.html")).MustWaitLoad()199 el := p.MustElement("#container")200 t.Eq("inside", el.MustShadowRoot().MustElement("p").MustText())201 t.Panic(func() {202 t.mc.stubErr(1, proto.DOMDescribeNode{})203 el.MustShadowRoot()204 })205 t.Panic(func() {206 t.mc.stubErr(1, proto.DOMResolveNode{})207 el.MustShadowRoot()208 })209}210func (t T) Press() {211 p := t.page.MustNavigate(t.srcFile("fixtures/input.html"))212 el := p.MustElement("[type=text]")213 el.MustPress('1', '2', input.Backspace, ' ')214 el.MustPress([]rune("A b")...)215 t.Eq("1 A b", el.MustText())216 t.Panic(func() {217 t.mc.stubErr(1, proto.DOMScrollIntoViewIfNeeded{})218 el.MustPress(' ')219 })220 t.Panic(func() {221 t.mc.stubErr(1, proto.DOMScrollIntoViewIfNeeded{})222 el.MustSelectAllText()223 })224}225func (t T) KeyDown() {226 p := t.page.MustNavigate(t.srcFile("fixtures/keys.html"))227 p.MustElement("body")228 p.Keyboard.MustDown('j')229 t.True(p.MustHas("body[event=key-down-j]"))230}231func (t T) KeyUp() {232 p := t.page.MustNavigate(t.srcFile("fixtures/keys.html"))233 p.MustElement("body")234 p.Keyboard.MustUp('x')235 t.True(p.MustHas("body[event=key-up-x]"))236}237func (t T) Input() {238 text := "é²ã®ä¸ã¯\nãã¤ãæ´ã"239 p := t.page.MustNavigate(t.srcFile("fixtures/input.html"))240 {241 el := p.MustElement("[contenteditable=true]").MustInput(text)242 t.Eq(text, el.MustText())243 }244 el := p.MustElement("textarea")245 el.MustInput(text)246 t.Eq(text, el.MustText())247 t.True(p.MustHas("[event=textarea-change]"))248 t.Panic(func() {249 t.mc.stubErr(1, proto.RuntimeCallFunctionOn{})250 el.MustText()251 })252 t.Panic(func() {253 t.mc.stubErr(4, proto.RuntimeCallFunctionOn{})254 el.MustInput("")255 })256 t.Panic(func() {257 t.mc.stubErr(5, proto.RuntimeCallFunctionOn{})258 el.MustInput("")259 })260 t.Panic(func() {261 t.mc.stubErr(6, proto.RuntimeCallFunctionOn{})262 el.MustInput("")263 })264 t.Panic(func() {265 t.mc.stubErr(7, proto.RuntimeCallFunctionOn{})266 el.MustInput("")267 })268 t.Panic(func() {269 t.mc.stubErr(1, proto.InputInsertText{})270 el.MustInput("")271 })272}273func (t T) InputTime() {274 now := time.Now()275 p := t.page.MustNavigate(t.srcFile("fixtures/input.html"))276 var el *rod.Element277 {278 el = p.MustElement("[type=date]")279 el.MustInputTime(now)280 t.Eq(el.MustText(), now.Format("2006-01-02"))281 t.True(p.MustHas("[event=input-date-change]"))282 }283 {284 el = p.MustElement("[type=datetime-local]")285 el.MustInputTime(now)286 t.Eq(el.MustText(), now.Format("2006-01-02T15:04"))287 t.True(p.MustHas("[event=input-datetime-local-change]"))288 }289 t.Panic(func() {290 t.mc.stubErr(1, proto.RuntimeCallFunctionOn{})291 el.MustInputTime(now)292 })293 t.Panic(func() {294 t.mc.stubErr(5, proto.RuntimeCallFunctionOn{})295 el.MustInputTime(now)296 })297 t.Panic(func() {298 t.mc.stubErr(6, proto.RuntimeCallFunctionOn{})299 el.MustInputTime(now)300 })301 t.Panic(func() {302 t.mc.stubErr(7, proto.RuntimeCallFunctionOn{})303 el.MustInputTime(now)304 })305}306func (t T) Checkbox() {307 p := t.page.MustNavigate(t.srcFile("fixtures/input.html"))308 el := p.MustElement("[type=checkbox]")309 t.True(el.MustClick().MustProperty("checked").Bool())310}311func (t T) SelectText() {312 p := t.page.MustNavigate(t.srcFile("fixtures/input.html"))313 el := p.MustElement("textarea")314 el.MustInput("test")315 el.MustSelectAllText()316 el.MustInput("test")317 t.Eq("test", el.MustText())318 el.MustSelectText(`es`)319 el.MustInput("__")320 t.Eq("t__t", el.MustText())321 t.Panic(func() {322 t.mc.stubErr(1, proto.DOMScrollIntoViewIfNeeded{})323 el.MustSelectText("")324 })325 t.Panic(func() {326 t.mc.stubErr(1, proto.DOMScrollIntoViewIfNeeded{})327 el.MustSelectAllText()328 })329 t.Panic(func() {330 t.mc.stubErr(1, proto.DOMScrollIntoViewIfNeeded{})331 el.MustInput("")332 })333 t.Panic(func() {334 t.mc.stubErr(1, proto.InputInsertText{})335 el.MustInput("")336 })337}338func (t T) Blur() {339 p := t.page.MustNavigate(t.srcFile("fixtures/input.html"))340 el := p.MustElement("#blur").MustInput("test").MustBlur()341 t.Eq("ok", *el.MustAttribute("a"))342}343func (t T) SelectQuery() {344 p := t.page.MustNavigate(t.srcFile("fixtures/input.html"))345 el := p.MustElement("select")346 err := el.Select([]string{`[value="c"]`}, true, rod.SelectorTypeCSSSector)347 t.E(err)348 t.Eq(2, el.MustEval("this.selectedIndex").Int())349}350func (t T) SelectOptions() {351 p := t.page.MustNavigate(t.srcFile("fixtures/input.html"))352 el := p.MustElement("select")353 el.MustSelect("B", "C")354 t.Eq("B,C", el.MustText())355 t.Eq(1, el.MustProperty("selectedIndex").Int())356 // unselect with regex357 err := el.Select([]string{`^B$`}, false, rod.SelectorTypeRegex)358 t.E(err)359 t.Eq("C", el.MustText())360 // unselect with css selector361 err = el.Select([]string{`[value="c"]`}, false, rod.SelectorTypeCSSSector)362 t.E(err)363 t.Eq("", el.MustText())364 // option not found error365 t.Is(el.Select([]string{"not-exists"}, true, rod.SelectorTypeCSSSector), &rod.ErrElementNotFound{})366 {367 t.mc.stubErr(5, proto.RuntimeCallFunctionOn{})368 t.Err(el.Select([]string{"B"}, true, rod.SelectorTypeText))369 }370}371func (t T) Matches() {372 p := t.page.MustNavigate(t.srcFile("fixtures/input.html"))373 el := p.MustElement("textarea")374 t.True(el.MustMatches(`[cols="30"]`))375 t.Panic(func() {376 t.mc.stubErr(1, proto.RuntimeCallFunctionOn{})377 el.MustMatches("")378 })379}380func (t T) Attribute() {381 p := t.page.MustNavigate(t.srcFile("fixtures/input.html"))382 el := p.MustElement("textarea")383 cols := el.MustAttribute("cols")384 rows := el.MustAttribute("rows")385 t.Eq("30", *cols)386 t.Eq("10", *rows)387 p = t.page.MustNavigate(t.srcFile("fixtures/click.html"))388 el = p.MustElement("button").MustClick()389 t.Eq("ok", *el.MustAttribute("a"))390 t.Nil(el.MustAttribute("b"))391 t.Panic(func() {392 t.mc.stubErr(1, proto.RuntimeCallFunctionOn{})393 el.MustAttribute("")394 })395}396func (t T) Property() {397 p := t.page.MustNavigate(t.srcFile("fixtures/input.html"))398 el := p.MustElement("textarea")399 cols := el.MustProperty("cols")400 rows := el.MustProperty("rows")401 t.Eq(float64(30), cols.Num())402 t.Eq(float64(10), rows.Num())403 p = t.page.MustNavigate(t.srcFile("fixtures/open-page.html"))404 el = p.MustElement("a")405 t.Eq("link", el.MustProperty("id").Str())406 t.Eq("_blank", el.MustProperty("target").Str())407 t.True(el.MustProperty("test").Nil())408 t.Panic(func() {409 t.mc.stubErr(1, proto.RuntimeCallFunctionOn{})410 el.MustProperty("")411 })412}413func (t T) SetFiles() {414 p := t.page.MustNavigate(t.srcFile("fixtures/input.html"))415 el := p.MustElement(`[type=file]`)416 el.MustSetFiles(417 slash("fixtures/click.html"),418 slash("fixtures/alert.html"),419 )420 list := el.MustEval("Array.from(this.files).map(f => f.name)").Arr()421 t.Len(list, 2)422 t.Eq("alert.html", list[1].String())423}424func (t T) Enter() {425 p := t.page.MustNavigate(t.srcFile("fixtures/input.html"))426 el := p.MustElement("[type=submit]")427 el.MustPress(input.Enter)428 t.True(p.MustHas("[event=submit]"))429}430func (t T) WaitInvisible() {431 p := t.page.MustNavigate(t.srcFile("fixtures/click.html"))432 h4 := p.MustElement("h4")433 btn := p.MustElement("button")434 t.True(h4.MustVisible())435 h4.MustWaitVisible()436 go func() {437 utils.Sleep(0.03)438 h4.MustEval(`this.remove()`)439 utils.Sleep(0.03)440 btn.MustEval(`this.style.visibility = 'hidden'`)441 }()442 h4.MustWaitInvisible()443 btn.MustWaitInvisible()444 t.False(p.MustHas("h4"))445}446func (t T) WaitEnabled() {447 p := t.page.MustNavigate(t.srcFile("fixtures/click.html"))448 p.MustElement("button").MustWaitEnabled()449}450func (t T) WaitWritable() {451 p := t.page.MustNavigate(t.srcFile("fixtures/input.html"))452 p.MustElement("input").MustWaitWritable()453}454func (t T) WaitStable() {455 p := t.page.MustNavigate(t.srcFile("fixtures/wait-stable.html"))456 el := p.MustElement("button")457 el.MustEval(`this.classList.add("play")`)458 start := time.Now()459 el.MustWaitStable()460 t.Gt(time.Since(start), time.Second)461 ctx := t.Context()462 t.mc.stub(1, proto.DOMGetContentQuads{}, func(send StubSend) (gson.JSON, error) {463 go func() {464 utils.Sleep(0.1)465 ctx.Cancel()466 }()467 return send()468 })469 t.Err(el.Context(ctx).WaitStable(time.Minute))470 t.Panic(func() {471 t.mc.stubErr(1, proto.DOMGetContentQuads{})472 el.MustWaitStable()473 })474 t.Panic(func() {475 t.mc.stubErr(2, proto.DOMGetContentQuads{})476 el.MustWaitStable()477 })478}479func (t T) WaitStableRAP() {480 p := t.page.MustNavigate(t.srcFile("fixtures/wait-stable.html"))481 el := p.MustElement("button")482 el.MustEval(`this.classList.add("play")`)483 start := time.Now()484 t.E(el.WaitStableRAF())485 t.Gt(time.Since(start), time.Second)486 t.mc.stubErr(2, proto.RuntimeCallFunctionOn{})487 t.Err(el.WaitStableRAF())488 t.mc.stubErr(1, proto.DOMGetContentQuads{})489 t.Err(el.WaitStableRAF())490}491func (t T) CanvasToImage() {492 p := t.page.MustNavigate(t.srcFile("fixtures/canvas.html"))493 src, err := png.Decode(bytes.NewBuffer(p.MustElement("#canvas").MustCanvasToImage()))494 t.E(err)495 t.Eq(src.At(50, 50), color.NRGBA{0xFF, 0x00, 0x00, 0xFF})496}497func (t T) ElementWaitLoad() {498 p := t.page.MustNavigate(t.srcFile("fixtures/resource.html"))499 p.MustElement("img").MustWaitLoad()500}501func (t T) Resource() {502 p := t.page.MustNavigate(t.srcFile("fixtures/resource.html"))503 el := p.MustElement("img")504 t.Eq(len(el.MustResource()), 22661)505 t.mc.stub(1, proto.PageGetResourceContent{}, func(send StubSend) (gson.JSON, error) {506 return gson.New(proto.PageGetResourceContentResult{507 Content: "ok",508 Base64Encoded: false,509 }), nil510 })511 t.Eq([]byte("ok"), el.MustResource())512 t.Panic(func() {513 t.mc.stubErr(1, proto.RuntimeCallFunctionOn{})514 el.MustResource()515 })516 t.Panic(func() {517 t.mc.stubErr(1, proto.PageGetResourceContent{})518 el.MustResource()519 })520}521func (t T) BackgroundImage() {522 p := t.page.MustNavigate(t.srcFile("fixtures/resource.html"))523 el := p.MustElement("div")524 t.Eq(len(el.MustBackgroundImage()), 22661)525 {526 t.mc.stubErr(1, proto.RuntimeCallFunctionOn{})527 t.Err(el.BackgroundImage())528 }529}530func (t T) ElementScreenshot() {531 f := filepath.Join("tmp", "screenshots", t.Srand(16)+".png")532 p := t.page.MustNavigate(t.srcFile("fixtures/click.html"))533 el := p.MustElement("h4")534 data := el.MustScreenshot(f)535 img, err := png.Decode(bytes.NewBuffer(data))536 t.E(err)537 t.Eq(200, img.Bounds().Dx())538 t.Eq(30, img.Bounds().Dy())539 t.Nil(os.Stat(f))540 t.Panic(func() {541 t.mc.stubErr(1, proto.DOMScrollIntoViewIfNeeded{})542 el.MustScreenshot()543 })544 t.Panic(func() {545 t.mc.stubErr(1, proto.PageCaptureScreenshot{})546 el.MustScreenshot()547 })548 t.Panic(func() {549 t.mc.stubErr(3, proto.DOMGetContentQuads{})550 el.MustScreenshot()551 })552}553func (t T) UseReleasedElement() {554 p := t.page.MustNavigate(t.srcFile("fixtures/click.html"))555 btn := p.MustElement("button")556 btn.MustRelease()557 t.Err(btn.Click("left"))558 btn = p.MustElement("button")559 t.E(proto.RuntimeReleaseObject{ObjectID: btn.Object.ObjectID}.Call(p))560 t.Is(btn.Click("left"), cdp.ErrObjNotFound)561}562func (t T) ElementRemove() {563 p := t.page.MustNavigate(t.srcFile("fixtures/click.html"))564 btn := p.MustElement("button")565 t.mc.stubErr(1, proto.RuntimeCallFunctionOn{})566 t.Err(btn.Remove())567}568func (t T) ElementMultipleTimes() {569 // To see whether chrome will reuse the remote object ID or not.570 // Seems like it will not.571 page := t.page.MustNavigate(t.srcFile("fixtures/click.html"))572 btn01 := page.MustElement("button")573 btn02 := page.MustElement("button")574 t.Eq(btn01.MustText(), btn02.MustText())575 t.Neq(btn01.Object, btn02.Object)576}577func (t T) FnErr() {578 p := t.page.MustNavigate(t.srcFile("fixtures/click.html"))579 el := p.MustElement("button")580 _, err := el.Eval("foo()")581 t.Err(err)582 t.Has(err.Error(), "ReferenceError: foo is not defined")583 var e *rod.ErrEval584 t.True(errors.As(err, &e))585 t.Eq(proto.RuntimeRemoteObjectSubtypeError, e.Exception.Subtype)586 _, err = el.ElementByJS(rod.Eval("foo()"))587 t.Err(err)588 t.Has(err.Error(), "ReferenceError: foo is not defined")589 t.True(errors.Is(err, &rod.ErrEval{}))590}591func (t T) ElementEWithDepth() {592 checkStr := `green tea`593 p := t.page.MustNavigate(t.srcFile("fixtures/describe.html"))594 ulDOMNode, err := p.MustElement(`ul`).Describe(-1, true)595 t.Nil(errors.Unwrap(err))596 data, err := json.Marshal(ulDOMNode)597 t.Nil(errors.Unwrap(err))598 // The depth is -1, should contain checkStr599 t.Has(string(data), checkStr)600}601func (t T) ElementOthers() {602 p := t.page.MustNavigate(t.srcFile("fixtures/input.html"))603 el := p.MustElement("form")604 el.MustFocus()605 el.MustScrollIntoView()606 t.Eq("submit", el.MustElement("[type=submit]").MustText())607 t.Eq("<input type=\"submit\" value=\"submit\">", el.MustElement("[type=submit]").MustHTML())608 el.MustWait(`true`)609 t.Eq("form", el.MustElementByJS(`this`).MustDescribe().LocalName)610 t.Len(el.MustElementsByJS(`[]`), 0)611}612func (t T) ElementEqual() {613 p := t.page.MustNavigate(t.srcFile("fixtures/describe.html"))614 el1 := p.MustElement("body > ul")615 el2 := p.MustElement("html > body > ul")616 t.True(el1.MustEqual(el2))617 el3 := p.MustElement("ul ul")618 t.False(el1.MustEqual(el3))619}620func (t T) ElementFromPointErr() {621 t.mc.stubErr(1, proto.DOMGetNodeForLocation{})622 t.Err(t.page.ElementFromPoint(10, 10))623}624func (t T) ElementFromNodeErr() {625 p := t.page.MustNavigate(t.srcFile("fixtures/click.html"))626 el := p.MustElementX("//button/text()")627 t.mc.stubErr(3, proto.RuntimeCallFunctionOn{})628 t.Err(p.ElementFromNode(el.MustDescribe()))629}630func (t T) ElementErrors() {631 p := t.page.MustNavigate(t.srcFile("fixtures/input.html"))632 el := p.MustElement("form")633 ctx := t.Timeout(0)634 _, err := el.Context(ctx).Describe(-1, true)635 t.Err(err)636 _, err = el.Context(ctx).Frame()637 t.Err(err)638 err = el.Context(ctx).Focus()639 t.Err(err)640 err = el.Context(ctx).Press('a')641 t.Err(err)642 err = el.Context(ctx).Input("a")...
query_test.go
Source:query_test.go
...13func (t T) PageElements() {14 t.page.MustNavigate(t.srcFile("fixtures/input.html"))15 t.page.MustElement("input")16 list := t.page.MustElements("input")17 t.Eq("input", list.First().MustDescribe().LocalName)18 t.Eq("submit", list.Last().MustText())19}20func (t T) Pages() {21 t.page.MustNavigate(t.srcFile("fixtures/click.html")).MustWaitLoad()22 pages := t.browser.MustPages()23 t.True(pages.MustFind("button").MustHas("button"))24 t.Panic(func() { rod.Pages{}.MustFind("____") })25 t.True(pages.MustFindByURL("click.html").MustHas("button"))26 t.Panic(func() { rod.Pages{}.MustFindByURL("____") })27 _, err := pages.Find("____")28 t.Err(err)29 t.Eq(err.Error(), "cannot find page")30 t.Panic(func() {31 pages.MustFindByURL("____")32 })33 t.Panic(func() {34 t.mc.stubErr(1, proto.RuntimeCallFunctionOn{})35 pages.MustFind("button")36 })37 t.Panic(func() {38 t.mc.stubErr(1, proto.RuntimeCallFunctionOn{})39 pages.MustFindByURL("____")40 })41}42func (t T) PageHas() {43 t.page.MustNavigate(t.srcFile("fixtures/selector.html"))44 t.page.MustElement("body")45 t.True(t.page.MustHas("span"))46 t.False(t.page.MustHas("a"))47 t.True(t.page.MustHasX("//span"))48 t.False(t.page.MustHasX("//a"))49 t.True(t.page.MustHasR("button", "03"))50 t.False(t.page.MustHasR("button", "11"))51 t.mc.stubErr(1, proto.RuntimeCallFunctionOn{})52 t.Err(t.page.HasX("//a"))53 t.mc.stubErr(1, proto.RuntimeCallFunctionOn{})54 t.Err(t.page.HasR("button", "03"))55}56func (t T) ElementHas() {57 t.page.MustNavigate(t.srcFile("fixtures/selector.html"))58 b := t.page.MustElement("body")59 t.True(b.MustHas("span"))60 t.False(b.MustHas("a"))61 t.True(b.MustHasX("//span"))62 t.False(b.MustHasX("//a"))63 t.True(b.MustHasR("button", "03"))64 t.False(b.MustHasR("button", "11"))65}66func (t T) Search() {67 p := t.page.MustNavigate(t.srcFile("fixtures/click.html"))68 el := p.MustSearch("click me")69 t.Eq("click me", el.MustText())70 t.True(el.MustClick().MustMatches("[a=ok]"))71 _, err := p.Sleeper(rod.NotFoundSleeper).Search("not-exists")72 t.True(errors.Is(err, &rod.ErrElementNotFound{}))73 t.Eq(err.Error(), "cannot find element")74 // when search result is not ready75 {76 t.mc.stub(1, proto.DOMGetSearchResults{}, func(send StubSend) (gson.JSON, error) {77 return gson.New(nil), cdp.ErrCtxNotFound78 })79 p.MustSearch("click me")80 }81 // when node id is zero82 {83 t.mc.stub(1, proto.DOMGetSearchResults{}, func(send StubSend) (gson.JSON, error) {84 return gson.New(proto.DOMGetSearchResultsResult{85 NodeIds: []proto.DOMNodeID{0},86 }), nil87 })88 p.MustSearch("click me")89 }90 t.Panic(func() {91 t.mc.stubErr(1, proto.DOMPerformSearch{})92 p.MustSearch("click me")93 })94 t.Panic(func() {95 t.mc.stubErr(1, proto.DOMGetSearchResults{})96 p.MustSearch("click me")97 })98 t.Panic(func() {99 t.mc.stubErr(1, proto.RuntimeCallFunctionOn{})100 p.MustSearch("click me")101 })102}103func (t T) SearchElements() {104 p := t.page.MustNavigate(t.srcFile("fixtures/selector.html"))105 {106 res, err := p.Search("button")107 t.E(err)108 c, err := res.All()109 t.E(err)110 t.Len(c, 4)111 t.mc.stubErr(1, proto.DOMGetSearchResults{})112 t.Err(res.All())113 t.mc.stubErr(1, proto.DOMResolveNode{})114 t.Err(res.All())115 }116 { // disable retry117 sleeper := func() utils.Sleeper { return utils.CountSleeper(1) }118 _, err := p.Sleeper(sleeper).Search("not-exists")119 t.Err(err)120 }121}122func (t T) SearchIframes() {123 p := t.page.MustNavigate(t.srcFile("fixtures/click-iframes.html"))124 el := p.MustSearch("button[onclick]")125 t.Eq("click me", el.MustText())126 t.True(el.MustClick().MustMatches("[a=ok]"))127}128func (t T) SearchIframesAfterReload() {129 p := t.page.MustNavigate(t.srcFile("fixtures/click-iframes.html"))130 frame := p.MustElement("iframe").MustFrame().MustElement("iframe").MustFrame()131 frame.MustReload()132 el := p.MustSearch("button[onclick]")133 t.Eq("click me", el.MustText())134 t.True(el.MustClick().MustMatches("[a=ok]"))135}136func (t T) PageRace() {137 p := t.page.MustNavigate(t.srcFile("fixtures/selector.html"))138 p.Race().Element("button").MustHandle(func(e *rod.Element) { t.Eq("01", e.MustText()) }).MustDo()139 t.Eq("01", p.Race().Element("button").MustDo().MustText())140 p.Race().ElementX("//button").MustHandle(func(e *rod.Element) { t.Eq("01", e.MustText()) }).MustDo()141 t.Eq("01", p.Race().ElementX("//button").MustDo().MustText())142 p.Race().ElementR("button", "02").MustHandle(func(e *rod.Element) { t.Eq("02", e.MustText()) }).MustDo()143 t.Eq("02", p.Race().ElementR("button", "02").MustDo().MustText())144 p.Race().MustElementByJS("document.querySelector('button')", nil).145 MustHandle(func(e *rod.Element) { t.Eq("01", e.MustText()) }).MustDo()146 t.Eq("01", p.Race().MustElementByJS("document.querySelector('button')", nil).MustDo().MustText())147 el, err := p.Sleeper(func() utils.Sleeper { return utils.CountSleeper(2) }).Race().148 Element("not-exists").MustHandle(func(e *rod.Element) {}).149 ElementX("//not-exists").150 ElementR("not-exists", "test").MustHandle(func(e *rod.Element) {}).151 Do()152 t.Err(err)153 t.Nil(el)154 el, err = p.Race().MustElementByJS(`notExists()`, nil).Do()155 t.Err(err)156 t.Nil(el)157}158func (t T) PageRaceRetryInHandle() {159 p := t.page.MustNavigate(t.srcFile("fixtures/selector.html"))160 p.Race().Element("div").MustHandle(func(e *rod.Element) {161 go func() {162 utils.Sleep(0.5)163 e.MustElement("button").MustEval(`this.innerText = '04'`)164 }()165 e.MustElement("button").MustWait("this.innerText === '04'")166 }).MustDo()167}168func (t T) PageElementX() {169 t.page.MustNavigate(t.srcFile("fixtures/click.html"))170 t.page.MustElement("body")171 name := t.page.MustElementX("//*[contains(text(), 'click')]").MustDescribe().LocalName172 t.Eq("button", name)173}174func (t T) PageElementsX() {175 t.page.MustNavigate(t.srcFile("fixtures/selector.html"))176 t.page.MustElement("body")177 list := t.page.MustElementsX("//button")178 t.Len(list, 4)179}180func (t T) ElementR() {181 p := t.page.MustNavigate(t.srcFile("fixtures/selector.html"))182 el := p.MustElementR("button", `\d1`)183 t.Eq("01", el.MustText())184 el = p.MustElement("div").MustElementR("button", `03`)185 t.Eq("03", el.MustText())...
MustDescribe
Using AI Code Generation
1import (2func main() {3 browser := rod.New().ControlURL(launcher.New().MustLaunch()).MustConnect()4 page.MustElement("input").MustInput("rod")5 page.MustElement("input").MustPress("enter")6 page.MustElement(".g").MustElement("h3").MustClick()7 page.MustElement("input").MustInput("rod")8 page.MustElement("input").MustPress("enter")9 fmt.Println(page.MustDescribe())10}11import (12func main() {13 browser := rod.New().ControlURL(launcher.New().MustLaunch()).MustConnect()14 page.MustElement("input").MustInput("rod")15 page.MustElement("input").MustPress("enter")16 page.MustElement(".g").MustElement("h3").MustClick()17 page.MustElement("input").MustInput("rod")18 page.MustElement("input").MustPress("enter")19 fmt.Println(page.MustElements("h3").MustTexts())20}
MustDescribe
Using AI Code Generation
1import (2func main() {3 browser := rod.New().MustConnect()4 fmt.Println(page.MustDescribe())5}6import (7func main() {8 browser := rod.New().MustConnect()9 fmt.Println(page.MustScreenshot("google.png"))10}11import (12func main() {13 browser := rod.New().MustConnect()14 fmt.Println(page.MustElement("input[name='q']").MustInput("rod"))15}16import (17func main() {18 browser := rod.New().MustConnect()19 fmt.Println(page.MustElement("input[name='q']").MustInput("rod"))20}21import (22func main() {23 browser := rod.New().MustConnect()24 fmt.Println(page.MustElement("input[name='q']").MustInput("rod"))25}26import (27func main() {28 browser := rod.New().MustConnect()29 fmt.Println(page.MustElement("input[name='q']").MustInput("rod"))30}31import (32func main() {33 browser := rod.New().MustConnect()34 fmt.Println(page.Must
MustDescribe
Using AI Code Generation
1import (2func main() {3 l := launcher.New().MustLaunch()4 browser := rod.New().ControlURL(l).MustConnect()5 fmt.Println(page.MustDescribe())6}
MustDescribe
Using AI Code Generation
1import (2func main() {3 utils.E(utils.Touch("2.html"))4 browser := rod.New().MustConnect()5 page := browser.MustPage("2.html")6 element := page.MustElement("h1")7 fmt.Println(element.MustDescribe())8}9import (10func main() {11 utils.E(utils.Touch("3.html"))12 browser := rod.New().MustConnect()13 page := browser.MustPage("3.html")14 element := page.MustElement("h1")15 fmt.Println(element.MustText())16}17import (18func main() {19 utils.E(utils.Touch("4.html"))20 browser := rod.New().MustConnect()21 page := browser.MustPage("4.html")22 fmt.Println(element.MustText())23}24import (25func main() {26 utils.E(utils.Touch("5.html"))27 browser := rod.New().MustConnect()28 page := browser.MustPage("5.html")29 element := page.MustElementR("h1")30 fmt.Println(element.MustText())31}32import (33func main() {34 utils.E(utils.Touch("6.html"))35 browser := rod.New().MustConnect()36 page := browser.MustPage("6.html")37 elements := page.MustElements("h1")38 fmt.Println(elements[0].MustText())39 fmt.Println(elements[1].MustText())40}41import (
MustDescribe
Using AI Code Generation
1import "fmt"2import "github.com/go-rod/rod"3func main() {4fmt.Println(page.MustDescribe())5}6rod.Page{7 Emitter: rod.Emitter{8 EventHandlers: map[string][]func(interface {}){},9 EventHandlersOnce: map[string][]func(interface {}){},10 },11 Browser: rod.Browser{12 Emitter: rod.Emitter{13 EventHandlers: map[string][]func(interface {}){},14 EventHandlersOnce: map[string][]func(interface {}){},15 },16 Target: rod.Target{17 Emitter: rod.Emitter{18 EventHandlers: map[string][]func(interface {}){},19 EventHandlersOnce: map[string][]func(interface {}){},20 },21 },22 Targets: []rod.Target{23 rod.Target{24 Emitter: rod.Emitter{25 EventHandlers: map[string][]func(interface {}){},26 EventHandlersOnce: map[string][]func(interface {}){},27 },28 },29 rod.Target{30 Emitter: rod.Emitter{31 EventHandlers: map[string][]func(interface {}){},32 EventHandlersOnce: map[string][]func(interface {}){},33 },34 },35 },36 Context: rod.BrowserContext{37 Emitter: rod.Emitter{38 EventHandlers: map[string][]func(interface {}){},39 EventHandlersOnce: map[string][]func(interface {}){},40 },41 Browser: rod.Browser{42 Emitter: rod.Emitter{43 EventHandlers: map[string][]func(interface {}){},44 EventHandlersOnce: map[string][]func(interface {}){},45 },46 Target: rod.Target{47 Emitter: rod.Emitter{48 EventHandlers: map[string][]func(interface {}){},49 EventHandlersOnce: map[string][]func(interface {}){},50 },
MustDescribe
Using AI Code Generation
1import (2func main() {3 rod.MustDescribe()4}5import (6func main() {7 rod.Describe()8}
MustDescribe
Using AI Code Generation
1import (2func main() {3 rod := new(Rod)4 rod.MustDescribe()5}6type Rod struct {7}8func (r *Rod) MustDescribe() {9 fmt.Println("Length of the rod is", r.Length)10 fmt.Println("Diameter of the rod is", r.Diameter)11 fmt.Println("Description of the rod is", r.Description)12}13import (14func main() {15 rod := new(Rod)16 rod.MustDescribe()17}18type Rod struct {19}20func (r *Rod) MustDescribe() {21 fmt.Println("Length of the rod is", r.Length)22 fmt.Println("Diameter of the rod is", r.Diameter)23 fmt.Println("Description of the rod is", r.Description)24}25import (26func main() {27 rod := new(Rod)28 rod.MustDescribe()29}30type Rod struct {31}32func (r *Rod) MustDescribe() {33 fmt.Println("
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!