Skip to content

Commit

Permalink
Update to 62.0.3202.9
Browse files Browse the repository at this point in the history
  • Loading branch information
wirepair committed Sep 9, 2017
1 parent b057a64 commit 10646c9
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 24 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Autogcd is a wrapper around the [gcd](https://github.com/wirepair/gcd/) library to enable automation of Google Chrome. It some what mimics the functionality offered by WebDriver but allows more low level access via the debugger service.

## Changelog (2017)
- September 9th: Updated to latest gcd / protocol.json file for 62.0.3202.9. We are now bound to the browser version (latest dev channel). See [gcd](https://github.com/wirepair/gcd/) updates for more information. Note if you change the gcd channel, you'll probably end up breaking a lot of methods in autogcd, so be warned.
- August 15th: Updated to the latest gcd / protocol.json file.
- May: Updated to latest gcd / protocol.json file.
- April: Updated to latest gcd / protocol.json file. Fixed unit tests to wait for stability a bit longer as node changes seem to take longer than before.
Expand Down
2 changes: 1 addition & 1 deletion api_overrides.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
The MIT License (MIT)
Copyright (c) 2016 isaac dawson
Copyright (c) 2017 isaac dawson
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 6 additions & 2 deletions autogcd.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
The MIT License (MIT)
Copyright (c) 2016 isaac dawson
Copyright (c) 2017 isaac dawson
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -90,7 +90,7 @@ func NewAutoGcd(settings *Settings) *AutoGcd {

// Default termination handling is to log, override with SetTerminationHandler
func (auto *AutoGcd) defaultTerminationHandler(reason string) {
panic(fmt.Sprintf("chrome was terminated: %s\n", reason))
fmt.Printf("chrome was terminated: %s\n", reason)
}

// Allow callers to handle chrome terminating.
Expand Down Expand Up @@ -262,3 +262,7 @@ func (auto *AutoGcd) tabById(id string) (*Tab, error) {
}
return tab, nil
}

func (auto *AutoGcd) GetChromeRevision() string {
return auto.debugger.GetRevision()
}
14 changes: 13 additions & 1 deletion autogcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"os/exec"
"runtime"
"strings"
"testing"
"time"
)
Expand Down Expand Up @@ -64,9 +65,11 @@ func TestStart(t *testing.T) {
auto.SetTerminationHandler(nil)
}

func TestGetTab(t *testing.T) {
func TestGetTabCheckVersion(t *testing.T) {
var err error
var tab *Tab
var product string

auto := testDefaultStartup(t)
defer auto.Shutdown()

Expand All @@ -78,6 +81,15 @@ func TestGetTab(t *testing.T) {
if tab.Target.Type != "page" {
t.Fatalf("Got tab but wasn't of type Page")
}

if _, product, _, _, _, err = tab.Browser.GetVersion(); err != nil {
t.Fatalf("Error getting browser version information: %s\n", err)
}

if !strings.Contains(product, auto.GetChromeRevision()) {
t.Fatalf("Error browser version: %s does not match gcd api version: %s\n", product, auto.GetChromeRevision())

}
}

func TestNewTab(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion conditionals.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
The MIT License (MIT)
Copyright (c) 2016 isaac dawson
Copyright (c) 2017 isaac dawson
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
3 changes: 2 additions & 1 deletion element.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ func (e *Element) GetSource() (string, error) {
return "", &InvalidElementErr{}
}
e.tab.debugf("id: %d\n", id)
return e.tab.DOM.GetOuterHTML(id)
outerParams := &gcdapi.DOMGetOuterHTMLParams{NodeId: id}
return e.tab.DOM.GetOuterHTMLWithParams(outerParams)
}

// Is this Element a #document?
Expand Down
8 changes: 4 additions & 4 deletions element_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func TestElementMouseOver(t *testing.T) {
if err != nil {
t.Fatalf("error getting tab")
}
//tab.Debug(true)

msgHandler := func(callerTab *Tab, message *gcdapi.ConsoleConsoleMessage) {
t.Logf("Got message %v\n", message)
if message.Text == "moused over" {
Expand Down Expand Up @@ -145,13 +145,13 @@ func TestElementMouseOver(t *testing.T) {
t.Fatalf("error moving mouse over button: %s\n", err)
}

timeout := time.NewTimer(time.Second * 8)
go func() {
timeout := time.NewTimer(time.Second * 4)
go func(timeout *time.Timer) {
select {
case <-timeout.C:
t.Fatalf("timed out waiting for button click event message")
}
}()
}(timeout)

wg.Wait()
timeout.Stop()
Expand Down
2 changes: 1 addition & 1 deletion settings.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
The MIT License (MIT)
Copyright (c) 2016 isaac dawson
Copyright (c) 2017 isaac dawson
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
37 changes: 26 additions & 11 deletions tab.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
The MIT License (MIT)
Copyright (c) 2016 isaac dawson
Copyright (c) 2017 isaac dawson
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -661,7 +661,8 @@ func (t *Tab) GetPageSource(docNodeId int) (string, error) {
if !ok {
return "", &ElementNotFoundErr{Message: fmt.Sprintf("docNodeId %d not found", docNodeId)}
}
return t.DOM.GetOuterHTML(doc.id)
outerParams := &gcdapi.DOMGetOuterHTMLParams{NodeId: doc.id}
return t.DOM.GetOuterHTMLWithParams(outerParams)
}

// Returns the current url of the top level document
Expand All @@ -686,17 +687,26 @@ func (t *Tab) Click(x, y float64) error {
func (t *Tab) click(x, y float64, clickCount int) error {
// "mousePressed", "mouseReleased", "mouseMoved"
// enum": ["none", "left", "middle", "right"]
pressed := "mousePressed"
released := "mouseReleased"
modifiers := 0
timestamp := 0.0
button := "left"
time.Now().Second()
if _, err := t.Input.DispatchMouseEvent(pressed, x, y, modifiers, timestamp, button, clickCount); err != nil {

mousePressedParams := &gcdapi.InputDispatchMouseEventParams{TheType: "mousePressed",
X: x,
Y: y,
Button: "left",
ClickCount: clickCount,
}

if _, err := t.Input.DispatchMouseEventWithParams(mousePressedParams); err != nil {
return err
}

if _, err := t.Input.DispatchMouseEvent(released, x, y, modifiers, timestamp, button, clickCount); err != nil {
mouseReleasedParams := &gcdapi.InputDispatchMouseEventParams{TheType: "mouseReleased",
X: x,
Y: y,
Button: "left",
ClickCount: clickCount,
}

if _, err := t.Input.DispatchMouseEventWithParams(mouseReleasedParams); err != nil {
return err
}
return nil
Expand All @@ -709,7 +719,12 @@ func (t *Tab) DoubleClick(x, y float64) error {

// Moves the mouse to the x, y coords provided.
func (t *Tab) MoveMouse(x, y float64) error {
_, err := t.Input.DispatchMouseEvent("mouseMoved", x, y, 0, 0.0, "none", 0)
mouseMovedParams := &gcdapi.InputDispatchMouseEventParams{TheType: "mouseMoved",
X: x,
Y: y,
}

_, err := t.Input.DispatchMouseEventWithParams(mouseMovedParams)
return err
}

Expand Down
2 changes: 1 addition & 1 deletion tab_subscribers.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
The MIT License (MIT)
Copyright (c) 2016 isaac dawson
Copyright (c) 2017 isaac dawson
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion types.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
The MIT License (MIT)
Copyright (c) 2016 isaac dawson
Copyright (c) 2017 isaac dawson
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down

0 comments on commit 10646c9

Please sign in to comment.