Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement tag name selector for FindElementFromElement WebDriver command
  • Loading branch information
georgeroman committed Jul 21, 2019
1 parent dec73e4 commit 616a81f
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 16 deletions.
9 changes: 9 additions & 0 deletions components/script/script_thread.rs
Expand Up @@ -2052,6 +2052,15 @@ impl ScriptThread {
reply,
)
},
WebDriverScriptCommand::FindElementElementTagName(selector, element_id, reply) => {
webdriver_handlers::handle_find_element_element_tag_name(
&*documents,
pipeline_id,
element_id,
selector,
reply,
)
},
WebDriverScriptCommand::FindElementElementsCSS(selector, element_id, reply) => {
webdriver_handlers::handle_find_element_elements_css(
&*documents,
Expand Down
20 changes: 20 additions & 0 deletions components/script/webdriver_handlers.rs
Expand Up @@ -259,6 +259,26 @@ pub fn handle_find_element_element_css(
reply.send(node_id).unwrap();
}

pub fn handle_find_element_element_tag_name(
documents: &Documents,
pipeline: PipelineId,
element_id: String,
selector: String,
reply: IpcSender<Result<Option<String>, ()>>,
) {
let node_id = find_node_by_unique_id(documents, pipeline, element_id)
.ok_or(())
.and_then(|node| match node.downcast::<Element>() {
Some(elem) => Ok(elem
.GetElementsByTagName(DOMString::from(selector))
.elements_iter()
.next()),
None => Err(()),
})
.map(|node| node.map(|x| x.upcast::<Node>().unique_id()));
reply.send(node_id).unwrap();
}

pub fn handle_find_element_elements_css(
documents: &Documents,
pipeline: PipelineId,
Expand Down
1 change: 1 addition & 0 deletions components/script_traits/webdriver_msg.rs
Expand Up @@ -29,6 +29,7 @@ pub enum WebDriverScriptCommand {
FindElementsCSS(String, IpcSender<Result<Vec<String>, ()>>),
FindElementsTagName(String, IpcSender<Result<Vec<String>, ()>>),
FindElementElementCSS(String, String, IpcSender<Result<Option<String>, ()>>),
FindElementElementTagName(String, String, IpcSender<Result<Option<String>, ()>>),
FindElementElementsCSS(String, String, IpcSender<Result<Option<String>, ()>>),
FocusElement(String, IpcSender<Result<(), ()>>),
GetActiveElement(IpcSender<Option<String>>),
Expand Down
37 changes: 24 additions & 13 deletions components/webdriver_server/lib.rs
Expand Up @@ -950,21 +950,32 @@ impl Handler {
element: &WebElement,
parameters: &LocatorParameters,
) -> WebDriverResult<WebDriverResponse> {
if parameters.using != LocatorStrategy::CSSSelector {
return Err(WebDriverError::new(
ErrorStatus::UnsupportedOperation,
"Unsupported locator strategy",
));
}

let (sender, receiver) = ipc::channel().unwrap();
let cmd = WebDriverScriptCommand::FindElementElementCSS(
parameters.value.clone(),
element.id.clone(),
sender,
);

self.browsing_context_script_command(cmd)?;
match parameters.using {
LocatorStrategy::CSSSelector => {
let cmd = WebDriverScriptCommand::FindElementElementCSS(
parameters.value.clone(),
element.id.clone(),
sender,
);
self.browsing_context_script_command(cmd)?;
},
LocatorStrategy::TagName => {
let cmd = WebDriverScriptCommand::FindElementElementTagName(
parameters.value.clone(),
element.id.clone(),
sender,
);
self.browsing_context_script_command(cmd)?;
},
_ => {
return Err(WebDriverError::new(
ErrorStatus::UnsupportedOperation,
"Unsupported locator strategy",
));
},
}

match receiver.recv().unwrap() {
Ok(value) => {
Expand Down
Expand Up @@ -62,9 +62,6 @@
[test_find_element_partial_link_text[<a href=#>partial link text</a>-k t\]]
expected: FAIL

[test_find_element[tag name-a\]]
expected: FAIL

[test_xhtml_namespace[partial link text-link text\]]
expected: FAIL

Expand Down

0 comments on commit 616a81f

Please sign in to comment.