Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Commit

Permalink
#293 Code cleanup and Sonar fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrzyzanowski committed Nov 6, 2018
1 parent d57823d commit 1226828
Show file tree
Hide file tree
Showing 29 changed files with 77 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
*/
package com.cognifide.qa.bb.aem.core.component.dialog.dialogfields;

import com.cognifide.qa.bb.aem.core.util.Conditions;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.ExpectedConditions;

import com.cognifide.qa.bb.constants.HtmlTags;
import com.cognifide.qa.bb.qualifier.CurrentScope;
import com.cognifide.qa.bb.qualifier.PageObject;
import com.cognifide.qa.bb.wait.BobcatWait;
import com.google.inject.Inject;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.ExpectedConditions;

/**
* This class represents path browser dialog field.
Expand Down Expand Up @@ -62,7 +62,8 @@ public void setValue(Object value) {
input.clear();
input.sendKeys(String.valueOf(value));
}
bobcatWait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".foundation-picker-buttonlist.coral3-Overlay.is-open")));
bobcatWait.until(ExpectedConditions.visibilityOfElementLocated(
By.cssSelector(".foundation-picker-buttonlist.coral3-Overlay.is-open")));
currentScope.findElement(By.className("coral-Form-fieldlabel")).click();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import com.cognifide.qa.bb.aem.core.login.AemAuthCookieFactoryImpl;
import com.cognifide.qa.bb.aem.core.login.AemAuthenticationController;
import com.cognifide.qa.bb.aem.core.login.AuthorAuthenticationController;
import com.cognifide.qa.bb.aem.core.siteadmin.SiteAdminController;
import com.cognifide.qa.bb.aem.core.siteadmin.AemSiteAdminController;
import com.google.inject.AbstractModule;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,9 @@
*/
package com.cognifide.qa.bb.aem.core.guice;

import com.cognifide.qa.bb.aem.core.constants.AemConfigKeys;
import com.cognifide.qa.bb.aem.core.pages.AemTestPageControler;
import com.cognifide.qa.bb.aem.core.pages.sling.SlingTestPageControler;
import com.cognifide.qa.bb.provider.http.HttpClientProvider;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.name.Named;
import org.apache.http.impl.client.CloseableHttpClient;

/**
* Module that need to be installed to use page creation in AEM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,11 @@
*/
package com.cognifide.qa.bb.aem.core.guice;

import com.cognifide.qa.bb.aem.core.component.actions.ConfigureComponentAction;
import com.cognifide.qa.bb.aem.core.component.actions.EditComponentAction;
import com.cognifide.qa.bb.aem.core.component.action.ComponentAction;
import com.cognifide.qa.bb.aem.core.component.action.ComponentController;
import com.cognifide.qa.bb.aem.core.component.actions.ComponentControllerImpl;
import com.cognifide.qa.bb.aem.core.sidepanel.internal.SidePanel;
import com.cognifide.qa.bb.aem.core.sidepanel.internal.SidePanelImpl;
import com.cognifide.qa.bb.aem.core.sidepanel.internal.SidePanelTabBar;
import com.cognifide.qa.bb.aem.core.sidepanel.internal.SidePanelTabBarImpl;
import com.google.inject.AbstractModule;
import com.google.inject.multibindings.MapBinder;

