Skip to content

Commit

Permalink
Add PopupButton trigger() with cuba-id
Browse files Browse the repository at this point in the history
  • Loading branch information
jreznot committed Dec 7, 2018
1 parent 3734c44 commit 60ae4c9
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,40 @@

package com.haulmont.masquerade.components;

import com.haulmont.masquerade.util.Log;
import com.haulmont.masquerade.Selectors;
import com.haulmont.masquerade.base.ByLocator;
import com.haulmont.masquerade.base.SelenideElementWrapper;
import com.haulmont.masquerade.util.Log;
import org.openqa.selenium.By;

import java.util.List;

public interface PopupButton extends Component<PopupButton> {
void click(String option);
void click(String optionText);

@Log
PopupContent openPopupContent();
PopupContent getPopupContent();

interface PopupContent extends SelenideElementWrapper<PopupContent>, ByLocator {
void select(String option);
void select(String optionText);

/**
* Trigger action of popup menu.
* <br>
* Supported bys:
* <ul>
* <li>{@link Selectors#byText(String)}</li>
* <li>{@link Selectors#withText(String)}</li>
* <li>{@link Selectors#byCubaId(String)} </li>
* </ul>
*
* @param actionBy action selector
*/
@Log
void trigger(By actionBy);
@Log
void trigger(String cubaId);

List<String> getOptions();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,19 @@ public interface Tree extends Component<Tree> {
* <li>{@link Selectors#byText(String)}</li>
* <li>{@link Selectors#withText(String)}</li>
* <li>{@link Selectors#byClassName(String)}</li>
* <li>{@link Selectors#byRowIndex(int)} </li>
* </ul>
*
* @param nodeBy node selector
* @return selenide element
*/
SelenideElement getNode(By nodeBy);

/* todo
void select(By nodeBy);
void expand(By nodeBy);
void collapse(By nodeBy);
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.haulmont.masquerade.components.impl;

import com.codeborne.selenide.SelenideElement;
import com.haulmont.masquerade.Selectors;
import com.haulmont.masquerade.components.PopupButton;
import org.openqa.selenium.By;

Expand All @@ -27,8 +28,11 @@
import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.$$;
import static com.haulmont.masquerade.Selectors.byChain;
import static com.haulmont.masquerade.Selectors.byCubaId;
import static com.haulmont.masquerade.sys.TagNames.SPAN;
import static com.haulmont.masquerade.sys.VaadinClassNames.disabledClass;
import static com.haulmont.masquerade.sys.matchers.InstanceOfCases.hasType;
import static com.leacox.motif.Motif.match;
import static org.openqa.selenium.By.className;

public class PopupButtonImpl extends AbstractComponent<PopupButton> implements PopupButton {
Expand All @@ -38,9 +42,9 @@ public PopupButtonImpl(By by) {
}

@Override
public void click(String option) {
public void click(String optionText) {
openPopupContent()
.select(option);
.select(optionText);
}

@Override
Expand Down Expand Up @@ -83,17 +87,48 @@ public SelenideElement getDelegate() {
}

@Override
public void select(String option) {
$(byChain(by, SPAN, byText(option)))
.parent().parent()
.shouldBe(visible)
.shouldNotHave(disabledClass)
.click();
public void select(String optionText) {
trigger(byText(optionText));
}

@SuppressWarnings("CodeBlock2Expr")
@Override
public void trigger(By actionBy) {
match(actionBy)
.when(hasType(Selectors.ByTargetText.class)).then(byText -> {

$(byChain(by, SPAN, byText))
.parent().parent()
.shouldBe(visible)
.shouldNotHave(disabledClass)
.click();
})
.when(hasType(Selectors.WithTargetText.class)).then(withText -> {

$(byChain(by, SPAN, withText))
.parent().parent()
.shouldBe(visible)
.shouldNotHave(disabledClass)
.click();
})
.when(hasType(Selectors.ByCubaId.class)).then(byCubaId -> {

$(byChain(by, byCubaId))
.shouldBe(visible)
.shouldNotHave(disabledClass)
.click();
})
.doMatch();
}

@Override
public void trigger(String cubaId) {
trigger(byCubaId(cubaId));
}

@Override
public List<String> getOptions() {
return $$(byChain(by, SPAN, className("v-button-caption"))).texts();
return $$(byChain(by, SPAN, className("c-cm-button-caption"))).texts();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ public SelenideElement getNode(By nodeBy) {

return $(byChain(by, byXpath(tdXpath)));
})
.when(hasType(Selectors.ByRowIndex.class)).get(byColRow -> {
int rowIndex = byColRow.getIndex() + 1;
.when(hasType(Selectors.ByRowIndex.class)).get(byRow -> {
int rowIndex = byRow.getIndex() + 1;

String tdsXpath = "(.//tr)[" + rowIndex + "]//td[" + 1 +"]";
String tdsXpath = "(.//tr)[" + rowIndex + "]//td[" + 1 + "]";

return $(byChain(by, byClassName("v-tree8-body"), byXpath(tdsXpath)));
})
Expand Down

0 comments on commit 60ae4c9

Please sign in to comment.