Kaydet (Commit) 26ee34d1 authored tarafından Markus Mohrhard's avatar Markus Mohrhard

uitest: add logging for UI actions

The long term goal for this logging is that it generates content in a
DSL for the UI testing. The generated file can then be interpreted by
the UI testing and replay the interaction with the UI.

For now the plan is to have a readable output of what happens in the UI
layer that allows to quickly transform it to a UI test.

Change-Id: Ic536db766e41d03d048c920f6d551047af6fbb74
Reviewed-on: https://gerrit.libreoffice.org/35447Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMarkus Mohrhard <markus.mohrhard@googlemail.com>
üst 2356bfdb
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <vcl/dllapi.h>
#include <tools/stream.hxx>
#include <vcl/ctrl.hxx>
class UITEST_DLLPUBLIC UITestLogger
{
private:
SvFileStream maStream;
bool mbValid;
public:
UITestLogger();
void logCommand(const OUString& rAction);
void logAction(VclPtr<Control>& xUIElement, VclEventId nEvent);
void log(const OUString& rString);
static UITestLogger& getInstance();
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -92,6 +92,11 @@ public:
*
*/
virtual OUString dumpHierarchy() const;
/**
* Gets the corresponding Action string for the event.
*/
virtual OUString get_action(VclEventId nEvent) const;
};
class UITEST_DLLPUBLIC WindowUIObject : public UIObject
......@@ -117,6 +122,8 @@ public:
virtual OUString dumpHierarchy() const override;
virtual OUString get_action(VclEventId nEvent) const override;
static std::unique_ptr<UIObject> create(vcl::Window* pWindow);
protected:
......
......@@ -393,6 +393,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
vcl/source/fontsubset/sft \
vcl/source/fontsubset/ttcr \
vcl/source/fontsubset/xlat \
vcl/source/uitest/logger \
vcl/source/uitest/uiobject \
vcl/source/uitest/uitest \
vcl/source/uitest/uno/uiobject_uno \
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <config_folders.h>
#include <vcl/uitest/logger.hxx>
#include <rtl/bootstrap.hxx>
#include <osl/file.hxx>
#include <vcl/uitest/uiobject.hxx>
#include <memory>
UITestLogger::UITestLogger():
maStream(),
mbValid(false)
{
static const char* pFile = std::getenv("LO_COLLECT_UIINFO");
if (pFile)
{
OUString aDirPath("${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("bootstrap") ":UserInstallation}/uitest/");
rtl::Bootstrap::expandMacros(aDirPath);
osl::Directory::createPath(aDirPath);
OUString aFilePath = aDirPath + OUString::fromUtf8(pFile);
maStream.Open(aFilePath, StreamMode::READWRITE);
mbValid = true;
}
}
void UITestLogger::logCommand(const OUString& rAction)
{
if (!mbValid)
return;
maStream.WriteLine(OUStringToOString(rAction, RTL_TEXTENCODING_UTF8));
}
void UITestLogger::logAction(VclPtr<Control>& xUIElement, VclEventId nEvent)
{
if (!mbValid)
return;
if (xUIElement->get_id().isEmpty())
return;
std::unique_ptr<UIObject> pUIObject = xUIElement->GetUITestFactory()(xUIElement.get());
OUString aAction = pUIObject->get_action(nEvent);
if (!aAction.isEmpty())
maStream.WriteLine(OUStringToOString(aAction, RTL_TEXTENCODING_UTF8));
}
void UITestLogger::log(const OUString& rString)
{
if (!mbValid)
return;
if (rString.isEmpty())
return;
maStream.WriteLine(OUStringToOString(rString, RTL_TEXTENCODING_UTF8));
}
UITestLogger& UITestLogger::getInstance()
{
static UITestLogger aInstance;
return aInstance;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -69,6 +69,11 @@ OUString UIObject::dumpHierarchy() const
return OUString();
}
OUString UIObject::get_action(VclEventId /*nEvent*/) const
{
return OUString();
}
namespace {
bool isDialogWindow(vcl::Window* pWindow)
......@@ -471,6 +476,31 @@ OUString WindowUIObject::dumpHierarchy() const
return pParentWrapper->dumpState();
}
OUString WindowUIObject::get_action(VclEventId nEvent) const
{
OUString aActionName;
switch (nEvent)
{
case VclEventId::ControlGetFocus:
case VclEventId::ControlLoseFocus:
return OUString();
case VclEventId::ButtonClick:
case VclEventId::CheckboxToggle:
aActionName = "CLICK";
break;
case VclEventId::EditModify:
aActionName = "TYPE";
break;
default:
aActionName = OUString::number(static_cast<int>(nEvent));
}
return "Action on element: " + mxWindow->get_id() + " with action : " + aActionName;
}
std::unique_ptr<UIObject> WindowUIObject::create(vcl::Window* pWindow)
{
return std::unique_ptr<UIObject>(new WindowUIObject(pWindow));
......
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