Skip to content

Commit

Permalink
Implement tag name selector for FindElement WebDriver command
Browse files Browse the repository at this point in the history
  • Loading branch information
georgeroman committed Jul 21, 2019
1 parent 4128a38 commit 7d5b324
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 15 deletions.
8 changes: 8 additions & 0 deletions components/script/script_thread.rs
Expand Up @@ -2019,6 +2019,14 @@ impl ScriptThread {
reply,
)
},
WebDriverScriptCommand::FindElementTagName(selector, reply) => {
webdriver_handlers::handle_find_element_tag_name(
&*documents,
pipeline_id,
selector,
reply,
)
},
WebDriverScriptCommand::FindElementsCSS(selector, reply) => {
webdriver_handlers::handle_find_elements_css(
&*documents,
Expand Down
19 changes: 19 additions & 0 deletions components/script/webdriver_handlers.rs
Expand Up @@ -182,6 +182,25 @@ pub fn handle_find_element_css(
reply.send(node_id).unwrap();
}

pub fn handle_find_element_tag_name(
documents: &Documents,
pipeline: PipelineId,
selector: String,
reply: IpcSender<Result<Option<String>, ()>>,
) {
let node_id = documents
.find_document(pipeline)
.ok_or(())
.and_then(|doc| {
Ok(doc
.GetElementsByTagName(DOMString::from(selector))
.elements_iter()
.next())
})
.map(|node| node.map(|x| x.upcast::<Node>().unique_id()));
reply.send(node_id).unwrap();
}

pub fn handle_find_elements_css(
documents: &Documents,
pipeline: PipelineId,
Expand Down
1 change: 1 addition & 0 deletions components/script_traits/webdriver_msg.rs
Expand Up @@ -25,6 +25,7 @@ pub enum WebDriverScriptCommand {
ExecuteScript(String, IpcSender<WebDriverJSResult>),
ExecuteAsyncScript(String, IpcSender<WebDriverJSResult>),
FindElementCSS(String, IpcSender<Result<Option<String>, ()>>),
FindElementTagName(String, IpcSender<Result<Option<String>, ()>>),
FindElementsCSS(String, IpcSender<Result<Vec<String>, ()>>),
FindElementElementCSS(String, String, IpcSender<Result<Option<String>, ()>>),
FindElementElementsCSS(String, String, IpcSender<Result<Option<String>, ()>>),
Expand Down
26 changes: 17 additions & 9 deletions components/webdriver_server/lib.rs
Expand Up @@ -804,17 +804,25 @@ impl Handler {
&self,
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::FindElementCSS(parameters.value.clone(), sender);
self.browsing_context_script_command(cmd)?;
match parameters.using {
LocatorStrategy::CSSSelector => {
let cmd = WebDriverScriptCommand::FindElementCSS(parameters.value.clone(), sender);
self.browsing_context_script_command(cmd)?;
},
LocatorStrategy::TagName => {
let cmd =
WebDriverScriptCommand::FindElementTagName(parameters.value.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
6 changes: 0 additions & 6 deletions tests/wpt/metadata/webdriver/tests/find_element/find.py.ini
Expand Up @@ -11,9 +11,6 @@
[test_find_element_partial_link_text[<a href=#>&nbsp;partial link text&nbsp;</a>-link\]]
expected: FAIL

[test_htmldocument[tag name-html\]]
expected: FAIL

[test_find_element_link_text[<a href=#>link<br>text</a>-link\ntext\]]
expected: FAIL

Expand Down Expand Up @@ -62,9 +59,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 7d5b324

Please sign in to comment.