MCPcopy Index your code
hub / github.com/tebeka/selenium / testLog

Function testLog

remote_test.go:1469–1532  ·  view source on GitHub ↗
(t *testing.T, c config)

Source from the content-addressed store, hash-verified

1467}
1468
1469func testLog(t *testing.T, c config) {
1470 switch {
1471 case c.browser == "htmlunit":
1472 t.Skip("Skipping on htmlunit")
1473 case c.browser == "firefox" && (c.seleniumVersion.Major == 3 || c.seleniumVersion.Major == 0):
1474 // Log is not supported on Firefox with Selenium 3.
1475 // https://github.com/w3c/webdriver/issues/406
1476 // https://github.com/mozilla/geckodriver/issues/284
1477 t.Skip("The log interface is not supported on Firefox, since it is not yet part of the W3C spec.")
1478 }
1479 caps := newTestCapabilities(t, c)
1480 caps.SetLogLevel(log.Browser, log.All)
1481 if c.browser == "chrome" {
1482 caps.SetLogLevel(log.Performance, log.All)
1483 }
1484
1485 wd := &remoteWD{
1486 capabilities: caps,
1487 urlPrefix: c.addr,
1488 }
1489 if _, err := wd.NewSession(); err != nil {
1490 t.Fatalf("wd.NewSession() returned error: %v", err)
1491 }
1492 defer quitRemote(t, wd)
1493
1494 url := serverURL + "/log"
1495 if err := wd.Get(url); err != nil {
1496 t.Fatalf("wd.Get(%q) returned error: %v", url, err)
1497 }
1498 logs, err := wd.Log(log.Browser)
1499 if err != nil {
1500 t.Fatalf("wd.Log(Browser) returned error: %v", err)
1501 }
1502 if len(logs) == 0 {
1503 t.Fatalf("empty reply from wd.Log(Browser)")
1504 } else {
1505 for _, l := range logs {
1506 if len(l.Level) == 0 || l.Timestamp.Unix() == 0 || len(l.Message) == 0 {
1507 t.Errorf("wd.Log(Browser) returned malformed message: %+v", l)
1508 }
1509 }
1510 }
1511
1512 if c.browser == "chrome" {
1513 logs, err = wd.Log(log.Performance)
1514 if err != nil {
1515 t.Fatalf("wd.Log(Performance) returned error: %v", err)
1516 }
1517 if len(logs) == 0 {
1518 t.Fatal("empty reply from wd.Log(Performance)")
1519 } else {
1520 for _, l := range logs {
1521 if len(l.Level) == 0 || l.Timestamp.Unix() == 0 || len(l.Message) == 0 {
1522 t.Errorf("wd.Log(Browser) returned malformed message: %+v", l)
1523 }
1524 // Make sure the timestamp conversion is vaguely correct. In
1525 // practice, this difference should be in the milliseconds range.
1526 if time.Now().Sub(l.Timestamp) > time.Hour {

Callers

nothing calls this directly

Calls 6

NewSessionMethod · 0.95
GetMethod · 0.95
LogMethod · 0.95
newTestCapabilitiesFunction · 0.85
quitRemoteFunction · 0.85
SetLogLevelMethod · 0.80

Tested by

no test coverage detected