Skip to content

Commit

Permalink
feat: refactor 'By' constants names to use PascalCase (#63)
Browse files Browse the repository at this point in the history
* feat: refactor 'By' constants names to use PascalCase

* feat: refactor 'By' constants names to use PascalCase

* feat: refactor 'By' constants names to use PascalCase
  • Loading branch information
njasm authored Oct 31, 2024
1 parent 48629c1 commit 258d726
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 42 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ jobs:
strategy:
fail-fast: false
matrix:
# If you change the Matrix values, make sure to update the 'carryforward'
# field of the coveralls app job below.
os: [ ubuntu-latest ]
go: [ 1.22.x ]
firefox: [ "130.0.1", "131.0.3", "132.0" ]
Expand Down Expand Up @@ -65,7 +67,7 @@ jobs:
outfile: coverage.lcov

- name: Coveralls
uses: coverallsapp/github-action@v1.1.2
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.github_token }}
path-to-lcov: coverage.lcov
Expand All @@ -77,11 +79,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@v1.2.4
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
flag-name: run ${{ join(matrix.*, ' - ') }}
parallel: true
debug: true
parallel-finished: true

windows:
Expand Down
58 changes: 36 additions & 22 deletions by.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,48 @@
package marionette_client

// strategy type to find elements in the DOM
import "fmt"

type ByStrategy interface {
fmt.Stringer
}

// By strategy type to find elements in the DOM
type By int

/*
:param method: The method to use to locate the element; one of:
"id", "name", "class name", "tag name", "css selector",
"link text", "partial link text", "xpath", "anon" and "anon
attribute". Note that the "name", "link text" and "partial
link test" methods are not supported in the chrome DOM.
:param target: The target of the search. For example, if method =
"tag", target might equal "div". If method = "id", target would
be an element id.
:param id: If specified, search for elements only inside the element
with the specified id.
"""
The method to use to locate the element; one of:
"id", "name", "class name", "tag name", "css selector",
"link text", "partial link text", "xpath", "anon" and "anon
attribute". Note that the "name", "link text" and "partial
link test" methods are not supported in the chrome DOM.
:param target: The target of the search. For example, if method =
"tag", target might equal "div". If method = "id", target would
be an element id.
:param id: If specified, search for elements only inside the element
with the specified id.
*/
const (
ID By = 1 + iota
NAME
CLASS_NAME
TAG_NAME
CSS_SELECTOR
LINK_TEXT
PARTIAL_LINK_TEXT
XPATH
ANON
ANON_ATTRIBUTE
Id By = 1 + iota
Name
ClassName
TagName
CssSelector
LinkText
PartialLinkText
Xpath
Anon
AnonAttribute
)

func ID() By {
return By(Id)
}

