Skip to content

Add ns predicate strategy #13

Merged
merged 7 commits into from
Aug 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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