public class AemSidePanelModule extends AbstractModule {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@
*/
package com.cognifide.qa.bb.aem.core.siteadmin;

import com.cognifide.qa.bb.aem.core.siteadmin.SiteAdminAction;
import com.cognifide.qa.bb.aem.core.siteadmin.SiteAdminController;
import com.google.inject.Inject;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import com.google.inject.Inject;

/**
* SiteAdminController for AEM 6.4
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ public void verifyPostAjax(ExpectedCondition condition) {
public Object optionalWait(ExpectedCondition<WebElement> condition) {
try {
return bobcatWait.until(condition);
} catch (TimeoutException ignored) {
LOG.warn("Condition failed, returing null: {}", ignored);
} catch (TimeoutException e) {
LOG.warn("Condition failed, returing null: {}", e);
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@

import com.cognifide.qa.bb.aem.core.component.configuration.ComponentConfigReader;
import com.cognifide.qa.bb.aem.core.component.configuration.ComponentConfigResourceFileReader;
import com.cognifide.qa.bb.aem.core.constants.AemConfigKeys;
import com.cognifide.qa.bb.provider.http.HttpClientProvider;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.name.Named;
import org.apache.http.impl.client.CloseableHttpClient;

/**
* Main module that need to be installed to use AEM functions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
*/
package com.cognifide.qa.bb.aem.core.pages;

import java.util.List;

import javax.inject.Named;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import com.cognifide.qa.bb.aem.core.component.GlobalBar;
import com.cognifide.qa.bb.frame.FrameSwitcher;
import com.cognifide.qa.bb.mapper.field.PageObjectProviderHelper;
Expand All @@ -28,22 +36,14 @@
import com.google.inject.Binding;
import com.google.inject.Inject;
import com.google.inject.internal.LinkedBindingImpl;

import io.qameta.allure.Step;
import java.util.List;
import javax.inject.Named;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Abstract class that marks page as being from AEM
*/
public class AemAuthorPage<T extends AemAuthorPage> extends Page {

private static final Logger LOG = LoggerFactory.getLogger(AemAuthorPage.class);

private static final String CONTENT_FRAME = "ContentFrame";

@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
* <code>
*{@literal @}{@link com.cognifide.qa.bb.qualifier.CurrentScope}
*{@literal @}{@link com.google.inject.Inject}
* private {@link org.openqa.selenium.WebElement} currentScope;
* private WebElement currentScope;
* </code>
*
* When this is true, but field of name currentScope has been already defined this switch has no effect and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
* <code>
*{@literal @}{@link CurrentScope}
*{@literal @}{@link com.google.inject.Inject}
* private {@link org.openqa.selenium.WebElement} currentScope;
* private WebElement currentScope;
* </code>
*
* When this is true, but field of name currentScope has been already defined this switch has no effect and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@

/**
* Provides configuration strategy that loads Bobcat properties from a YAML file.
* The 'new' Bobcat configuration strategy, it replaces the {@link LegacyConfig}.
* <br>
* At the moment, to enable this config, Bobcat users needs to run tests with
* {@value com.cognifide.qa.bb.constants.ConfigKeys#CONFIG_STRATEGY} system property set to {@code yaml}.
Expand Down Expand Up @@ -141,10 +140,12 @@ private Map<String, Map<String, String>> readAdditionalContexts() {
}

private Map<? extends String, ? extends Map<String, String>> getContextsFromYaml(Path path) {
TypeReference<Map<String, Map<String, String>>> typeRef = new TypeReference<Map<String, Map<String, String>>>() {
};
TypeReference<Map<String, Map<String, String>>> typeRef =
new TypeReference<Map<String, Map<String, String>>>() {
};
return YamlReader
.read(ADDITIONAL_CONTEXTS_FOLDER + StringUtils.substringAfter(path.toString(), ADDITIONAL_CONTEXTS_FOLDER_NAME),
.read(ADDITIONAL_CONTEXTS_FOLDER + StringUtils
.substringAfter(path.toString(), ADDITIONAL_CONTEXTS_FOLDER_NAME),
typeRef);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
import com.cognifide.qa.bb.cookies.domain.CookieData;
import com.google.inject.Inject;

public class Cookies {
public class CookiesSetter {

private List<CookieData> cookies;

@Inject
public Cookies(List<CookieData> cookies) {
public CookiesSetter(List<CookieData> cookies) {
this.cookies = cookies;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.openqa.selenium.WebDriver;

import com.cognifide.qa.bb.constants.ConfigKeys;
import com.cognifide.qa.bb.cookies.Cookies;
import com.cognifide.qa.bb.cookies.CookiesSetter;
import com.cognifide.qa.bb.cookies.DefaultCookiesProvider;
import com.cognifide.qa.bb.provider.selenium.webdriver.modifiers.webdriver.WebDriverModifier;
import com.google.inject.Inject;
Expand Down Expand Up @@ -55,7 +55,7 @@ public boolean shouldModify() {
*/
@Override
public WebDriver modify(WebDriver webDriver) {
injector.getInstance(Cookies.class).setCookies(webDriver);
injector.getInstance(CookiesSetter.class).setCookies(webDriver);
return webDriver;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,49 +19,54 @@
*/
package com.cognifide.qa.bb.mapper.field;

import com.cognifide.qa.bb.qualifier.PageObject;
import com.cognifide.qa.bb.qualifier.PageObjectInterface;
import com.google.inject.Binding;
import com.google.inject.Injector;
import com.google.inject.internal.LinkedBindingImpl;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.WildcardType;
import java.util.Objects;

import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.By;

import com.cognifide.qa.bb.qualifier.PageObject;
import com.cognifide.qa.bb.qualifier.PageObjectInterface;
import com.google.inject.Binding;
import com.google.inject.Injector;
import com.google.inject.internal.LinkedBindingImpl;

/**
* Helper class for Page Objects
*/
public final class PageObjectProviderHelper {

public static final String ERROR_MSG =
"PageObject has to have defined selector when used with FindPageObject annotation";

private PageObjectProviderHelper() {
// Empty for helper class
}

/**
* Gets selector from {@link PageObject} if class annotated by this annotation is used in list
*
* @param field class field
* @param field class field
* @param originalInjector
* @return selector
*/
public static By getSelectorFromGenericPageObject(Field field,
Injector originalInjector) {
Class<?> genericType = getGenericType(field);
if(genericType.isAnnotationPresent(
PageObjectInterface.class)){
if (genericType != null && genericType.isAnnotationPresent(
PageObjectInterface.class)) {
Binding<?> binding = originalInjector.getBinding(genericType);
if(binding instanceof LinkedBindingImpl){
return PageObjectProviderHelper.retrieveSelectorFromPageObjectInterface(((LinkedBindingImpl) binding).getLinkedKey().getTypeLiteral().getRawType());
};
if (binding instanceof LinkedBindingImpl) {
return PageObjectProviderHelper.retrieveSelectorFromPageObjectInterface(
((LinkedBindingImpl) binding).getLinkedKey().getTypeLiteral().getRawType());
}
} else {
return retrieveSelectorFromPageObject(field, true);
}
throw new IllegalArgumentException(
"PageObject has to have defined selector when used with FindPageObject annotation");
throw new IllegalArgumentException(ERROR_MSG);
}

/**
Expand Down Expand Up @@ -100,8 +105,7 @@ public static By retrieveSelectorFromPageObjectInterface(Class<?> field) {
if (StringUtils.isNotEmpty(xpathValue)) {
return By.xpath(xpathValue);
}
throw new IllegalArgumentException(
"PageObject has to have defined selector when used with FindPageObject annotation");
throw new IllegalArgumentException(ERROR_MSG);
}

private static By retrieveSelectorFromPageObject(Field field, boolean useGeneric) {
Expand All @@ -119,8 +123,7 @@ private static By retrieveSelectorFromPageObject(Field field, boolean useGeneric
if (StringUtils.isNotEmpty(xpathValue)) {
return By.xpath(xpathValue);
}
throw new IllegalArgumentException(
"PageObject has to have defined selector when used with FindPageObject annotation");
throw new IllegalArgumentException(ERROR_MSG);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
*/
package com.cognifide.qa.bb.mapper.field;

import java.lang.reflect.Field;
import java.util.Optional;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.pagefactory.ElementLocatorFactory;

import com.cognifide.qa.bb.exceptions.BobcatRuntimeException;
import com.cognifide.qa.bb.qualifier.PageObject;
import com.cognifide.qa.bb.qualifier.PageObjectInterface;
Expand All @@ -31,10 +37,6 @@
import com.google.inject.ConfigurationException;
import com.google.inject.Inject;
import com.google.inject.Injector;
import java.lang.reflect.Field;
import java.util.Optional;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.pagefactory.ElementLocatorFactory;

/**
* This provider produces values for PageObject's fields that are annotated with one of the Find
Expand Down Expand Up @@ -86,12 +88,10 @@ public Optional<Object> provideValue(Object pageObject, Field field, PageObjectC
Object scopedPageObject = null;
try {
scopedPageObject = injector.getInstance(field.getType());
} catch (ConfigurationException e) {
throw new BobcatRuntimeException(
"Configuration exception: " + e.getErrorMessages().toString(), e);
} catch (Exception e) {
if (e instanceof ConfigurationException) {
ConfigurationException ce = (ConfigurationException) e;
throw new BobcatRuntimeException(
"Configuration exception: " + ce.getErrorMessages().toString(), e);
}
throw new BobcatRuntimeException(e.getMessage(), e);
} finally {
contextStack.pop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.ContextAware;
Expand All @@ -43,7 +42,6 @@
import org.openqa.selenium.internal.FindsByName;
import org.openqa.selenium.internal.FindsByTagName;
import org.openqa.selenium.internal.FindsByXPath;
import org.openqa.selenium.internal.HasIdentity;
import org.openqa.selenium.remote.Response;
import org.openqa.selenium.support.events.EventFiringWebDriver;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
package com.cognifide.qa.bb.scope.webelement;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.openqa.selenium.WebElement;
Expand Down Expand Up @@ -48,7 +48,7 @@ public WebElement findElement() {

@Override
public List<WebElement> findElements() {
return Arrays.asList(webElement);
return Collections.singletonList(webElement);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.cognifide.qa.bb.guice.ThreadScoped;
import com.google.inject.Inject;
import com.google.inject.Provider;

Expand Down
Loading

0 comments on commit 1226828

Please sign in to comment.