Added SelectContextMenuId Command, increasing uiabridge speeds, reliability

This commit is contained in:
Edward Jakubowski
2014-05-02 22:01:43 -04:00
parent ce78f9c084
commit 4258d0977f
19 changed files with 185 additions and 65 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -24,7 +24,8 @@ using namespace uiabridge;
*/
JNIEXPORT void JNICALL Java_org_synthuse_UiaBridge_initialize(JNIEnv *env, jobject obj, jstring jproperties)
{
Global::AUTO_BRIDGE = gcnew AutomationBridge();
const char *properties = env->GetStringUTFChars(jproperties, 0);//convert string
Global::AUTO_BRIDGE = gcnew AutomationBridge(marshal_as<String ^>(properties));
}
/*

View File

@@ -18,7 +18,14 @@ AutomationBridge::AutomationBridge()
{
enumFilters = gcnew Dictionary<System::String ^, System::String ^>();
cacheRequest = nullptr;
initializeCache();
initializeCache("");
}
AutomationBridge::AutomationBridge(System::String ^cachedProperties)
{
enumFilters = gcnew Dictionary<System::String ^, System::String ^>();
cacheRequest = nullptr;
initializeCache(cachedProperties);
}
AutomationBridge::~AutomationBridge()
@@ -29,7 +36,7 @@ AutomationBridge::~AutomationBridge()
//Console::WriteLine("disposing of AutomationBridge");
}
void AutomationBridge::initializeCache()
void AutomationBridge::initializeCache(System::String ^cachedProperties)
{
cacheRequest = gcnew CacheRequest();
//cacheRequest->AutomationElementMode = AutomationElementMode::Full;
@@ -45,7 +52,11 @@ void AutomationBridge::initializeCache()
cacheRequest->Add(AutomationElement::NameProperty);
cacheRequest->Add(AutomationElement::BoundingRectangleProperty);
*/
System::String ^cachedPropStr = L"RuntimeIdProperty,ParentRuntimeIdProperty,NativeWindowHandleProperty,ProcessIdProperty,FrameworkIdProperty,LocalizedControlTypeProperty,ControlTypeProperty,ClassNameProperty,NameProperty,BoundingRectangleProperty,ValueProperty";
System::String ^cachedPropStr = cachedProperties;
if (cachedPropStr == nullptr) // check if blank/null we need to use DEFAULT_CACHED_PROPS;
cachedPropStr = DEFAULT_CACHED_PROPS;
else if (cachedPropStr->Equals(""))
cachedPropStr = DEFAULT_CACHED_PROPS;
array<AutomationProperty^> ^rootProperties = AutomationElement::RootElement->GetSupportedProperties();
List<AutomationProperty^> ^cacheList = gcnew List<AutomationProperty^>();
if (cachedPropStr->Contains(L"NativeWindowHandleProperty")) //special property not in the root property list
@@ -244,7 +255,7 @@ array<System::String ^> ^ AutomationBridge::enumWindowInfo(System::IntPtr window
AutomationElement ^element = AutomationElement::FromHandle(windowHandle);
List<System::String ^> ^winInfoList = gcnew List<System::String ^>();
if (!isElementFiltered(element)) //test parent should be filtered
winInfoList->Add(getWindowInfo(element, properties));
winInfoList->Add(getWindowInfo(element, properties, nullptr));
winInfoList->AddRange(enumWindowInfo(element, properties));
return winInfoList->ToArray();
}
@@ -255,25 +266,16 @@ array<System::String ^> ^ AutomationBridge::enumWindowInfo(AutomationElement ^el
return enumWindowInfo(element, properties, filterModifierList);
}
array<System::String ^> ^ AutomationBridge::enumWindowInfo(AutomationElement ^element, System::String ^properties, List<System::String ^> ^filterModifierList)
array<System::String ^> ^ AutomationBridge::enumWindowInfo(AutomationElement ^parentElement, System::String ^properties, List<System::String ^> ^filterModifierList)
{
List<System::String ^> ^winInfoList = gcnew List<System::String ^>();
if (element == nullptr)
if (parentElement == nullptr)
return winInfoList->ToArray();
TreeWalker ^tw = TreeWalker::RawViewWalker;
//System::Console::WriteLine("get info: {0}", getWindowInfo(element, properties));
//AutomationElement ^currentElement = tw->GetFirstChild(element, cacheRequest);
AutomationElement ^currentElement = nullptr;
/*if (element->CachedChildren != nullptr)
{
System::Console::WriteLine("using cached child");
currentElement = element->CachedChildren[0];
}
else*/
{
//System::Console::WriteLine("not cached child");
currentElement = tw->GetFirstChild(element, cacheRequest);
}
currentElement = tw->GetFirstChild(parentElement, cacheRequest);
if (currentElement == nullptr)
{
//System::Console::WriteLine("no children {0}", element->CachedChildren->Count);
@@ -292,7 +294,7 @@ array<System::String ^> ^ AutomationBridge::enumWindowInfo(AutomationElement ^el
Boolean modifierChanged = fmlOriginalSize != filterModifierList->Count;
if (!filtered) //not filtered so return element
{
winInfoList->Add(getWindowInfo(currentElement, properties));
winInfoList->Add(getWindowInfo(currentElement, properties, parentElement));
winInfoList->AddRange(enumWindowInfo(currentElement, properties, filterModifierList));
}
else //filtered, but if modifier used keep searching children
@@ -303,16 +305,16 @@ array<System::String ^> ^ AutomationBridge::enumWindowInfo(AutomationElement ^el
processFilterModifier(filtered, modifierChanged, filterModifierList); //cleans filterModifierList
//System::Console::WriteLine("element: {0}", currentElement);
//currentElement->
currentElement = tw->GetNextSibling(currentElement, cacheRequest);
} catch (Exception ^ex)
{
System::Console::WriteLine("Exception: {0} {1}", ex->Message, ex->StackTrace);
}
currentElement = tw->GetNextSibling(currentElement, cacheRequest);
}
return winInfoList->ToArray();
}
System::String ^ AutomationBridge::getWindowInfo(AutomationElement ^element, System::String ^properties)
System::String ^ AutomationBridge::getWindowInfo(AutomationElement ^element, System::String ^properties, AutomationElement ^optionalParentElement)
{
System::String ^resultProperties = L"";
System::String ^propertyNameErrorCheck = L"";
@@ -323,16 +325,28 @@ System::String ^ AutomationBridge::getWindowInfo(AutomationElement ^element, Sys
if (properties->Equals(L"*"))
wildcardEnabled = true;
//setup parentElement
System::String ^parentRuntimeId = L"";
if (wildcardEnabled || properties->Contains(L"ParentRuntimeIdProperty"))
{
if (optionalParentElement == nullptr)
{
TreeWalker ^tw = TreeWalker::ControlViewWalker;
parentRuntimeId = getRuntimeIdFromElement(tw->GetParent(element, cacheRequest));
}
else
parentRuntimeId = getRuntimeIdFromElement(optionalParentElement);
}
//create array for keeping order of properties
System::String ^delim = L",";
array<System::String ^> ^propSpltArray = properties->Split(delim->ToCharArray());
TreeWalker ^tw = TreeWalker::ControlViewWalker;
System::Int32 count = 0;
array<AutomationProperty^> ^aps = cachedRootProperties;//element->GetSupportedProperties();
array<System::String ^> ^propValues = gcnew array<System::String ^>(propSpltArray->Length);//keep order
System::String ^wildcardProperties = L"";
if (wildcardEnabled) {
wildcardProperties += "ParentRuntimeIdProperty:" + getRuntimeIdFromElement(tw->GetParent(element, cacheRequest)) + ",";
wildcardProperties += "ParentRuntimeIdProperty:" + parentRuntimeId + ",";
//propValues = gcnew array<System::String ^>(aps->Length +1 );//add one for parent property since it doesn't exist
}
for(int i=0 ; i < propValues->Length ; i++)
@@ -340,7 +354,7 @@ System::String ^ AutomationBridge::getWindowInfo(AutomationElement ^element, Sys
propValues[i] = L"";
if (propSpltArray[i]->Equals("ParentRuntimeIdProperty"))//custom property for getting parent
{
propValues[i] = getRuntimeIdFromElement(tw->GetParent(element, cacheRequest));
propValues[i] = parentRuntimeId;
}
}
for each(AutomationProperty ^ap in aps) //loop through all supported Properties for a child
@@ -404,13 +418,13 @@ System::String ^ AutomationBridge::getWindowInfo(AutomationElement ^element, Sys
System::String ^ AutomationBridge::getWindowInfo(System::Int32 x, System::Int32 y, System::String ^properties)
{
AutomationElement ^element = AutomationElement::FromPoint(System::Windows::Point(x, y));
return getWindowInfo(element, properties);
return getWindowInfo(element, properties, nullptr);
}
System::String ^ AutomationBridge::getWindowInfo(System::IntPtr windowHandle, System::String ^properties)
{
AutomationElement ^element = AutomationElement::FromHandle(windowHandle);
return getWindowInfo(element, properties);
return getWindowInfo(element, properties, nullptr);
}
System::String ^ AutomationBridge::getWindowInfo(System::String ^runtimeIdStr, System::String ^properties)

View File

@@ -18,6 +18,7 @@ namespace uiabridge {
{
public:
AutomationBridge(void);
AutomationBridge(System::String ^cachedProperties);
~AutomationBridge();
int addEnumFilter(System::String ^propertyName, System::String ^propertyValue);
void clearEnumFilters();
@@ -28,7 +29,7 @@ namespace uiabridge {
array<System::String ^> ^ enumWindowInfo(System::IntPtr windowHandle, System::String ^properties);
array<System::String ^> ^ enumWindowInfo(AutomationElement ^element, System::String ^properties);
array<System::String ^> ^ enumWindowInfo(AutomationElement ^element, System::String ^properties, List<System::String ^> ^filterModifierList);
System::String ^ getWindowInfo(AutomationElement ^element, System::String ^properties);
System::String ^ getWindowInfo(AutomationElement ^element, System::String ^properties, AutomationElement ^optionalParentElement);
System::String ^ getWindowInfo(System::Int32 x, System::Int32 y, System::String ^properties);
System::String ^ getWindowInfo(System::IntPtr windowHandle, System::String ^properties);
System::String ^ getWindowInfo(System::String ^runtimeIdStr, System::String ^properties);
@@ -36,8 +37,9 @@ namespace uiabridge {
static System::String ^ALL_MODIFIER = L"All";// find all matching elements of this filter
static System::String ^PARENT_MODIFIER = L"Parent";//find all children of this matching parent filter
static System::String ^FIRST_MODIFIER = L"First"; //find first element matching this filter then stop
static System::String ^DEFAULT_CACHED_PROPS = L"RuntimeIdProperty,ParentRuntimeIdProperty,NativeWindowHandleProperty,ProcessIdProperty,FrameworkIdProperty,LocalizedControlTypeProperty,ControlTypeProperty,ClassNameProperty,NameProperty,BoundingRectangleProperty,ValueProperty";
private:
void initializeCache();
void initializeCache(System::String ^cachedProperties);
Dictionary<System::String ^, System::String ^> ^enumFilters;
void AutomationBridge::processFilterModifier(Boolean filtered, Boolean modifierChanged, List<System::String ^> ^filterModifierList);
CacheRequest ^cacheRequest;

Binary file not shown.

Binary file not shown.

View File

@@ -25,32 +25,67 @@ void outputResults(array<System::String ^> ^winInfo)
}
void runBasicTests(AutomationBridge ^ab, System::String ^propList)
{
array<System::String ^> ^winInfo = nullptr;
System::DateTime start;
System::Double seconds = 0;
start = System::DateTime::Now;
ab->clearEnumFilters();
ab->addEnumFilter("Parent/FrameworkIdProperty", "WinForm");
winInfo = ab->enumWindowInfo(propList);
//outputResults(winInfo);
seconds = System::Math::Round(System::DateTime::Now.Subtract(start).TotalSeconds, 4);
Console::WriteLine(L"Total WinForm Elements: {0} in {1} seconds", winInfo->Length, seconds);
start = System::DateTime::Now;
ab->clearEnumFilters();
ab->addEnumFilter("Parent/FrameworkIdProperty", "WPF");
winInfo = ab->enumWindowInfo(propList);
//outputResults(winInfo);
seconds = System::Math::Round(System::DateTime::Now.Subtract(start).TotalSeconds, 4);
Console::WriteLine(L"Total WPF Elements: {0} in {1} seconds", winInfo->Length, seconds);
start = System::DateTime::Now;
ab->clearEnumFilters();
winInfo = ab->enumWindowInfo(propList);
//outputResults(winInfo);
seconds = System::Math::Round(System::DateTime::Now.Subtract(start).TotalSeconds, 4);
Console::WriteLine(L"Total All Elements: {0} in {1} seconds", winInfo->Length, seconds);
Console::WriteLine(L"---------------------------------------");
}
int main(array<System::String ^> ^args)
{
Console::WriteLine(L"UI Automation Bridge Test");
AutomationBridge ^ab = gcnew AutomationBridge();
System::String ^propList = L"RuntimeIdProperty,ParentRuntimeIdProperty,NativeWindowHandleProperty,ProcessIdProperty,FrameworkIdProperty,LocalizedControlTypeProperty,ClassNameProperty,NameProperty";
//System::String ^propList = L"RuntimeIdProperty,ProcessIdProperty,FrameworkIdProperty,LocalizedControlTypeProperty,ClassNameProperty,NameProperty";
System::String ^propList = L"RuntimeIdProperty,ParentRuntimeIdProperty,NativeWindowHandleProperty,ProcessIdProperty,FrameworkIdProperty,LocalizedControlTypeProperty,ControlTypeProperty,ClassNameProperty,NameProperty,BoundingRectangleProperty";
AutomationBridge ^ab = gcnew AutomationBridge(propList);
//System::String ^propList = L"RuntimeIdProperty,BoundingRectangleProperty";
Console::WriteLine(propList);
//System::String ^winInfo1 = ab->getWindowInfo(System::IntPtr(3409618), propList);
System::DateTime start = System::DateTime::Now;
runBasicTests(ab, propList);
runBasicTests(ab, propList);
runBasicTests(ab, propList);
//System::String ^winInfo1 = ab->getWindowInfo(System::IntPtr(3409618), propList);
//ab->addEnumFilter("Parent/ClassNameProperty", "Notepad");
//ab->addEnumFilter("First/RuntimeIdProperty", "42-4784952");
//ab->addEnumFilter("ClassNameProperty", "Notepad");
//ab->addEnumFilter("All/ClassNameProperty", "Edit");
//ab->addEnumFilter("All/LocalizedControlTypeProperty", "menu item");
ab->addEnumFilter("Parent/FrameworkIdProperty", "WinForm");
//ab->addEnumFilter("Parent/FrameworkIdProperty", "WinForm");
//ab->addEnumFilter("Parent/FrameworkIdProperty", "WPF");
//ab->addEnumFilter("Parent/ClassNameProperty", "WindowsForms10.Window.8.app.0.2bf8098_r13_ad1");
array<System::String ^> ^winInfo = ab->enumWindowInfo(propList); //L"*"
//array<System::String ^> ^winInfo = ab->enumWindowInfo(propList); //L"*"
//ab->clearEnumFilters();
//ab->addEnumFilter("Parent/FrameworkIdProperty", "WinForm");
//array<System::String ^> ^winInfo = ab->enumWindowInfo(System::IntPtr(3409618), propList); //L"*"
//array<System::String ^> ^winInfo = ab->enumWindowInfo(System::IntPtr(12977932), propList); //L"*"
//Console::WriteLine("enumWindowInfo x,y: {0}", ab->getWindowInfo(100,100, propList); //L"*"
outputResults(winInfo);
//outputResults(winInfo);
//Globals::Global::AUTO_BRIDGE->clearEnumFilters();
//winInfo = nullptr;
//winInfo = Globals::Global::AUTO_BRIDGE->enumWindowInfo(System::IntPtr(7603636), propList);
@@ -64,8 +99,9 @@ int main(array<System::String ^> ^args)
//array<System::String ^> ^winInfo2 = ab->enumWindowInfo(propList); //L"*"
//outputResults(winInfo2);
System::Double seconds = System::Math::Round(System::DateTime::Now.Subtract(start).TotalSeconds, 4);
Console::WriteLine(L"Total Elements: {0} in {1} seconds", winInfo->Length, seconds);
//System::Double seconds = System::Math::Round(System::DateTime::Now.Subtract(start).TotalSeconds, 4);
//Console::WriteLine(L"Total Elements: {0} in {1} seconds", winInfo->Length, seconds);
Console::WriteLine(L"press any key to exit");
getch();//wait for user input
return 0;
}