Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better Filter on Path (Text, Type and Property) #107

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
add_subdirectory(Basic)
add_subdirectory(GTest)
add_subdirectory(GTestTypeFinder)
add_subdirectory(ListGridView)
add_subdirectory(RemoteCtrl)
add_subdirectory(RepeaterLoader)
44 changes: 44 additions & 0 deletions examples/GTest/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,51 @@ Button 1 clicked
Button 1 right clicked)RSLT";

EXPECT_EQ(result, expected_result);
}

TEST(GTestExample, SearchText)
{
// Clean Output
srv->setStringProperty("mainWindow/results", "text", "");
srv->wait(std::chrono::milliseconds(500));
// Look for a Text "Press Me"
srv->mouseClick(spix::ItemPath("mainWindow/\"Press Me\""));
srv->wait(std::chrono::milliseconds(500));

auto result = srv->getStringProperty("mainWindow/results", "text");
auto expected_result = R"RSLT(Button 1 clicked)RSLT";

EXPECT_EQ(result, expected_result);
}

TEST(GTestExample, SearchType)
{
// Clean Output
srv->setStringProperty("mainWindow/results", "text", "");
srv->wait(std::chrono::milliseconds(500));
// Serach for Type Button in the end of a Path
srv->mouseClick(spix::ItemPath("mainWindow/#Button"));
srv->wait(std::chrono::milliseconds(500));

auto result = srv->getStringProperty("mainWindow/results", "text");
auto expected_result = R"RSLT(Button 1 clicked)RSLT";

EXPECT_EQ(result, expected_result);
}

TEST(GTestExample, SearchTypeAndTextCombined)
{
// Clean Output
srv->setStringProperty("mainWindow/results", "text", "");
srv->wait(std::chrono::milliseconds(500));
// Search for Type in the center of a Path
srv->mouseClick(spix::ItemPath("mainWindow/#Rectangle/\"Or Click Me\""));
srv->wait(std::chrono::milliseconds(500));

auto result = srv->getStringProperty("mainWindow/results", "text");
auto expected_result = R"RSLT(Button 2 clicked)RSLT";

EXPECT_EQ(result, expected_result);
srv->quit();
}

Expand Down
35 changes: 20 additions & 15 deletions examples/GTest/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,26 @@ Window {
}
}
}
Button {
objectName: "Button_2"
text: "Or Click Me"
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.AllButtons

onClicked:
{
if(mouse.button & Qt.RightButton)
resultsView.appendText("Button 2 right clicked")
else
resultsView.appendText("Button 2 clicked")
}
}
Rectangle {
width: 100
height: 100
color: "red"
Button {
objectName: "Button_2"
text: "Or Click Me"
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.AllButtons

onClicked:
{
if(mouse.button & Qt.RightButton)
resultsView.appendText("Button 2 right clicked")
else
resultsView.appendText("Button 2 clicked")
}
}
}
}
}

Expand Down
14 changes: 14 additions & 0 deletions examples/GTestTypeFinder/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(SPIX_QT_MAJOR "6" CACHE STRING "Major Qt version to build Spix against")

find_package(Qt${SPIX_QT_MAJOR} COMPONENTS Core Quick REQUIRED)
find_package(GTest REQUIRED)

