TAPs now also accept string as atspi object to tap on 81/205581/3
authorRadoslaw Cybulski <r.cybulski@partner.samsung.com>
Tue, 7 May 2019 14:17:30 +0000 (16:17 +0200)
committerRadoslaw Cybulski <r.cybulski@partner.samsung.com>
Thu, 16 May 2019 09:31:20 +0000 (11:31 +0200)
Change-Id: Ie477d1f858c00fe4d0818d70b4a07c2e71b9a5ca

src/batch/BatchRunner.cpp
src/batch/BatchRunner.hpp

index fb0d4b6..bc0f0f0 100644 (file)
@@ -543,6 +543,10 @@ void BatchExecutor::insertMethods()
                                auto root = getVisibleRoot();
                                if (!root) throw EvaluationFailure{} << "no visible root (context changed didn't happen)";
                                ASSERT(root->getObject());
+                               if (target.isString())
+                               {
+                                       target = this->convertToUIElement(target.convertToString());
+                               }
                                auto dest = target.convertToUIElement();
 
                                auto sleep_until = std::chrono::high_resolution_clock::now() + std::chrono::milliseconds{ 400 };
@@ -701,58 +705,60 @@ void BatchExecutor::insertWaits()
        variables["gui"] = EvaluationValueFunction{ std::move(waitGui), { { "name", "" }, { "timeout", 5.0 } } };
 }
 
+void BatchExecutor::callActivity(const std::string &activityName, const EvaluationValueFunction::Args &args)
+{
+       auto activity = executeOnMainThread([&]() {
+               return ActivityFactory::getInstance()->createActivity(activityName);
+       });
+       if (!activity)
+               throw EvaluationFailure{} << "failed to construct '" << activityName << "' activity";
+       auto numOfArgs = activity->getRequiredNumberOfArgumentsIfAllowedInBatchProcessing();
+       if (!numOfArgs)
+               throw EvaluationFailure{} << "activity '" << activityName << "' is not supported";
+       if (*numOfArgs != args.size())
+               throw EvaluationFailure{} << "invalid number of arguments for activity '" << activityName <<
+                                                                 "', got " << args.size() << ", expected " << *numOfArgs;
+       auto uiActivity = std::dynamic_pointer_cast<UIActivity>(activity);
+
+       // activity must inherit from UIActivity if it returns non zero expected arguments
+       ASSERT(args.empty() || uiActivity);
+
+       std::vector<std::shared_ptr<UIElement>> uiArgs(args.size());
+       for (size_t i = 0; i < args.size(); ++i) {
+               ASSERT(uiActivity);
+               uiArgs[i] = args[i].convertToUIElement();
+               if (!uiArgs[i])
+                       throw EvaluationFailure{} << "can't convert argument " << (i + 1) <<
+                                                                         " of kind " << args[i].typeName() << " to UIElement";
+       }
+       Monitor<BatchValueOrError<bool>> monitor;
+       {
+               executeOnMainThread([&]() {
+                       DEBUG("calling activity %s", activityName.c_str());
+                       for (auto &arg : uiArgs) {
+                               ASSERT(uiActivity);
+                               uiActivity->update(std::move(arg));
+                       }
+                       activity->process(DoneCallback{ [ = ] {
+                                       auto h = monitor.lock();
+                                       h->setValue(true);
+                               } });
+                       DEBUG("calling activity %s done", activityName.c_str());
+               }, monitor);
+               if (!activity->isCompleted())
+                       throw EvaluationFailure{} << "activity '" << activityName << "' is not marked as completed!";
+               auto h = monitor.lock();
+               ASSERT(*h); // sanity check, must be set, otherwise an exception was thrown
+       }
+}
+
 void BatchExecutor::insertActivities()
 {
        for (auto activityName : ActivityFactory::getInstance()->getAllActivityTypes()) {
                if (variables.find(activityName) != variables.end())
                        continue;
                variables[activityName] = [ = ](EvaluationValueFunction::Args args) -> EvaluationValue {
-                       auto activity = executeOnMainThread([&]()
-                       {
-                               return ActivityFactory::getInstance()->createActivity(activityName);
-                       });
-                       if (!activity)
-                               throw EvaluationFailure{} << "failed to construct '" << activityName << "' activity";
-                       auto numOfArgs = activity->getRequiredNumberOfArgumentsIfAllowedInBatchProcessing();
-                       if (!numOfArgs)
-                               throw EvaluationFailure{} << "activity '" << activityName << "' is not supported";
-                       if (*numOfArgs != args.size())
-                               throw EvaluationFailure{} << "invalid number of arguments for activity '" << activityName <<
-                                                                         "', got " << args.size() << ", expected " << *numOfArgs;
-                       auto uiActivity = std::dynamic_pointer_cast<UIActivity>(activity);
-
-                       // activity must inherit from UIActivity if it returns non zero expected arguments
-                       ASSERT(args.empty() || uiActivity);
-
-                       std::vector<std::shared_ptr<UIElement>> uiArgs(args.size());
-                       for (size_t i = 0; i < args.size(); ++i)
-                       {
-                               ASSERT(uiActivity);
-                               uiArgs[i] = args[i].convertToUIElement();
-                               if (!uiArgs[i])
-                                       throw EvaluationFailure{} << "can't convert argument " << (i + 1) <<
-                                                                                 " of kind " << args[i].typeName() << " to UIElement";
-                       }
-                       Monitor<BatchValueOrError<bool>> monitor;
-                       {
-                               executeOnMainThread([&]()
-                               {
-                                       DEBUG("calling activity %s", activityName.c_str());
-                                       for (auto &arg : uiArgs) {
-                                               ASSERT(uiActivity);
-                                               uiActivity->update(std::move(arg));
-                                       }
-                                       activity->process(DoneCallback{ [ = ] {
-                                                       auto h = monitor.lock();
-                                                       h->setValue(true);
-                                               } });
-                                       DEBUG("calling activity %s done", activityName.c_str());
-                               }, monitor);
-                               if (!activity->isCompleted())
-                                       throw EvaluationFailure{} << "activity '" << activityName << "' is not marked as completed!";
-                               auto h = monitor.lock();
-                               ASSERT(*h); // sanity check, must be set, otherwise an exception was thrown
-                       }
+                       callActivity(activityName, args);
                        return {};
                };
        }
index 7e8c11c..91d1cd6 100644 (file)
@@ -99,6 +99,7 @@ protected:
        void insertStateConstants();
        void insertRoleConstants();
 
+       void callActivity(const std::string &activityName, const EvaluationValueFunction::Args &args);
        void findByName(const std::vector<AtspiAccessiblePtr> &elems, std::string requestedName, std::function<void(DBus::ValueOrError<std::vector<AtspiAccessiblePtr>>)> callback);
        void getAllObjects(AtspiAccessiblePtr root, std::function<void(DBus::ValueOrError<std::vector<AtspiAccessiblePtr>>)> callback,
                                           std::vector<int> roles = {}, std::vector<int> states = {});