Commit ca9396ea authored by Yiming Zhou's avatar Yiming Zhou Committed by Commit Bot

Account for different element visibility states in tests.

The Captured Sites Automation Framework interacts with real-life pages.
By default, the framework expects that a page element to be visible,
enabled and on top of the page. In the Chrome Autofill tests, some sites
break this expection. Some address or credit card fields are hidden
inputs, and some customized combo boxes have a selection element hide behind sibling span elements. Today, the test framework fails when encountering these exceptions.

The Action Recorder Extension already logs the visibility state of each
element it records. This change takes account of the element visibility
state information inside the recipe files.

Bug: 847905
Change-Id: Ibed7beef309d1bfbfb285cae02d026e172da8fb4
Reviewed-on: https://chromium-review.googlesource.com/c/1332701Reviewed-by: default avatarSebastien Seguin-Gagnon <sebsg@chromium.org>
Commit-Queue: Yiming Zhou <uwyiming@google.com>
Cr-Commit-Position: refs/heads/master@{#607433}
parent f164239c
......@@ -627,11 +627,16 @@ bool TestRecipeReplayer::ExecuteAutofillAction(
if (!GetTargetHTMLElementXpathFromAction(action, &xpath))
return false;
int visibility_enum_val;
if (!GetTargetHTMLElementVisibilityEnumFromAction(action,
&visibility_enum_val))
return false;
content::RenderFrameHost* frame;
if (!GetTargetFrameFromAction(action, &frame))
return false;
if (!WaitForElementToBeReady(frame, xpath))
if (!WaitForElementToBeReady(frame, xpath, visibility_enum_val))
return false;
VLOG(1) << "Invoking Chrome Autofill on `" << xpath << "`.";
......@@ -663,11 +668,16 @@ bool TestRecipeReplayer::ExecuteClickAction(
if (!GetTargetHTMLElementXpathFromAction(action, &xpath))
return false;
int visibility_enum_val;
if (!GetTargetHTMLElementVisibilityEnumFromAction(action,
&visibility_enum_val))
return false;
content::RenderFrameHost* frame;
if (!GetTargetFrameFromAction(action, &frame))
return false;
if (!WaitForElementToBeReady(frame, xpath))
if (!WaitForElementToBeReady(frame, xpath, visibility_enum_val))
return false;
VLOG(1) << "Left mouse clicking `" << xpath << "`.";
......@@ -687,11 +697,16 @@ bool TestRecipeReplayer::ExecuteHoverAction(
if (!GetTargetHTMLElementXpathFromAction(action, &xpath))
return false;
int visibility_enum_val;
if (!GetTargetHTMLElementVisibilityEnumFromAction(action,
&visibility_enum_val))
return false;
content::RenderFrameHost* frame;
if (!GetTargetFrameFromAction(action, &frame))
return false;
if (!WaitForElementToBeReady(frame, xpath))
if (!WaitForElementToBeReady(frame, xpath, visibility_enum_val))
return false;
VLOG(1) << "Hovering over `" << xpath << "`.";
......@@ -718,11 +733,16 @@ bool TestRecipeReplayer::ExecutePressEnterAction(
if (!GetTargetHTMLElementXpathFromAction(action, &xpath))
return false;
int visibility_enum_val;
if (!GetTargetHTMLElementVisibilityEnumFromAction(action,
&visibility_enum_val))
return false;
content::RenderFrameHost* frame;
if (!GetTargetFrameFromAction(action, &frame))
return false;
if (!WaitForElementToBeReady(frame, xpath))
if (!WaitForElementToBeReady(frame, xpath, visibility_enum_val))
return false;
VLOG(1) << "Press 'Enter' on `" << xpath << "`.";
......@@ -830,11 +850,16 @@ bool TestRecipeReplayer::ExecuteSelectDropdownAction(
if (!GetTargetHTMLElementXpathFromAction(action, &xpath))
return false;
int visibility_enum_val;
if (!GetTargetHTMLElementVisibilityEnumFromAction(action,
&visibility_enum_val))
return false;
content::RenderFrameHost* frame;
if (!GetTargetFrameFromAction(action, &frame))
return false;
if (!WaitForElementToBeReady(frame, xpath))
if (!WaitForElementToBeReady(frame, xpath, visibility_enum_val))
return false;
VLOG(1) << "Select option '" << index << "' from `" << xpath << "`.";
......@@ -872,11 +897,16 @@ bool TestRecipeReplayer::ExecuteTypeAction(
if (!GetTargetHTMLElementXpathFromAction(action, &xpath))
return false;
int visibility_enum_val;
if (!GetTargetHTMLElementVisibilityEnumFromAction(action,
&visibility_enum_val))
return false;
content::RenderFrameHost* frame;
if (!GetTargetFrameFromAction(action, &frame))
return false;
if (!WaitForElementToBeReady(frame, xpath))
if (!WaitForElementToBeReady(frame, xpath, visibility_enum_val))
return false;
VLOG(1) << "Typing '" << value << "' inside `" << xpath << "`.";
......@@ -900,11 +930,16 @@ bool TestRecipeReplayer::ExecuteTypePasswordAction(
if (!GetTargetHTMLElementXpathFromAction(action, &xpath))
return false;
int visibility_enum_val;
if (!GetTargetHTMLElementVisibilityEnumFromAction(action,
&visibility_enum_val))
return false;
content::RenderFrameHost* frame;
if (!GetTargetFrameFromAction(action, &frame))
return false;
if (!WaitForElementToBeReady(frame, xpath))
if (!WaitForElementToBeReady(frame, xpath, visibility_enum_val))
return false;
const base::Value* value_container = action.FindKey("value");
......@@ -971,11 +1006,16 @@ bool TestRecipeReplayer::ExecuteValidateFieldValueAction(
if (!GetTargetHTMLElementXpathFromAction(action, &xpath))
return false;
int visibility_enum_val;
if (!GetTargetHTMLElementVisibilityEnumFromAction(action,
&visibility_enum_val))
return false;
content::RenderFrameHost* frame;
if (!GetTargetFrameFromAction(action, &frame))
return false;
if (!WaitForElementToBeReady(frame, xpath))
if (!WaitForElementToBeReady(frame, xpath, visibility_enum_val))
return false;
const base::Value* autofill_prediction_container =
......@@ -1079,6 +1119,27 @@ bool TestRecipeReplayer::GetTargetHTMLElementXpathFromAction(
return true;
}
bool TestRecipeReplayer::GetTargetHTMLElementVisibilityEnumFromAction(
const base::DictionaryValue& action,
int* visibility_enum_val) {
const base::Value* visibility_container = action.FindKey("visibility");
if (!visibility_container) {
// By default, set the visibility to (visible | enabled | on_top), as
// defined in
// chrome/test/data/web_page_replay_go_helper_scripts/automation_helper.js
*visibility_enum_val = 7;
return true;
}
if (base::Value::Type::INTEGER != visibility_container->type()) {
ADD_FAILURE() << "visibility property is not an integer!";
return false;
}
*visibility_enum_val = visibility_container->GetInt();
return true;
}
bool TestRecipeReplayer::GetTargetFrameFromAction(
const base::DictionaryValue& action,
content::RenderFrameHost** frame) {
......@@ -1160,11 +1221,12 @@ bool TestRecipeReplayer::GetTargetFrameFromAction(
bool TestRecipeReplayer::WaitForElementToBeReady(
content::RenderFrameHost* frame,
const std::string& xpath) {
const std::string& xpath,
const int visibility_enum_val) {
std::vector<std::string> state_assertions;
state_assertions.push_back(base::StringPrintf(
"return automation_helper.isElementWithXpathReady(`%s`);",
xpath.c_str()));
"return automation_helper.isElementWithXpathReady(`%s`, %d);",
xpath.c_str(), visibility_enum_val));
return WaitForStateChange(frame, state_assertions, default_action_timeout);
}
......
......@@ -260,8 +260,12 @@ class TestRecipeReplayer {
std::string* xpath);
bool GetTargetFrameFromAction(const base::DictionaryValue& action,
content::RenderFrameHost** frame);
bool GetTargetHTMLElementVisibilityEnumFromAction(
const base::DictionaryValue& action,
int* visibility_enum_val);
bool WaitForElementToBeReady(content::RenderFrameHost* frame,
const std::string& xpath);
const std::string& xpath,
const int visibility_enum_val);
bool WaitForStateChange(
content::RenderFrameHost* frame,
const std::vector<std::string>& state_assertions,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment