Skip to content

Commit

Permalink
Changes requested by Linter:
Browse files Browse the repository at this point in the history
- Not used imports
- Replace string concatenation with {}
- Replace <= lists with .empty method
  • Loading branch information
augustocristian committed Aug 20, 2024
1 parent 99eecd4 commit 197171d
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.slf4j.LoggerFactory;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
Expand Down Expand Up @@ -353,7 +352,6 @@ protected void waitForDialogClosed(String dialogId, String errorMessage,

protected void waitSeconds(int seconds) throws InterruptedException {
Thread.sleep(1000L * seconds);

}

public String getUserName(BrowserUser user, boolean goBack, String host) throws NotLoggedException, ElementNotFoundException {
Expand Down Expand Up @@ -383,9 +381,8 @@ public String getUserName(BrowserUser user, boolean goBack, String host) throws
}
//Check if the username is the expected
log.info("[END] getUserName");
return userNameTag;

return userNameTag;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public static WebDriver changeCourseName(WebDriver wd, String oldName, String ne
}

log.info("[END] changeCourseName OK");

return wd;
}
private static void openEditCourseModal(WebDriver wd, WebElement courseElement) throws ElementNotFoundException {
Expand Down Expand Up @@ -228,7 +229,7 @@ public static boolean isUserInAttendersList(WebDriver wd, String user_name) thro
getTabContent(wd, ATTENDERS_ICON);
Wait.notTooMuch(wd).until(ExpectedConditions.visibilityOfElementLocated(ATTENDERS_LIST_ROWS));
List<WebElement> attenders_lst = wd.findElements(ATTENDERS_LIST_ROWS);
if (attenders_lst.size() < 1) {
if (attenders_lst.isEmpty()) {
log.info("[END] isUserInAttendersList KO: attenders list is empty");
//TO-DO Check if can be replaced by a fail ("meessage")
throw new ElementNotFoundException("isUserInAttendersList - attenders list is empty");
Expand All @@ -248,7 +249,7 @@ public static String getHighlightedAttender(WebDriver wd) throws ElementNotFound
log.info("[INI] getHighlightedAttender");
WebElement attenders_content = getTabContent(wd, ATTENDERS_ICON);
List<WebElement> attender_highlighted = attenders_content.findElements(ATTENDERS_LIST_HIGHLIGHTED_ROW);
if (attender_highlighted == null || attender_highlighted.size() < 1) {
if (attender_highlighted == null || attender_highlighted.isEmpty()) {
log.info("[END] getHighlightedAttender KO: no highlighted user");
throw new ElementNotFoundException("getHighlightedAttender - no highlighted user");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@
import com.fullteaching.e2e.no_elastest.utils.Wait;
import giis.retorch.annotations.AccessMode;
import giis.retorch.annotations.Resource;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.openqa.selenium.By;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;
Expand Down Expand Up @@ -226,7 +224,7 @@ void forumNewCommentTest(String mail, String password, String role) throws NotLo
assertTrue(ForumNavigationUtilities.isForumEnabled(CourseNavigationUtilities.getTabContent(driver, FORUM_ICON)), "Forum not activated");//6lines
List<String> entries_list = ForumNavigationUtilities.getFullEntryList(driver);//6lines
WebElement entry;
if (entries_list.size() <= 0) {//if not new entry
if (entries_list.isEmpty()) {//if not new entry
String newEntryTitle = "New Comment Test " + mDay + mMonth + mYear + mHour + mMinute + mSecond;
String newEntryContent = "This is the content written on the " + mDay + " of " + months[mMonth - 1] + ", " + mHour + ":" + mMinute + "," + mSecond;
ForumNavigationUtilities.newEntry(driver, newEntryTitle, newEntryContent);//16lines
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

@ExtendWith(SeleniumJupiter.class)
class UserTest extends BaseLoggedTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void studentCourseMainTest(String userMail, String password, String role) throws
//go to first course
//get course list
List<String> course_list = CourseNavigationUtilities.getCoursesList(driver); //13 lines
if (course_list.size() <= 0) fail("No courses available for test user");
if (course_list.isEmpty()) fail("No courses available for test user");
WebElement course_button = CourseNavigationUtilities.getCourseByName(driver, course_list.get(0)).findElement(By.className("title")); //14 lines
Click.element(driver, course_button);
Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(By.id(COURSE_TABS_TAG)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void teacherEditCourseValues(String mail, String password, String role) throws N
//New Title
log.info("Adding the new description");
WebElement headerSelector = driver.findElement(By.className("ql-header"));
Click.element(driver, By.className("ql-header"));
Click.element(driver, headerSelector);
WebElement picker_options = Wait.notTooMuch(driver).until(ExpectedConditions.visibilityOfElementLocated(By.className("ql-picker-options")));
WebElement option = NavigationUtilities.getOption(picker_options.findElements(By.className("ql-picker-item")), "Heading", NavigationUtilities.FindOption.ATTRIBUTE, "data-label");//20 lines
assertNotNull(option, "Something went wrong while setting the Heading");
Expand Down
21 changes: 9 additions & 12 deletions src/test/java/com/fullteaching/e2e/no_elastest/utils/Click.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static java.lang.invoke.MethodHandles.lookup;
import static org.slf4j.LoggerFactory.getLogger;

public class Click {

private static final Logger log = LoggerFactory.getLogger(Click.class);
Expand Down Expand Up @@ -42,23 +39,23 @@ public static WebDriver withNRetries(WebDriver wd, By eleBy, int n, By waitFor)
Wait.notTooMuch(wd).until(ExpectedConditions.elementToBeClickable(wd.findElement(eleBy)));
wd.findElement(eleBy).click();
Wait.notTooMuch(wd).until(ExpectedConditions.visibilityOfElementLocated(waitFor));
log.info("Click.withNRetries (click): ele:" + tagName + ":" + text + " ==>OK");
log.info("Click.withNRetries (click): ele:{}:{} ==>OK", tagName, text);
return wd;
} catch (Exception e) {
try {
log.error("Click.withNRetries n (click):" + i + " " + e.getClass().getName() + ":" + e.getLocalizedMessage());
log.error("Click.withNRetries n (click):{} {}:{}", i ,e.getClass().getName(),e.getLocalizedMessage());
byJS(wd, wd.findElement(eleBy));
log.info("Click.element (ByJs): ele:" + tagName + ":" + text + " ==>OK");
log.info("Click.withNRetries element (ByJs): ele:{}:{} ==>OK", tagName, text);
return wd;
} catch (Exception ex) {
log.error("Click.withNRetries n (ByJS):" + i + " " + ex.getClass().getName() + ":" + ex.getLocalizedMessage());
log.error("Click.withNRetries n (ByJS):{} {}:{}", i, ex.getClass().getName(), ex.getLocalizedMessage());
i++;
}
}

} while (i < n);

log.error("Click.withNRetries: ele:" + tagName + ":" + text + " ==>KO");
log.error("Click.withNRetries: ele:{}:{} ==>KO",tagName,text);
throw new ElementNotFoundException("Click doesn't work properly");
}

Expand All @@ -84,18 +81,18 @@ public static WebDriver element(WebDriver wd, WebElement ele) throws ElementNotF
try {
Wait.notTooMuch(wd).until(ExpectedConditions.elementToBeClickable(ele));
ele.click();
log.info("Click.element (click): ele:" + tagName + ":" + text + " ==>OK");
log.info("Click.element (click): ele:{}:{} ==>OK", tagName, text);
return wd;
} catch (Exception e) {
log.error("Click.element (click): ele:" + tagName + ":" + text + " ==>KO " + e.getClass().getName() + ":" + e.getLocalizedMessage());
log.error("Click.element (click): ele:{}:{} ==>KO {}:{}", tagName, text, e.getClass().getName(), e.getLocalizedMessage());
}
//Try by Js
try {
byJS(wd, ele);
log.info("Click.element (ByJs): ele:" + tagName + ":" + text + " ==>OK");
log.info("Click.element (ByJs): ele:{}:{} ==>OK", tagName, text);
return wd;
} catch (Exception e) {
log.error("Click.element (ByJs): ele:" + tagName + ":" + text + " ==>KO " + e.getClass().getName() + ":" + e.getLocalizedMessage());
log.error("Click.element (ByJs): ele:{}:{} ==>KO {}:{}", tagName, text, e.getClass().getName(), e.getLocalizedMessage());
}

throw new ElementNotFoundException("Click.element ERROR");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
import java.util.Collection;
import java.util.stream.Stream;

import static java.lang.invoke.MethodHandles.lookup;
import static org.junit.jupiter.params.provider.Arguments.arguments;
import static org.slf4j.LoggerFactory.getLogger;

public class ParameterLoader {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,16 @@
import java.util.Date;
import java.util.concurrent.TimeUnit;

import static com.fullteaching.e2e.no_elastest.common.Constants.LOCALHOST;
import static java.lang.System.getProperty;
import static java.lang.invoke.MethodHandles.lookup;
import static org.openqa.selenium.OutputType.BASE64;
import static org.openqa.selenium.logging.LogType.BROWSER;
import static org.slf4j.LoggerFactory.getLogger;

public class SetUp {

private static final Logger log = LoggerFactory.getLogger(SetUp.class);

public static void tearDown(WebDriver driver) throws InterruptedException {
if (driver != null) {
log.info("url:" + driver.getCurrentUrl() + "\nScreenshot (in Base64) at the end of the test:\n{}",
log.info("url:{}\nScreenshot (in Base64) at the end of the test:\n{}",driver.getCurrentUrl(),
getBase64Screenshot(driver));

log.info("Browser console at the end of the test");
Expand Down

0 comments on commit 197171d

Please sign in to comment.