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

Create gui tests environment #3226

Open
wants to merge 6 commits into
base: develop
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2019 EPAM Systems, Inc. (https://www.epam.com/)
* Copyright 2017-2023 EPAM Systems, Inc. (https://www.epam.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,11 +15,71 @@
*/
package com.epam.pipeline.autotests;

import static com.codeborne.selenide.Condition.visible;
import com.codeborne.selenide.ElementsCollection;
import static com.codeborne.selenide.Selectors.byClassName;
import static com.codeborne.selenide.Selectors.byId;
import static com.codeborne.selenide.Selectors.byText;
import com.epam.pipeline.autotests.mixins.Authorization;
import com.epam.pipeline.autotests.mixins.Navigation;
import static com.epam.pipeline.autotests.utils.Utils.readResourceFully;
import static com.epam.pipeline.autotests.utils.Utils.writeTempJsonFile;
import org.testng.annotations.Test;
import static com.codeborne.selenide.Selenide.$;

public class PrerequisitesTest extends AbstractBfxPipelineTest implements Navigation {
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class PrerequisitesTest extends AbstractBfxPipelineTest implements Navigation, Authorization {
private static final String uiRunsFiltersJsonInitial = "uiRunsFiltersInitial.json";
private static final String uiRunsFiltersJson = "/uiRunsFilters.json";

@Test
public void prerequisitesTest() {}

@Test
public void muteTestUsersNotifications() {
Stream.of(admin, user, userWithoutCompletedRuns)
.forEach(user -> {
logout();
loginAs(user);
closeNotificationIfNeeded();
navigationMenu()
.settings()
.switchToMyProfile()
.validateUserName(user.login)
.muteEmailNotificationsSelect(true);
});
}

@Test
public void setUiRunsFilters() {
logoutIfNeeded();
loginAs(admin);
String[] json = navigationMenu()
.settings()
.switchToPreferences()
.getPreference("ui.runs.filters");
writeTempJsonFile(uiRunsFiltersJsonInitial, json[0]);
navigationMenu()
.settings()
.switchToPreferences()
.updateCodeText("ui.runs.filters",
readResourceFully(uiRunsFiltersJson), true)
.saveIfNeeded();
}

private void closeNotificationIfNeeded() {
if ($(byId("notification-center"))
.find(byText("hide")).is(visible)) {
$(byId("notification-center"))
.find(byText("hide")).click();
} else {
ElementsCollection list = $(byId("notification-center"))
.findAll(byClassName("cp-notification"))
.filterBy(visible);
IntStream.range(0, list.size()).forEach(i ->
list.get(i).$(byId("notification-close-button")).click());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2017-2023 EPAM Systems, Inc. (https://www.epam.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.epam.pipeline.autotests;

import com.epam.pipeline.autotests.mixins.Authorization;
import com.epam.pipeline.autotests.mixins.Navigation;
import com.epam.pipeline.autotests.utils.C;
import static java.lang.String.format;
import org.apache.commons.lang3.StringUtils;
import org.testng.annotations.Test;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

public class RestorePreferencesTest extends AbstractBfxPipelineTest implements Navigation, Authorization {

private static final String uiRunsFiltersJsonInitial = format("%s/uiRunsFiltersInitial.json", C.DOWNLOAD_FOLDER);

@Test
public void restoreUiRunsFilters() {
logoutIfNeeded();
loginAs(admin);
try {
navigationMenu()
.settings()
.switchToPreferences()
.updateCodeText("ui.runs.filters",
StringUtils.join(Files.readAllLines(Paths.get(uiRunsFiltersJsonInitial)), "\n"), true)
.saveIfNeeded();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -322,5 +322,6 @@ public enum Primitive {
PROTOCOL,
REINDEX,
CONDITION,
SHOW_TIMINGS
SHOW_TIMINGS,
MUTE_EMAIL_NOTIFICATIONS
}
Original file line number Diff line number Diff line change
Expand Up @@ -1753,7 +1753,8 @@ public class MyProfileAO implements AccessObject<MyProfileAO> {
private final Map<Primitive,SelenideElement> elements = initialiseElements(
entry(USER_NAME, $(byClassName("rofile__header"))),
entry(LIMIT_MOUNTS, $(byClassName("limit-mounts-input__limit-mounts-input"))),
entry(DO_NOT_MOUNT_STORAGES, $(byXpath(".//span[.='Do not mount storages']/preceding-sibling::span")))
entry(DO_NOT_MOUNT_STORAGES, $(byXpath(".//span[.='Do not mount storages']/preceding-sibling::span"))),
entry(MUTE_EMAIL_NOTIFICATIONS, $(byXpath(".//span[.='Mute email notifications']/preceding-sibling::span")))
);

public MyProfileAO validateUserName(String user) {
Expand All @@ -1774,6 +1775,16 @@ public MyProfileAO doNotMountStoragesSelect(boolean isSelected) {
return this;
}

public MyProfileAO muteEmailNotificationsSelect(boolean isSelected) {
sleep(1, SECONDS);
if ((!get(MUTE_EMAIL_NOTIFICATIONS).has(cssClass("ant-checkbox-checked")) && isSelected) ||
(get(MUTE_EMAIL_NOTIFICATIONS).has(cssClass("ant-checkbox-checked")) && !isSelected)) {
click(MUTE_EMAIL_NOTIFICATIONS);
sleep(1, SECONDS);
}
return this;
}

public MyProfileAO assertDoNotMountStoragesIsNotChecked() {
get(DO_NOT_MOUNT_STORAGES).shouldNotHave(cssClass("ant-checkbox-checked"));
return this;
Expand Down
10 changes: 10 additions & 0 deletions e2e/gui/src/test/java/com/epam/pipeline/autotests/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,16 @@ public static File createFileAndFillWithString(String name,
return file;
}

public static File writeTempJsonFile(String name, String content) {
Path path = Paths.get(C.DOWNLOAD_FOLDER).resolve(name);
try {
Files.write(path, content.getBytes());
} catch (IOException e) {
e.printStackTrace();
}
return path.toFile();
}

private static String repeatString(String str, int times) {
return new String(new char[times]).replace("\0", str);
}
Expand Down
37 changes: 37 additions & 0 deletions e2e/gui/src/test/resources/uiRunsFilters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[
{
"key": "active",
"title": "Active Runs",
"filters": {
"statuses": [
"RUNNING",
"PAUSED",
"PAUSING"
],
"onlyMasterJobs": false
},
"autoUpdate": true,
"showCount": true,
"showPersonalRuns": true
},
{
"key": "paused",
"filters": {
"statuses": [
"PAUSED"
]
},
"autoUpdate": true,
"showCount": true,
"showPersonalRuns": true
},
{
"key": "resuming",
"filters": {
"statuses": [
"RESUMING"
]
},
"autoUpdate": true
}
]
6 changes: 6 additions & 0 deletions e2e/gui/testng.xml
Original file line number Diff line number Diff line change
Expand Up @@ -537,4 +537,10 @@
<class name="com.epam.pipeline.autotests.RestrictionsOnInstancePriceTypeTest"/>
</classes>
</test>

<test name="RestorePreferencesTest">
<classes>
<class name="com.epam.pipeline.autotests.RestorePreferencesTest"/>
</classes>
</test>
</suite>