add_executable(SpixGTestTypeFinder "main.cpp" "qml.qrc")
target_compile_definitions(SpixGTestTypeFinder PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
target_link_libraries(SpixGTestTypeFinder PRIVATE Qt${SPIX_QT_MAJOR}::Core Qt${SPIX_QT_MAJOR}::Quick GTest::GTest Spix)
43 changes: 43 additions & 0 deletions examples/GTestTypeFinder/ResultsView.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import QtQuick 2.11
import QtQuick.Controls 2.4

Rectangle {
id: resultsView
color: "#222222"

function appendText(text) {
resultsArea.append(text);
}

Text {
id: resultsTitle
text: "Result: "
color: "white"
font.bold: true

anchors {
top: resultsView.top
left: resultsView.left
right: resultsView.right

topMargin: 5
leftMargin: 2
bottomMargin: 2
}
}
TextEdit {
id: resultsArea
objectName: "results"
color: "white"
anchors {
top: resultsTitle.bottom
left: resultsView.left
right: resultsView.right
bottom: resultsView.bottom

leftMargin: 2
rightMargin: 2
bottomMargin: 2
}
}
}
171 changes: 171 additions & 0 deletions examples/GTestTypeFinder/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
/***
* Copyright (C) Falko Axmann. All rights reserved.
* Licensed under the MIT license.
* See LICENSE.txt file in the project root for full license information.
****/

/**
* This is a very basic example to demonstrate how to run your UI tests
* using GTest. It can be useful when you have to make sure that your
* UI tests work well in an existing, GTest based environment.
*
* Keep in mind that GTest is not designed for UI testing and that the
* order of the test execution is not guaranteed. Thus, you should only
* have one test per executable.
*/

#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <Spix/Events/Identifiers.h>
#include <Spix/QtQmlBot.h>

#include <atomic>
#include <gtest/gtest.h>

class SpixGTest;
static SpixGTest* srv;

class SpixGTest : public spix::TestServer {
public:
SpixGTest(int argc, char* argv[])
{
m_argc = argc;
m_argv = argv;
}

int testResult() { return m_result.load(); }

protected:
int m_argc;
char** m_argv;
std::atomic<int> m_result {0};

void executeTest() override
{
srv = this;
::testing::InitGoogleTest(&m_argc, m_argv);
auto testResult = RUN_ALL_TESTS();
m_result.store(testResult);
}
};

TEST(GTestExample, SearchTypeCentre)
{
// Search for mutible Types in a Path
srv->mouseClick(spix::ItemPath("mainWindow/#Rectangle/#Rectangle/#Rectangle/\"Click Me\""));
srv->wait(std::chrono::milliseconds(500));

auto result = srv->getStringProperty("mainWindow/results", "text");
auto expected_result = R"RSLT(Button 2 clicked)RSLT";

EXPECT_EQ(result, expected_result);
}

TEST(GTestExample, SearchTypeCentreShortened)
{
// Clean Output
srv->setStringProperty("mainWindow/results", "text", "");
srv->wait(std::chrono::milliseconds(500));
// Search for mutible Types in a Path
srv->mouseClick(spix::ItemPath("mainWindow/#Rectangle/#Rectangle/\"Click Me\""));
srv->wait(std::chrono::milliseconds(500));

auto result = srv->getStringProperty("mainWindow/results", "text");
auto expected_result = R"RSLT(Button 2 clicked)RSLT";

EXPECT_EQ(result, expected_result);
}

TEST(GTestExample, SearchWrongText)
{
// Clean Output
srv->setStringProperty("mainWindow/results", "text", "No Click");
srv->wait(std::chrono::milliseconds(500));
// Search for mutible Types in a Path
srv->mouseClick(spix::ItemPath("mainWindow/#Rectangle/#Rectangle\"Not on the Screen\""));
srv->wait(std::chrono::milliseconds(500));

auto result = srv->getStringProperty("mainWindow/results", "text");
auto expected_result = R"RSLT(No Click)RSLT";

EXPECT_EQ(result, expected_result);
}

TEST(GTestExample, SearchTypeInTwoReacts)
{
// Clean Output
srv->setStringProperty("mainWindow/results", "text", "");
srv->wait(std::chrono::milliseconds(500));
// Search for mutible Types in a Path
srv->mouseClick(spix::ItemPath("mainWindow/#Rectangle/#Rectangle/\"Click Me\""));
srv->wait(std::chrono::milliseconds(500));

auto result = srv->getStringProperty("mainWindow/results", "text");
auto expected_result = R"RSLT(Button 2 clicked)RSLT";

EXPECT_EQ(result, expected_result);
}

TEST(GTestExample, SearchTypeInTwoReactsWithWrongButton)
{
// Clean Output
srv->setStringProperty("mainWindow/results", "text", "No Click");
srv->wait(std::chrono::milliseconds(500));
// Search for mutible Types in a Path
srv->mouseClick(spix::ItemPath("mainWindow/#Rectangle/#Rectangle/\"Click You\""));
srv->wait(std::chrono::milliseconds(500));

auto result = srv->getStringProperty("mainWindow/results", "text");
auto expected_result = R"RSLT(No Click)RSLT";

EXPECT_EQ(result, expected_result);
}

TEST(GTestExample, SearchTypeCentreFirstButton)
{
// Clean Output
srv->setStringProperty("mainWindow/results", "text", "");
srv->wait(std::chrono::milliseconds(500));
// Search for mutible Types in a Path
srv->mouseClick(spix::ItemPath("mainWindow/#Rectangle/\"Click Me\""));
srv->wait(std::chrono::milliseconds(500));

auto result = srv->getStringProperty("mainWindow/results", "text");
auto expected_result = R"RSLT(Button 1 clicked)RSLT";

EXPECT_EQ(result, expected_result);
}

TEST(GTestExample, SearchTypeToManyRectangles)
{
// Clean Output
srv->setStringProperty("mainWindow/results", "text", "No Click");
srv->wait(std::chrono::milliseconds(500));
// Search for mutible Types in a Path
srv->mouseClick(spix::ItemPath("mainWindow/#Rectangle/#Rectangle/#Rectangle/#Rectangle"));
srv->wait(std::chrono::milliseconds(500));

auto result = srv->getStringProperty("mainWindow/results", "text");
auto expected_result = R"RSLT(No Click)RSLT";

EXPECT_EQ(result, expected_result);
srv->quit();
}

int main(int argc, char* argv[])
{
// Init Qt Qml Application
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;

// Instantiate and run tests
SpixGTest tests(argc, argv);
auto bot = new spix::QtQmlBot();
bot->runTestServer(tests);

app.exec();
return tests.testResult();
}
Loading
Loading