Skip to content

Commit

Permalink
Update tests per PR suggestion
Browse files Browse the repository at this point in the history
Split the tests for relative locators and used a live page for the tests.
  • Loading branch information
pmartinez1 committed Sep 24, 2024
1 parent 49f4e58 commit 9ccc041
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 32 deletions.
62 changes: 50 additions & 12 deletions examples/python/tests/elements/test_locators.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ def test_find_by_classname():

def test_find_by_css_selector():
driver = webdriver.Chrome()
driver.get("https://www.selenium.dev/")
driver.get("https://www.selenium.dev/documentation/")

driver.find_element(By.CSS_SELECTOR, "#announcement-banner")
driver.find_element(By.CSS_SELECTOR, "#td-sidebar-menu")

driver.quit()

def test_find_by_id():
driver = webdriver.Chrome()
driver.get("https://www.selenium.dev/")
driver.get("https://www.selenium.dev/documentation/")

driver.find_element(By.ID, "announcement-banner")
driver.find_element(By.ID, "td-sidebar-menu")

driver.quit()

Expand Down Expand Up @@ -66,19 +66,57 @@ def test_find_by_xpath():

driver.quit()

def find_by_relative_locators():
def test_relative_locators_above():
driver = webdriver.Chrome()
driver.get("https://www.selenium.dev/")
driver.get("https://www.selenium.dev/selenium/web/inputs.html")

email_input = driver.find_element(locate_with(By.TAG_NAME, "input").above({ By.NAME: "password_input" }))
email_input.send_keys("[email protected]")

driver.quit()

def test_relative_locators_below():
driver = webdriver.Chrome()
driver.get("https://www.selenium.dev/selenium/web/inputs.html")

password_input = driver.find_element(locate_with(By.TAG_NAME, "input").below({ By.NAME: "email_input" }))
password_input.send_keys("randompassword")

driver.quit()

email_locator = locate_with(By.TAG_NAME, "input").above({By.ID: "password"})
def test_relative_locators_to_the_left_of():
driver = webdriver.Chrome()
driver.get("https://www.selenium.dev/selenium/web/inputs.html")

button = driver.find_element(locate_with(By.TAG_NAME, "input").to_left_of({ By.NAME: "submit_input" }))
button.click()

password_locator = locate_with(By.TAG_NAME, "input").below({By.ID: "email"})
driver.quit()

cancel_locator = locate_with(By.TAG_NAME, "button").to_left_of({By.ID: "submit"})
def test_relative_locators_to_the_right_of():
driver = webdriver.Chrome()
driver.get("https://www.selenium.dev/selenium/web/inputs.html")

submit_locator = locate_with(By.TAG_NAME, "button").to_right_of({By.ID: "cancel"})
button = driver.find_element(locate_with(By.TAG_NAME, "input").to_right_of({ By.NAME: "reset_input" }))
button.click()

email_locator = locate_with(By.TAG_NAME, "input").near({By.ID: "lbl-email"})
driver.quit()

def test_relative_locators_near():
driver = webdriver.Chrome()
driver.get("https://www.selenium.dev/selenium/web/inputs.html")

submit_locator = locate_with(By.TAG_NAME, "button").below({By.ID: "email"}).to_right_of({By.ID: "cancel"})
button = driver.find_element(locate_with(By.TAG_NAME, "input").near({ By.NAME: "week_input" }))
button.send_keys('someweek')

driver.quit()

def test_relative_locators_below_and_right_of():
driver = webdriver.Chrome()
driver.get("https://www.selenium.dev/selenium/web/inputs.html")

button = driver.find_element(locate_with(By.TAG_NAME, "input").below({ By.NAME: "week_input" }).to_right_of({ By.NAME: "button_input" }))
button.click()