var bys = [...]string{
"id",
"name",
Expand Down
6 changes: 3 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func (c *Client) Context() (*Response, error) {
// WINDOWS HANDLES //
/////////////////////

// GetWindowHandle returns the current window ID
// GetWindowHandle returns the current window Id
func (c *Client) GetWindowHandle() (string, error) {
r, err := c.transport.Send("WebDriver:GetWindowHandle", nil)
if err != nil {
Expand All @@ -299,7 +299,7 @@ func (c *Client) GetWindowHandle() (string, error) {
return d["value"], nil
}

// GetWindowHandles return array of window ID currently opened
// GetWindowHandles return array of window Id currently opened
func (c *Client) GetWindowHandles() ([]string, error) {
r, err := c.transport.Send("WebDriver:GetWindowHandles", nil)
if err != nil {
Expand Down Expand Up @@ -461,7 +461,7 @@ func (c *Client) CloseChromeWindow() (*Response, error) {
// FRAMES //
////////////

// SwitchToFrame switch to frame - strategies: By(ID), By(NAME) or name only.
// SwitchToFrame switch to frame - strategies: By(Id), By(Name) or name only.
func (c *Client) SwitchToFrame(by By, value string) error {

//with current marionette implementation we have to find the element first and send the switchToFrame
Expand Down
14 changes: 7 additions & 7 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,13 +337,13 @@ func GetActiveElementTest(t *testing.T) {
// theres always an active element?
t.Logf("%#v", r)

form, err := client.FindElement(By(NAME), "optional")
form, err := client.FindElement(By(Name), "optional")
if err != nil {
t.Fatalf("%#v", err)
}

// click on a *other* form element to activate
e, _ := client.FindElement(By(ID), "email")
e, _ := client.FindElement(By(Id), "email")
e.Click()

// assert now
Expand Down Expand Up @@ -482,7 +482,7 @@ func GetTitleTest(t *testing.T) {

func FindElementTest(t *testing.T) {
navigateLocal("table.html")
element, err := client.FindElement(By(ID), "the-table")
element, err := client.FindElement(By(Id), "the-table")
if err != nil {
t.Fatalf("%#v", err)
}
Expand Down Expand Up @@ -532,7 +532,7 @@ func FindElementTest(t *testing.T) {
t.Fatalf("%#v", err)
}

collection, err := element.FindElements(By(CSS_SELECTOR), CSS_SELECTOR_LI)
collection, err := element.FindElements(By(CssSelector), CSS_SELECTOR_LI)
if err != nil {
t.Fatalf("%#v", err)
}
Expand All @@ -543,7 +543,7 @@ func FindElementTest(t *testing.T) {

t.Logf("%T %#v", collection, collection)

el, err := element.FindElement(By(CSS_SELECTOR), CSS_SELECTOR_LI)
el, err := element.FindElement(By(CssSelector), CSS_SELECTOR_LI)
if el == nil || err != nil {
t.FailNow()
}
Expand All @@ -552,7 +552,7 @@ func FindElementTest(t *testing.T) {

func SendKeysTest(t *testing.T) {
navigateLocal("form.html")
e, err := client.FindElement(By(ID), "email")
e, err := client.FindElement(By(Id), "email")
if err != nil {
t.Fatalf("%#v", err)
}
Expand All @@ -579,7 +579,7 @@ func SendKeysTest(t *testing.T) {

func FindElementsTest(t *testing.T) {
navigateLocal("ul.html")
elements, err := client.FindElements(By(CSS_SELECTOR), CSS_SELECTOR_LI)
elements, err := client.FindElements(By(CssSelector), CSS_SELECTOR_LI)
if err != nil {
t.Fatalf("%#v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions expected_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func ElementIsPresentFalseTest(t *testing.T) {
fake := new(fakeFinder)
fake.ReturnError = true

fun := ElementIsPresent(By(ID), "")
fun := ElementIsPresent(By(Id), "")

r, _, _ := fun(fake)
if r {
Expand All @@ -46,7 +46,7 @@ func ElementIsPresentFalseTest(t *testing.T) {
// required test in sequential main client test: client_test.go
func NotPresentTest(t *testing.T) {
timeout := time.Duration(5) * time.Second
condition := ElementIsNotPresent(By(ID), "non-existing-element")
condition := ElementIsNotPresent(By(Id), "non-existing-element")
ok, _, _ := Wait(client).For(timeout).Until(condition)

if !ok {
Expand Down
2 changes: 1 addition & 1 deletion transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (t *MarionetteTransport) Close() error {
}

func (t *MarionetteTransport) Send(command string, values interface{}) (*Response, error) {
t.messageID = t.messageID + 1 // next message ID
t.messageID = t.messageID + 1 // next message Id
buf, err := t.de.Encode(t, command, values)
if err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions wait_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func WaitForUntilIntegrationTest(t *testing.T) {
client.Navigate("http://www.w3schools.com/xml/tryit.asp?filename=tryajax_get")

timeout := time.Duration(10) * time.Second
condition := ElementIsPresent(By(CSS_SELECTOR), "a.w3-button.w3-bar-item.topnav-icons.fa.fa-rotate")
condition := ElementIsPresent(By(CssSelector), "a.w3-button.w3-bar-item.topnav-icons.fa.fa-rotate")
ok, v, err := Wait(client).For(timeout).Until(condition)

if err != nil || !ok {
Expand All @@ -50,12 +50,12 @@ func WaitForUntilIntegrationTest(t *testing.T) {

v.Click()

err = client.SwitchToFrame(By(ID), "iframeResult")
err = client.SwitchToFrame(By(Id), "iframeResult")
if err != nil {
t.Fatalf("%#v", err)
}

e, err := client.FindElement(By(TAG_NAME), "button")
e, err := client.FindElement(By(TagName), "button")
if err != nil {
t.Fatalf("%#v", err)
}
Expand Down

0 comments on commit 258d726

Please sign in to comment.