Skip to content

Commit

Permalink
Add ns predicate strategy (#13)
Browse files Browse the repository at this point in the history
* optimize clear field step

* add iOSNSPredicate strategy

* fix tests

* fix tests

* refactor byText iOS strategy
  • Loading branch information
JasperJhons authored and Yaromudr committed Aug 28, 2017
1 parent 7b4355f commit 88a3b0a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
16 changes: 12 additions & 4 deletions src/main/java/ru/colibri/ui/settings/ios/IOSByFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,25 @@
@Component
public class IOSByFactory extends ByFactory {

private static String XPATH_TEMPLATE = "//*[contains(@name,'%1$s') or contains(@value,'%1$s') or contains(@label,'%1$s')]";

private static String IOSNSPREDICATE_TEMPLATE = "name contains'%1$s' or value contains '%1$s' or label contains '%1$s'";
private String XPATH_TEMPLATE = "//*[contains(@name,'%1$s') or contains(@value,'%1$s') or contains(@label,'%1$s')]";

public By byNameOrValueOrLabel(String label) {
return By.xpath(createXPathByNameOrValueOrLabel(label));
return byIOSNSPredicate(createIOSNSPredicateByNameOrValueOrLabel(label));
}

private String createXPathByNameOrValueOrLabel(String label) {
return format(XPATH_TEMPLATE, label);
}

private String createIOSNSPredicateByNameOrValueOrLabel(String label) {
return format(IOSNSPREDICATE_TEMPLATE, label);
}

@Override
public By byElement(IElement element) {
if (!TextUtils.isEmpty(element.getNSPredicate())) {
return MobileBy.iOSNsPredicateString(element.getNSPredicate());
return byIOSNSPredicate(element.getNSPredicate());
}
if (TextUtils.isEmpty(element.getXpath())) {
if (TextUtils.isEmpty(element.getId())) {
Expand Down Expand Up @@ -54,4 +58,8 @@ private String createSearchXpath(IElement element) {
}
}
}

public MobileBy byIOSNSPredicate(String predicate) {
return (MobileBy) MobileBy.iOSNsPredicateString(predicate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class TestIOSByFactory {

private IOSByFactory byFactory = new IOSByFactory();
private String XPATH_TEMPLATE = "//*[contains(@name,'%1$s') or contains(@value,'%1$s') or contains(@label,'%1$s')]";
private String IOSNSPREDICATE_TEMPLATE = "name contains'%1$s' or value contains '%1$s' or label contains '%1$s'";

@Test
public void testByID() {
Expand All @@ -32,8 +33,8 @@ public void testByText() {
.withName("elementByText")
.withText("visibleText")
.please();
String xpath = format(XPATH_TEMPLATE, element.getText());
By expected = By.xpath(xpath);
String predicate = format(IOSNSPREDICATE_TEMPLATE, element.getText());
MobileBy expected = (MobileBy) MobileBy.iOSNsPredicateString(predicate);

By byElementFromFactory = byFactory.byElement(element);
Assert.assertEquals("Результат работы IOSFactory по text некорректен", expected, byElementFromFactory);
Expand Down

0 comments on commit 88a3b0a

Please sign in to comment.