driver.quit()

Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ we can locate the text field element using the fact that it is an "input" elemen
By passwordLocator = RelativeLocator.with(By.tagName("input")).below(By.id("email"));
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L75" >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L82" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
var passwordLocator = RelativeBy.WithLocator(By.TagName("input")).Below(By.Id("email"));
Expand All @@ -499,7 +499,7 @@ we can locate the cancel button element using the fact that it is a "button" ele
By cancelLocator = RelativeLocator.with(By.tagName("button")).toLeftOf(By.id("submit"));
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L77" >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L91" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
var cancelLocator = RelativeBy.WithLocator(By.tagName("button")).LeftOf(By.Id("submit"));
Expand All @@ -526,7 +526,7 @@ we can locate the submit button element using the fact that it is a "button" ele
By submitLocator = RelativeLocator.with(By.tagName("button")).toRightOf(By.id("cancel"));
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L79" >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L100" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
var submitLocator = RelativeBy.WithLocator(By.tagName("button")).RightOf(By.Id("cancel"));
Expand Down Expand Up @@ -555,7 +555,7 @@ but its associated [input label element](https://developer.mozilla.org/en-US/doc
By emailLocator = RelativeLocator.with(By.tagName("input")).near(By.id("lbl-email"));
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L81" >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L109" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
var emailLocator = RelativeBy.WithLocator(By.tagName("input")).Near(By.Id("lbl-email"));
Expand All @@ -581,7 +581,7 @@ You can also chain locators if needed. Sometimes the element is most easily iden
By submitLocator = RelativeLocator.with(By.tagName("button")).below(By.id("email")).toRightOf(By.id("cancel"));
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L83" >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L118" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
var submitLocator = RelativeBy.WithLocator(By.tagName("button")).Below(By.Id("email")).RightOf(By.Id("cancel"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ we can locate the text field element using the fact that it is an "input" elemen
By passwordLocator = RelativeLocator.with(By.tagName("input")).below(By.id("email"));
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L75" >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L82" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
var passwordLocator = RelativeBy.WithLocator(By.TagName("input")).Below(By.Id("email"));
Expand All @@ -488,7 +488,7 @@ we can locate the cancel button element using the fact that it is a "button" ele
By cancelLocator = RelativeLocator.with(By.tagName("button")).toLeftOf(By.id("submit"));
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L77" >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L91" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
var cancelLocator = RelativeBy.WithLocator(By.tagName("button")).LeftOf(By.Id("submit"));
Expand All @@ -514,7 +514,7 @@ we can locate the submit button element using the fact that it is a "button" ele
By submitLocator = RelativeLocator.with(By.tagName("button")).toRightOf(By.id("cancel"));
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L79" >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L100" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
var submitLocator = RelativeBy.WithLocator(By.tagName("button")).RightOf(By.Id("cancel"));
Expand Down Expand Up @@ -542,7 +542,7 @@ but its associated [input label element](https://developer.mozilla.org/en-US/doc
By emailLocator = RelativeLocator.with(By.tagName("input")).near(By.id("lbl-email"));
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L81" >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L109" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
var emailLocator = RelativeBy.WithLocator(By.tagName("input")).Near(By.Id("lbl-email"));
Expand All @@ -567,7 +567,7 @@ You can also chain locators if needed. Sometimes the element is most easily iden
By submitLocator = RelativeLocator.with(By.tagName("button")).below(By.id("email")).toRightOf(By.id("cancel"));
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L83" >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L118" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
var submitLocator = RelativeBy.WithLocator(By.tagName("button")).Below(By.Id("email")).RightOf(By.Id("cancel"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ we can locate the text field element using the fact that it is an "input" elemen
By passwordLocator = RelativeLocator.with(By.tagName("input")).below(By.id("email"));
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L75" >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L82" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
var passwordLocator = RelativeBy.WithLocator(By.TagName("input")).Below(By.Id("email"));
Expand All @@ -491,7 +491,7 @@ we can locate the cancel button element using the fact that it is a "button" ele
By cancelLocator = RelativeLocator.with(By.tagName("button")).toLeftOf(By.id("submit"));
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L77" >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L91" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
var cancelLocator = RelativeBy.WithLocator(By.tagName("button")).LeftOf(By.Id("submit"));
Expand All @@ -517,7 +517,7 @@ we can locate the submit button element using the fact that it is a "button" ele
By submitLocator = RelativeLocator.with(By.tagName("button")).toRightOf(By.id("cancel"));
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L79" >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L100" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
var submitLocator = RelativeBy.WithLocator(By.tagName("button")).RightOf(By.Id("cancel"));
Expand Down Expand Up @@ -545,7 +545,7 @@ but its associated [input label element](https://developer.mozilla.org/en-US/doc
By emailLocator = RelativeLocator.with(By.tagName("input")).near(By.id("lbl-email"));
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L81" >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L109" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
var emailLocator = RelativeBy.WithLocator(By.tagName("input")).Near(By.Id("lbl-email"));
Expand All @@ -570,7 +570,7 @@ You can also chain locators if needed. Sometimes the element is most easily iden
By submitLocator = RelativeLocator.with(By.tagName("button")).below(By.id("email")).toRightOf(By.id("cancel"));
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L83" >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L118" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
var submitLocator = RelativeBy.WithLocator(By.tagName("button")).Below(By.Id("email")).RightOf(By.Id("cancel"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ we can locate the text field element using the fact that it is an "input" elemen
By passwordLocator = RelativeLocator.with(By.tagName("input")).below(By.id("email"));
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L75" >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L82" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
var passwordLocator = RelativeBy.WithLocator(By.TagName("input")).Below(By.Id("email"));
Expand All @@ -491,7 +491,7 @@ we can locate the cancel button element using the fact that it is a "button" ele
By cancelLocator = RelativeLocator.with(By.tagName("button")).toLeftOf(By.id("submit"));
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L77" >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L91" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
var cancelLocator = RelativeBy.WithLocator(By.tagName("button")).LeftOf(By.Id("submit"));
Expand All @@ -517,7 +517,7 @@ we can locate the submit button element using the fact that it is a "button" ele
By submitLocator = RelativeLocator.with(By.tagName("button")).toRightOf(By.id("cancel"));
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L79" >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L100" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
var submitLocator = RelativeBy.WithLocator(By.tagName("button")).RightOf(By.Id("cancel"));
Expand Down Expand Up @@ -545,7 +545,7 @@ but its associated [input label element](https://developer.mozilla.org/en-US/doc
By emailLocator = RelativeLocator.with(By.tagName("input")).near(By.id("lbl-email"));
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L81" >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L109" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
var emailLocator = RelativeBy.WithLocator(By.tagName("input")).Near(By.Id("lbl-email"));
Expand All @@ -570,7 +570,7 @@ You can also chain locators if needed. Sometimes the element is most easily iden
By submitLocator = RelativeLocator.with(By.tagName("button")).below(By.id("email")).toRightOf(By.id("cancel"));
{{< /tab >}}
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L83" >}}
{{< gh-codeblock path="examples/python/tests/elements/test_locators.py#L118" >}}
{{< /tab >}}
{{< tab header="CSharp" >}}
var submitLocator = RelativeBy.WithLocator(By.tagName("button")).Below(By.Id("email")).RightOf(By.Id("cancel"));
Expand Down

0 comments on commit 9ccc041

Please sign in to comment.