-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[py]: move python code to test_locators.py
#2102
Open
navin772
wants to merge
2
commits into
SeleniumHQ:trunk
Choose a base branch
from
navin772:py-locators
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<html> | ||
<body> | ||
<style> | ||
.information { | ||
background-color: white; | ||
color: black; | ||
padding: 10px; | ||
} | ||
</style> | ||
<h2>Contact Selenium</h2> | ||
|
||
<form> | ||
<input type="radio" name="gender" value="m" />Male | ||
<input type="radio" name="gender" value="f" />Female <br> | ||
<br> | ||
<label for="fname">First name:</label><br> | ||
<input class="information" type="text" id="fname" name="fname" value="Jane"><br><br> | ||
<label for="lname">Last name:</label><br> | ||
<input class="information" type="text" id="lname" name="lname" value="Doe"><br><br> | ||
<label for="newsletter">Newsletter:</label> | ||
<input type="checkbox" name="newsletter" value="1" /><br><br> | ||
<input type="submit" value="Submit"> | ||
</form> | ||
|
||
<p>To know more about Selenium, visit the official page | ||
<a href ="https://www.selenium.dev/">Selenium Official Page</a> | ||
</p> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,54 @@ | ||
import pytest | ||
from selenium import webdriver | ||
from selenium.webdriver.common.by import By | ||
|
||
@pytest.fixture | ||
def driver(html_server): | ||
""" | ||
Initialize the WebDriver and navigate to the elements/locators.html page. | ||
""" | ||
driver = webdriver.Chrome() | ||
driver.implicitly_wait(0.5) | ||
driver.get(f"{html_server}/elements/locators.html") | ||
yield driver | ||
driver.quit() | ||
|
||
def test_class_name(driver): | ||
element = driver.find_element(By.CLASS_NAME, "information") | ||
assert element is not None | ||
assert element.tag_name == "input" | ||
|
||
def test_css_selector(driver): | ||
element = driver.find_element(By.CSS_SELECTOR, "#fname") | ||
assert element is not None | ||
assert element.get_attribute("value") == "Jane" | ||
|
||
def test_id(driver): | ||
element = driver.find_element(By.ID, "lname") | ||
assert element is not None | ||
assert element.get_attribute("value") == "Doe" | ||
|
||
def test_name(driver): | ||
element = driver.find_element(By.NAME, "newsletter") | ||
assert element is not None | ||
assert element.tag_name == "input" | ||
|
||
def test_link_text(driver): | ||
element = driver.find_element(By.LINK_TEXT, "Selenium Official Page") | ||
assert element is not None | ||
assert element.get_attribute("href") == "https://www.selenium.dev/" | ||
|
||
def test_partial_link_text(driver): | ||
element = driver.find_element(By.PARTIAL_LINK_TEXT, "Official Page") | ||
assert element is not None | ||
assert element.get_attribute("href") == "https://www.selenium.dev/" | ||
|
||
def test_tag_name(driver): | ||
element = driver.find_element(By.TAG_NAME, "a") | ||
assert element is not None | ||
assert element.get_attribute("href") == "https://www.selenium.dev/" | ||
|
||
def test_xpath(driver): | ||
element = driver.find_element(By.XPATH, "//input[@value='f']") | ||
assert element is not None | ||
assert element.get_attribute("type") == "radio" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't place HTML code here. Instead, you can use the static pages deployed on the official Selenium website
https://www.selenium.dev/selenium/web/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't find a similar html page, so created a PR to add it in selenium - SeleniumHQ/selenium#14905