Skip to content

Commit

Permalink
Feature/new selector type (#657)
Browse files Browse the repository at this point in the history
* Added remote type reference resolver

* Added support of XPath query selector

* Added CDP e2e testss covering XPath integration

* Added additional CDP e2e tests covering XPath integration

* Added type check to QuerySelector casting function

* Fixed XPath e2e tests

* Fixed vuln issue

* Added support of XPath selectors to http driver

* Added e2e tests for XPAth
  • Loading branch information
ziflex authored Sep 17, 2021
1 parent a000302 commit 90427cd
Show file tree
Hide file tree
Showing 167 changed files with 2,228 additions and 1,055 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
LET url = @lab.cdn.dynamic + "/#/events"
LET page = DOCUMENT(url, true)

CLICK(page, "#wait-class-random button")
T::TRUE(CLICK(page, "#wait-class-random button"))

WAIT_CLASS(page, "#wait-class-random-content", "alert-success", 10000)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LET input = ELEMENT(page, "#text_input")

INPUT(input, "Foo")

CLICK(page, "#text_input", 2)
T::TRUE(CLICK(page, "#text_input", 2))

INPUT(input, "Bar")

Expand Down
8 changes: 8 additions & 0 deletions e2e/tests/dynamic/doc/click/click_by_xpath.fql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
LET url = @lab.cdn.dynamic + "/#/events"
LET page = DOCUMENT(url, true)

T::TRUE(CLICK(page, X("//button[@id='wait-class-random-btn']")))

WAIT_CLASS(page, "#wait-class-random-content", "alert-success", 10000)

RETURN TRUE
16 changes: 16 additions & 0 deletions e2e/tests/dynamic/doc/click/click_by_xpath_with_count.fql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
LET url = @lab.cdn.dynamic + "/#/forms"
LET page = DOCUMENT(url, true)

WAIT_ELEMENT(page, "form")

LET input = ELEMENT(page, "#text_input")

INPUT(input, "Foo")

T::TRUE(CLICK(page, X(".//*[@id='text_input']"), 2))

INPUT(input, "Bar")

WAIT(100)

RETURN T::EQ(input.value, "Bar")
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
LET url = @lab.cdn.dynamic
LET doc = DOCUMENT(url)
LET doc = DOCUMENT(url, { driver: "cdp" })

T::TRUE(ELEMENT_EXISTS(doc, '.text-center'))
T::FALSE(ELEMENT_EXISTS(doc, '.foo-bar'))
Expand Down
7 changes: 7 additions & 0 deletions e2e/tests/dynamic/doc/element/exists_by_xpath.fql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
LET url = @lab.cdn.dynamic
LET doc = DOCUMENT(url, { driver: "cdp" })

T::TRUE(ELEMENT_EXISTS(doc, X(".//*[contains(@class, 'text-center')]")))
T::FALSE(ELEMENT_EXISTS(doc, X(".//*[contains(@class, 'foo-bar')]")))

RETURN NONE
8 changes: 8 additions & 0 deletions e2e/tests/dynamic/doc/focus/focus_by_css.fql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
LET url = @lab.cdn.dynamic + "/#/events"
LET page = DOCUMENT(url, { driver: "cdp" })

FOCUS(page, "#focus-input")

WAIT_CLASS(page, "#focus-content", "alert-success")

RETURN TRUE
8 changes: 8 additions & 0 deletions e2e/tests/dynamic/doc/focus/focus_by_xpath.fql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
LET url = @lab.cdn.dynamic + "/#/events"
LET page = DOCUMENT(url, { driver: "cdp" })

FOCUS(page, X("//*[@id='focus-input']"))

WAIT_CLASS(page, "#focus-content", "alert-success")

RETURN TRUE
10 changes: 10 additions & 0 deletions e2e/tests/dynamic/doc/inner_html/get_by_xpath.fql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
LET url = @lab.cdn.dynamic
LET doc = DOCUMENT(url, { driver: "cdp" })
LET selector = X('//*[@id="root"]/div/main/div')

WAIT_ELEMENT(doc, "#layout")

LET expected = '<div><h1>Welcome to Ferret E2E test page!</h1></div><div><p class="lead">It has several pages for testing different possibilities of the library</p></div>'
LET actual = INNER_HTML(doc, selector)

RETURN T::EQ(REGEX_REPLACE(TRIM(actual), '(\n|\s)', ''), REGEX_REPLACE(expected, '\s', ''))
13 changes: 13 additions & 0 deletions e2e/tests/dynamic/doc/inner_html/get_by_xpath_all.fql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
LET url = @lab.cdn.dynamic
LET doc = DOCUMENT(url, true)
LET selector = X('//*[@id="root"]/div/main/div/*')

WAIT_ELEMENT(doc, "#layout")

LET expected = [
'<h1>Welcome to Ferret E2E test page!</h1>',
'<p class="lead">It has several pages for testing different possibilities of the library</p>'
]
LET actual = INNER_HTML_ALL(doc, selector)

RETURN T::EQ(actual, expected)
10 changes: 10 additions & 0 deletions e2e/tests/dynamic/doc/inner_text/get_by_xpath.fql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
LET url = @lab.cdn.dynamic
LET doc = DOCUMENT(url, { driver: "cdp" })
LET selector = X('.//*[@id="root"]/div/main/div/*/h1')

WAIT_ELEMENT(doc, "#layout")

LET expected = 'Welcome to Ferret E2E test page!'
LET actual = INNER_TEXT(doc, selector)

RETURN T::EQ(REGEX_REPLACE(TRIM(actual), '(\n|\s)', ''), REGEX_REPLACE(expected, '\s', ''))
16 changes: 16 additions & 0 deletions e2e/tests/dynamic/doc/inner_text/get_by_xpath_all.fql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
LET url = @lab.cdn.dynamic
LET doc = DOCUMENT(url, true)
LET selector = X('.//*[@id="root"]/div/main/div/*')

WAIT_ELEMENT(doc, "#layout")

LET expected = [
'Welcome to Ferret E2E test page!',
'It has several pages for testing different possibilities of the library'
]
LET actual = (
FOR str IN INNER_TEXT_ALL(doc, selector)
RETURN REGEX_REPLACE(TRIM(str), '\n', '')
)

RETURN T::EQ(actual, expected)
File renamed without changes.
10 changes: 10 additions & 0 deletions e2e/tests/dynamic/doc/input/input_by_xpath.fql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
LET url = @lab.cdn.dynamic + "?redirect=/forms"
LET doc = DOCUMENT(url, true)

WAIT_ELEMENT(doc, "form")

LET output = ELEMENT(doc, "#text_output")

INPUT(doc, X("//*[@id='text_input']"), "foo")

RETURN T::EQ(output.innerText, "foo")
File renamed without changes.
9 changes: 9 additions & 0 deletions e2e/tests/dynamic/doc/pagination_by_xpath.fql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
LET url = @lab.cdn.dynamic + "/#/pagination"
LET page = DOCUMENT(url, true)

LET items = (
FOR i IN PAGINATION(page, X("//li[contains(@class, 'page-item-next') and contains(@class, 'page-item') and not(contains(@class, 'disabled'))]"))
RETURN i
)

RETURN T::LEN(items, 5)
File renamed without changes.
12 changes: 12 additions & 0 deletions e2e/tests/dynamic/doc/select/multi_by_xpath.fql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
LET url = @lab.cdn.dynamic + "?redirect=/forms"
LET doc = DOCUMENT(url, true)

WAIT_ELEMENT(doc, "form")

LET output = ELEMENT(doc, "#multi_select_output")
LET result = SELECT(doc, X("//*[@id='multi_select_input']"), ["1", "2", "4"])

T::EQ(output.innerText, "1, 2, 4")
T::EQ(JSON_STRINGIFY(result), '["1","2","4"]')

RETURN NONE
File renamed without changes.
12 changes: 12 additions & 0 deletions e2e/tests/dynamic/doc/select/single_by_xpath.fql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
LET url = @lab.cdn.dynamic + "?redirect=/forms"
LET doc = DOCUMENT(url, { driver: "cdp" })

WAIT_ELEMENT(doc, "form")

LET output = ELEMENT(doc, "#select_output")
LET result = SELECT(doc, X("//*[@id='select_input']"), ["4"])

T::EQ(output.innerText, "4")
T::EQ(JSON_STRINGIFY(result), '["4"]')

RETURN NONE
File renamed without changes.
10 changes: 10 additions & 0 deletions e2e/tests/dynamic/doc/wait/attr_all_by_xpath.fql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
LET url = @lab.cdn.dynamic + "?redirect=/events"
LET doc = DOCUMENT(url, true)

WAIT_ELEMENT(doc, "#page-events")

CLICK_ALL(doc, "#wait-class-btn, #wait-class-random-btn")
T::LEN(ELEMENTS(doc, X("//*[@id='wait-class-content' or @id='wait-class-random-content']")), 2)
WAIT_ATTR_ALL(doc, X("//*[@id='wait-class-content' or @id='wait-class-random-content']"), "class", "alert alert-success", 10000)

RETURN TRUE
File renamed without changes.
20 changes: 20 additions & 0 deletions e2e/tests/dynamic/doc/wait/attr_by_xpath.fql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
LET url = @lab.cdn.dynamic + "?redirect=/events"
LET doc = DOCUMENT(url, true)
LET selector = X("//*[@id='wait-class-btn']")
LET attrName = "data-ferret-x"
LET attrVal = "foobar"

WAIT_ELEMENT(doc, "#page-events")

LET el = ELEMENT(doc, selector)
LET prev = el.attributes

ATTR_SET(el, attrName, attrVal)
WAIT_ATTR(doc, selector, attrName, attrVal, 30000)

LET curr = el.attributes

T::NONE(prev[attrName])
T::EQ(attrVal, curr[attrName], "attributes should be updated")

RETURN TRUE
File renamed without changes.
9 changes: 9 additions & 0 deletions e2e/tests/dynamic/doc/wait/class_all_by_xpath.fql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
LET url = @lab.cdn.dynamic + "?redirect=/events"
LET doc = DOCUMENT(url, true)

WAIT_ELEMENT(doc, "#page-events")

CLICK_ALL(doc, "#wait-class-btn, #wait-class-random-btn")
WAIT_CLASS_ALL(doc, X("//*[@id='wait-class-content' or @id='wait-class-random-content']"), "alert-success", 10000)

RETURN NONE
File renamed without changes.
14 changes: 14 additions & 0 deletions e2e/tests/dynamic/doc/wait/class_by_xpath.fql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
LET url = @lab.cdn.dynamic + "?redirect=/events"
LET doc = DOCUMENT(url, true)

WAIT_ELEMENT(doc, "#page-events")

// with fixed timeout
CLICK(doc, "#wait-class-btn")
WAIT_CLASS(doc, X("//*[@id='wait-class-content']"), "alert-success")

// with random timeout
CLICK(doc, "#wait-class-random-btn")
WAIT_CLASS(doc, X("//*[@id='wait-class-random-content']"), "alert-success", 10000)

RETURN NONE
File renamed without changes.
15 changes: 15 additions & 0 deletions e2e/tests/dynamic/doc/wait/element_by_xpath.fql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
LET url = @lab.cdn.dynamic + "?redirect=/events"
LET doc = DOCUMENT(url, true)
LET pageSelector = X("//*[@id='page-events']")
LET elemSelector = X("//*[@id='wait-element-content']")
LET btnSelector = "#wait-element-btn"

WAIT_ELEMENT(doc, pageSelector)

CLICK(doc, btnSelector)

WAIT_ELEMENT(doc, elemSelector, 10000)

T::TRUE(ELEMENT_EXISTS(doc, elemSelector), "element not found")

RETURN NONE
5 changes: 0 additions & 5 deletions e2e/tests/dynamic/doc/wait/frame_navigation.fqlx
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
LET url = @lab.cdn.dynamic + "?redirect=/iframe&src=/iframe"
// LET url = "http://192.168.4.23:8080/?redirect=/iframe&src=/iframe"
LET page = DOCUMENT(url, { driver: 'cdp' })
LET original = FIRST(FRAMES(page, "url", "/\?redirect=/iframe$"))

INPUT(original, "#url_input", "https://getbootstrap.com/")
// WAIT(3000)

// LET btn = ELEMENT(original, "#submit")
// CLICK(btn)

CLICK(original, "#submit")

Expand Down
File renamed without changes.
16 changes: 16 additions & 0 deletions e2e/tests/dynamic/doc/wait/no_attr_by_xpath.fql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
LET url = @lab.cdn.dynamic + "?redirect=/events"
LET doc = DOCUMENT(url, true)

WAIT_ELEMENT(doc, "#page-events")

// with fixed timeout
CLICK(doc, "#wait-no-class-btn")
WAIT(1000)
PRINT(ATTR_GET(ELEMENT(doc, "#wait-no-class-content"), "class"))
WAIT_NO_ATTR(doc, X("//*[@id='wait-no-class-content']"), "class", "alert alert-success")

// with random timeout
CLICK(doc, "#wait-no-class-random-btn")
WAIT_NO_ATTR(doc, X("//*[@id='wait-no-class-random-content']"), "class", "alert alert-success", 10000)

RETURN NONE
File renamed without changes.
9 changes: 9 additions & 0 deletions e2e/tests/dynamic/doc/wait/no_class_all_by_xpath.fql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
LET url = @lab.cdn.dynamic + "?redirect=/events"
LET doc = DOCUMENT(url, true)

WAIT_ELEMENT(doc, "#page-events")

CLICK_ALL(doc, "#wait-no-class-btn, #wait-no-class-random-btn")
WAIT_NO_CLASS_ALL(doc, X("//*[@id='wait-no-class-content' or @id='wait-no-class-random-content']"), "alert-success", 10000)

RETURN NONE
File renamed without changes.
14 changes: 14 additions & 0 deletions e2e/tests/dynamic/doc/wait/no_class_by_xpath.fql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
LET url = @lab.cdn.dynamic + "?redirect=/events"
LET doc = DOCUMENT(url, true)

WAIT_ELEMENT(doc, "#page-events")

// with fixed timeout
CLICK(doc, "#wait-no-class-btn")
WAIT_NO_CLASS(doc, X("//*[@id='wait-no-class-content']"), "alert-success")

// with random timeout
CLICK(doc, "#wait-no-class-random-btn")
WAIT_NO_CLASS(doc, X("//*[@id='wait-no-class-random-content']"), "alert-success", 10000)

RETURN NONE
File renamed without changes.
15 changes: 15 additions & 0 deletions e2e/tests/dynamic/doc/wait/no_element_by_xpath.fql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
LET url = @lab.cdn.dynamic + "?redirect=/events"
LET doc = DOCUMENT(url, true)
LET pageSelector = "#page-events"
LET elemSelector = X("//*[@id='wait-no-element-content']")
LET btnSelector = "#wait-no-element-btn"

WAIT_ELEMENT(doc, pageSelector)

CLICK(doc, btnSelector)

WAIT_NO_ELEMENT(doc, elemSelector, 10000)

T::FALSE(ELEMENT_EXISTS(doc, elemSelector), "element should not be found")

RETURN NONE
File renamed without changes.
32 changes: 32 additions & 0 deletions e2e/tests/dynamic/doc/wait/no_style_all_by_xpath.fql
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
LET url = @lab.cdn.dynamic + "?redirect=/events"
LET doc = DOCUMENT(url, true)
LET selector = X("//*[@id='wait-class-btn' or @id='wait-class-random-btn']")

WAIT_ELEMENT(doc, "#page-events")

LET n = (
FOR el IN ELEMENTS(doc, selector)
ATTR_SET(el, "style", "color: black")

RETURN NONE
)

WAIT_STYLE_ALL(doc, selector, "color", "rgb(0, 0, 0)", 10000)

LET n2 = (
FOR el IN ELEMENTS(doc, selector)
ATTR_SET(el, "style", "color: red")

RETURN NONE
)

WAIT_NO_STYLE_ALL(doc, selector, "color", "rgb(0, 0, 0)", 10000)

LET results = (
FOR el IN ELEMENTS(doc, selector)
RETURN el.style.color
)

T::EQ(results, ["rgb(255, 0, 0)","rgb(255, 0, 0)"])

RETURN NONE
File renamed without changes.
Loading

0 comments on commit 90427cd

Please sign in to comment.