-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add Session/Element.requireElement #157
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,6 +98,16 @@ public struct Element { | |
try session.findElements(startingAt: self, locator: locator, waitTimeout: waitTimeout) | ||
} | ||
|
||
/// Finds an element using a given locator, starting from this element, and throwing upon failure. | ||
/// - Parameter locator: The locator strategy to use. | ||
/// - Parameter description: A human-readable description of the element, included in thrown errors. | ||
/// - Parameter waitTimeout: The amount of time to wait for element existence. Overrides the implicit wait timeout. | ||
/// - Returns: The element that was found. | ||
@discardableResult // for use as an assertion | ||
public func requireElement(locator: ElementLocator, description: String? = nil, waitTimeout: TimeInterval? = nil) throws -> Element { | ||
vinocher-bc marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would this be better as an extension method in our app instead? @jeffdav . I feel like it's not quite at the right layer here and I am leaning towards that (so we can have both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was going to ask, actually, because I was thinking about how to put it in the "supported apis" documentation. Could go either way. We could also have a new target in this project that is "bonus stuff". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like (nonmonetary) bonuses. I think I'll move this to the arc repo. It'll also make more sense with the custom error type. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. C'est bon. |
||
try session.requireElement(startingAt: self, locator: locator, description: description, waitTimeout: waitTimeout) | ||
} | ||
|
||
/// Gets an attribute of this element. | ||
/// - Parameter name: the attribute name. | ||
/// - Returns: the attribute value string. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
public struct ElementNotFoundError: Error { | ||
/// The locator that was used to search for the element. | ||
public var locator: ElementLocator | ||
|
||
/// A human-readable description of the element. | ||
public var description: String? | ||
|
||
/// The error that caused the element to not be found. | ||
public var sourceError: Error | ||
|
||
public init(locator: ElementLocator, description: String? = nil, sourceError: Error) { | ||
self.locator = locator | ||
self.description = description | ||
self.sourceError = sourceError | ||
} | ||
|
||
/// The error response returned by the WebDriver server, if this was the source of the failure. | ||
public var errorResponse: ErrorResponse? { sourceError as? ErrorResponse } | ||
} |
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.
why not just change
findElement
to return a non optional?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.
findElement
is neutral and I'm trying to call out thatif try? findElement() == nil
is a bad idea because it will wait the full timeout in the expected scenario. There might be other ways to achieve this, curious for your thoughtsThere 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.
Reviewing other languages bindings, I think you're right it makes more sense to throw: