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

Commit

Permalink
Merge pull request #141 from sbtqa/fix2
Browse files Browse the repository at this point in the history
fix element redirect issue
  • Loading branch information
clicman authored Jul 27, 2018
2 parents aa3d94e + b4a03d7 commit 62267c9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
32 changes: 16 additions & 16 deletions src/main/java/ru/sbtqa/tag/pagefactory/Page.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ public void clickWebElement(WebElement webElement) {
* initialized, or required element couldn't be found
*/
@ActionTitles({
@ActionTitle("ru.sbtqa.tag.pagefactory.click.link"),
@ActionTitle("ru.sbtqa.tag.pagefactory.click.button")})
@ActionTitle("ru.sbtqa.tag.pagefactory.click.link"),
@ActionTitle("ru.sbtqa.tag.pagefactory.click.button")})
public void clickElementByTitle(String elementTitle) throws PageException {
WebElement webElement;
try {
Expand Down Expand Up @@ -407,7 +407,7 @@ public void checkValue(String elementTitle, String text) throws PageException {
/**
* Action for upload file.
*
* @param filePath path to file
* @param filePath path to file
* @param elementTitle field name, usually 'input' type
* @throws PageException if file cant be uploaded
*/
Expand Down Expand Up @@ -570,8 +570,8 @@ public boolean checkValuesAreNotEqual(String text, WebElement webElement) {
* @param text a {@link java.lang.String} object.
*/
@ActionTitles({
@ActionTitle("ru.sbtqa.tag.pagefactory.check.element.with.text.present"),
@ActionTitle("ru.sbtqa.tag.pagefactory.check.text.visible")})
@ActionTitle("ru.sbtqa.tag.pagefactory.check.element.with.text.present"),
@ActionTitle("ru.sbtqa.tag.pagefactory.check.text.visible")})
public void checkElementWithTextIsPresent(String text) {
if (!DriverExtension.checkElementWithTextIsPresent(text, PageFactory.getTimeOutInSeconds())) {
throw new AutotestError("Text '" + text + "' is not present");
Expand All @@ -592,8 +592,7 @@ public void checkElementWithTextIsPresent(String text) {
* @return web element of the required type
* @throws ru.sbtqa.tag.pagefactory.exceptions.ElementNotFoundException if
* element was not found
* @throws ru.sbtqa.tag.pagefactory.exceptions.ElementDescriptionException
* if element was not found, but with the wrong type
* @throws ru.sbtqa.tag.pagefactory.exceptions.ElementDescriptionException if element was not found, but with the wrong type
*/
public <T extends WebElement> T findElementInBlockByTitle(String blockPath, String title, Class<T> type)
throws PageException {
Expand All @@ -617,8 +616,7 @@ public <T extends WebElement> T findElementInBlockByTitle(String blockPath, Stri
* @return WebElement
* @throws ru.sbtqa.tag.pagefactory.exceptions.ElementNotFoundException if
* element was not found
* @throws ru.sbtqa.tag.pagefactory.exceptions.ElementDescriptionException
* if element was not found, but with the wrong type
* @throws ru.sbtqa.tag.pagefactory.exceptions.ElementDescriptionException if element was not found, but with the wrong type
*/
public WebElement findElementInBlockByTitle(String blockPath, String title) throws PageException {
return findElementInBlockByTitle(blockPath, title, WebElement.class);
Expand Down Expand Up @@ -826,8 +824,7 @@ public String getElementTitle(WebElement element) {
*
* @param element element, redirect for which is being searched
* @return class of the page object, element redirects to
* @throws ru.sbtqa.tag.pagefactory.exceptions.ElementDescriptionException
* if failed to find redirect
* @throws ru.sbtqa.tag.pagefactory.exceptions.ElementDescriptionException if failed to find redirect
*/
public Class<? extends Page> getElementRedirect(WebElement element) throws ElementDescriptionException {
try {
Expand Down Expand Up @@ -857,9 +854,8 @@ public WebElement getElementByTitle(String title) throws PageException {
return Core.getElementByField(this, field);
}
}
}
else {
for (Field field : FieldUtilsExt.getDeclaredFieldsWithInheritance(usedBlock)){
} else {
for (Field field : FieldUtilsExt.getDeclaredFieldsWithInheritance(usedBlock)) {
if (Core.isRequiredElementInBlock(field, title)) {
return Core.getElementByField(usedBlock, field);
}
Expand Down Expand Up @@ -996,7 +992,7 @@ private static Boolean isRequiredAction(Method method, final String title) {

for (ActionTitle action : actionList) {
String actionValue;
actionValue = (i18n != null) ? i18n.get(action.value()) : action.value();
actionValue = (i18n != null) ? i18n.get(action.value()) : action.value();

if (actionValue.equals(title)) {
return true;
Expand Down Expand Up @@ -1136,7 +1132,7 @@ private static <T extends WebElement> T findElementInBlock(HtmlElement block, St
} catch (ClassCastException cce) {
throw new ElementDescriptionException(
String.format("Element '%s' was found in block '%s', but it's type is incorrect."
+ "Requested '%s', but got '%s'",
+ "Requested '%s', but got '%s'",
elementTitle, block.getName(), type.getName(), f.getType()), cce);
}
}
Expand Down Expand Up @@ -1229,6 +1225,10 @@ private static String getFieldTitleInBlock(Field field) {
* @return class of the page, this element redirects to
*/
private static Class<? extends Page> findRedirect(Object parent, Object element) {
if (PageFactory.getPageRepository().get(parent.getClass()) == null) {
return null;
}

for (Map.Entry<Field, String> entry : PageFactory.getPageRepository().get(parent.getClass()).entrySet()) {
Field field = entry.getKey();
RedirectsTo redirect = field.getAnnotation(RedirectsTo.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,17 @@ public class ClickAspect {
@Around("call(* org.openqa.selenium.WebElement.click()) || call(* ru.yandex.qatools.htmlelements.element.*.click())")
public void doAroundClick(ProceedingJoinPoint joinPoint) throws Throwable {
WebElement targetWebElement = null;
Class<? extends Page> elementRedirect = null;

if (joinPoint.getTarget() instanceof TypifiedElement) {
targetWebElement = ((TypifiedElement) joinPoint.getTarget()).getWrappedElement();
TypifiedElement typifiedElement = (TypifiedElement) joinPoint.getTarget();
elementRedirect = PageFactory.getInstance().getCurrentPage().getElementRedirect(typifiedElement);
} else if (joinPoint.getTarget() instanceof WebElement) {
targetWebElement = (WebElement) joinPoint.getTarget();
elementRedirect = PageFactory.getInstance().getCurrentPage().getElementRedirect(targetWebElement);
} else {
joinPoint.proceed();
return;
}

Class<? extends Page> elementRedirect = PageFactory.getInstance().getCurrentPage().getElementRedirect(targetWebElement);

String elementHighlightStyle = null;
boolean isVideoHighlightEnabled = Boolean.valueOf(Props.get("video.highlight.enabled"));
if (isVideoHighlightEnabled) {
Expand Down

0 comments on commit 62267c9

Please sign in to comment.