Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2311 fix appium combined locator in reports #2315

Merged
merged 1 commit into from
May 28, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public ByTagAndAttribute(String tag, String attributeName, String attributeValue
@CheckReturnValue
@Nonnull
public String toString() {
return "by tag: " + tag + "; by attribute: " + attributeName + "; by value: " + attributeValue;
return "*".equals(tag) ?
String.format("[%s=%s]", attributeName, attributeValue) :
String.format("%s[%s=%s]", tag, attributeName, attributeValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,18 @@ private By chooseSelector(SearchContext context) {
}
throw new UnsupportedOperationException("Unsupported webdriver: " + WebDriverRunner.getWebDriver());
}

@Override
public String toString() {
if (androidSelector != null && iosSelector != null) {
return String.format("[android:%s, ios:%s]", androidSelector, iosSelector);
}
if (androidSelector != null) {
return androidSelector.toString();
}
if (iosSelector != null) {
return iosSelector.toString();
}
return "CombinedBy: null";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public WithTagAndAttribute(String tag, String attributeName, String attributeVal
@CheckReturnValue
@Nonnull
public String toString() {
return "by tag: " + tag + "; by attribute: " + attributeName + "; with value: " + attributeValue;
return "*".equals(tag) ?
String.format("[%s*=%s]", attributeName, attributeValue) :
String.format("%s[%s*=%s]", tag, attributeName, attributeValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,126 +12,129 @@ void testByTagAndTextSelector() {
By by = AppiumSelectors.byTagAndText("*", "selen'ide-app'ium");
assertThat(by)
.isInstanceOf(By.ByXPath.class)
.hasToString("by tag: *; by attribute: text; by value: selen'ide-app'ium");
.hasToString("[text=selen'ide-app'ium]");
}

@Test
void testByTextSelector() {
By by = AppiumSelectors.byText("selen'ide-app'ium");
assertThat(by)
.isInstanceOf(By.ByXPath.class)
.hasToString("by tag: *; by attribute: text; by value: selen'ide-app'ium");
.hasToString("[text=selen'ide-app'ium]");
}

@Test
void testWithTagAndTextSelector() {
By by = AppiumSelectors.withTagAndText("*", "selen'ide-app'ium");
assertThat(by)
.isInstanceOf(By.ByXPath.class)
.hasToString("by tag: *; by attribute: text; with value: selen'ide-app'ium");
.hasToString("[text*=selen'ide-app'ium]");
}

@Test
void testWithTextSelector() {
By by = AppiumSelectors.withText("selen'ide-app'ium");
assertThat(by)
.isInstanceOf(By.ByXPath.class)
.hasToString("by tag: *; by attribute: text; with value: selen'ide-app'ium");
.hasToString("[text*=selen'ide-app'ium]");
}

@Test
void testByTagAndNameSelector() {
By by = AppiumSelectors.byTagAndName("*", "selen'ide-app'ium");
assertThat(by)
.isInstanceOf(By.ByXPath.class)
.hasToString("by tag: *; by attribute: name; by value: selen'ide-app'ium");
.hasToString("[name=selen'ide-app'ium]");
}

@Test
void testByNameSelector() {
By by = AppiumSelectors.byName("selen'ide-app'ium");
assertThat(by)
.isInstanceOf(By.ByXPath.class)
.hasToString("by tag: *; by attribute: name; by value: selen'ide-app'ium");
.hasToString("[name=selen'ide-app'ium]");
}

@Test
void testWithTagAndNameSelector() {
By by = AppiumSelectors.withTagAndName("*", "selen'ide-app'ium");
assertThat(by)
.isInstanceOf(By.ByXPath.class)
.hasToString("by tag: *; by attribute: name; with value: selen'ide-app'ium");
.hasToString("[name*=selen'ide-app'ium]");
}

@Test
void testWithNameSelector() {
By by = AppiumSelectors.withName("selen'ide-app'ium");
assertThat(by)
.isInstanceOf(By.ByXPath.class)
.hasToString("by tag: *; by attribute: name; with value: selen'ide-app'ium");
.hasToString("[name*=selen'ide-app'ium]");
}

@Test
void testByTagAndAttributeSelector() {
By by = AppiumSelectors.byTagAndAttribute("*", "text", "selen'ide-app'ium");
assertThat(by)
.isInstanceOf(By.ByXPath.class)
.hasToString("by tag: *; by attribute: text; by value: selen'ide-app'ium");
.hasToString("[text=selen'ide-app'ium]");
}

@Test
void testByAttributeSelector() {
By by = AppiumSelectors.byAttribute("text", "selen'ide-app'ium");
assertThat(by)
.isInstanceOf(By.ByXPath.class)
.hasToString("by tag: *; by attribute: text; by value: selen'ide-app'ium");
.hasToString("[text=selen'ide-app'ium]");
}

@Test
void testWithTagAndAttributeSelector() {
By by = AppiumSelectors.withTagAndAttribute("*", "text", "selen'ide-app'ium");
assertThat(by)
.isInstanceOf(By.ByXPath.class)
.hasToString("by tag: *; by attribute: text; with value: selen'ide-app'ium");
.hasToString("[text*=selen'ide-app'ium]");
}

@Test
void testWithAttributeSelector() {
By by = AppiumSelectors.withAttribute("text", "selen'ide-app'ium");
assertThat(by)
.isInstanceOf(By.ByXPath.class)
.hasToString("by tag: *; by attribute: text; with value: selen'ide-app'ium");
.hasToString("[text*=selen'ide-app'ium]");
}

@Test
void testByTagAndContentDescriptionSelector() {
By by = AppiumSelectors.byTagAndContentDescription("*", "selen'ide-app'ium");
assertThat(by)
.isInstanceOf(By.ByXPath.class)
.hasToString("by tag: *; by attribute: content-desc; by value: selen'ide-app'ium");
.hasToString("[content-desc=selen'ide-app'ium]");
}

@Test
void testWithTagAndContentDescriptionSelector() {
By by = AppiumSelectors.withTagAndContentDescription("*", "selen'ide-app'ium");
assertThat(by)
assertThat(AppiumSelectors.withTagAndContentDescription("*", "selen'ide-app'ium"))
.isInstanceOf(By.ByXPath.class)
.hasToString("[content-desc*=selen'ide-app'ium]");

assertThat(AppiumSelectors.withTagAndContentDescription("android.widget.TextView", "selen'ide-app'ium"))
.isInstanceOf(By.ByXPath.class)
.hasToString("by tag: *; by attribute: content-desc; with value: selen'ide-app'ium");
.hasToString("android.widget.TextView[content-desc*=selen'ide-app'ium]");
}

@Test
void testByContentDescriptionSelector() {
By by = AppiumSelectors.byContentDescription("selen'ide-app'ium");
assertThat(by)
.isInstanceOf(By.ByXPath.class)
.hasToString("by tag: *; by attribute: content-desc; by value: selen'ide-app'ium");
.hasToString("[content-desc=selen'ide-app'ium]");
}

@Test
void testWithContentDescriptionSelector() {
By by = AppiumSelectors.withContentDescription("selen'ide-app'ium");
assertThat(by)
.isInstanceOf(By.ByXPath.class)
.hasToString("by tag: *; by attribute: content-desc; with value: selen'ide-app'ium");
.hasToString("[content-desc*=selen'ide-app'ium]");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.codeborne.selenide.appium.selector;

import org.junit.jupiter.api.Test;

import static com.codeborne.selenide.appium.AppiumSelectors.byTagAndAttribute;
import static org.assertj.core.api.Assertions.assertThat;

class ByTagAndAttributeTest {
@Test
void testToString() {
assertThat(byTagAndAttribute("div", "accessibility-id", "hello"))
.hasToString("div[accessibility-id=hello]");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.codeborne.selenide.appium.selector;

import org.junit.jupiter.api.Test;

import static com.codeborne.selenide.appium.AppiumSelectors.byTagAndText;
import static org.assertj.core.api.Assertions.assertThat;

class ByTagAndTextTest {
@Test
void testToString() {
assertThat(byTagAndText("div", "Hello"))
.hasToString("div[text=Hello]");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.codeborne.selenide.appium.selector;

import org.junit.jupiter.api.Test;

import static com.codeborne.selenide.appium.AppiumSelectors.byText;
import static org.assertj.core.api.Assertions.assertThat;

class ByTextTest {
@Test
void testToString() {
assertThat(byText("Hello")).hasToString("[text=Hello]");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.codeborne.selenide.appium.selector;

import org.junit.jupiter.api.Test;

import static com.codeborne.selenide.appium.AppiumSelectors.withTagAndAttribute;
import static org.assertj.core.api.Assertions.assertThat;

class WithTagAndAttributeTest {
@Test
void testToString() {
assertThat(withTagAndAttribute("div", "accessibility-id", "hello"))
.hasToString("div[accessibility-id*=hello]");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.codeborne.selenide.appium.selector;

import org.junit.jupiter.api.Test;

import static com.codeborne.selenide.appium.AppiumSelectors.withTagAndText;
import static org.assertj.core.api.Assertions.assertThat;

class WithTagAndTextTest {
@Test
void testToString() {
assertThat(withTagAndText("div", "Hello"))
.hasToString("div[text*=Hello]");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.codeborne.selenide.appium.selector;

import org.junit.jupiter.api.Test;

import static com.codeborne.selenide.appium.AppiumSelectors.withText;
import static org.assertj.core.api.Assertions.assertThat;

class WithTextTest {
@Test
void testToString() {
assertThat(withText("Hello")).hasToString("[text*=Hello]");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
class AndroidSelectorsTest extends BaseApiDemosTest {

private static final String VIEWS = "Views";
private static final String GRAPHICS_PARTIAL_STRING = "Graphi";

@BeforeEach
void setUp() {
Expand All @@ -35,7 +34,7 @@ void setUp() {
}

@Test
void testAppiumSelectorsInAndroidApp() {
void appiumSelectorsInAndroidApp() {
$(byAttribute("content-desc", VIEWS)).click();
back();
$(byContentDescription(VIEWS)).click();
Expand All @@ -48,17 +47,17 @@ void testAppiumSelectorsInAndroidApp() {
back();
$(byText(VIEWS)).click();
back();
$(withAttribute("text", GRAPHICS_PARTIAL_STRING)).click();
$(withAttribute("text", "Graphi")).click();
back();
$(withContentDescription(GRAPHICS_PARTIAL_STRING)).click();
$(withContentDescription("Graphi")).click();
back();
$(withTagAndAttribute("*", "text", GRAPHICS_PARTIAL_STRING)).click();
$(withTagAndAttribute("*", "text", "Graphi")).click();
back();
$(withTagAndContentDescription("*", GRAPHICS_PARTIAL_STRING)).click();
$(withTagAndContentDescription("*", "Graphi")).click();
back();
$(withTagAndText("android.widget.TextView", GRAPHICS_PARTIAL_STRING)).click();
$(withTagAndText("android.widget.TextView", "Graphi")).click();
back();
$(android(withText(GRAPHICS_PARTIAL_STRING)).ios(By.xpath("")))
.shouldHave(text("Graphics"));
$(android(withText("Graphi")).ios(By.xpath("/"))).shouldHave(text("Graphics"));
$(android(byText("Graphics")).ios(By.xpath("/"))).shouldHave(text("Graphics"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

class IosSelectorsTest extends BaseIosCalculatorTest {
@Test
void testAppiumSelectorsInIosApp() {
void appiumSelectorsInIosApp() {
$(byTagAndName("*", "IntegerA")).setValue("2");
$(byName("IntegerB")).setValue("4");
$(withName("ComputeSum")).click();
$(withTagAndName("*", "Answ")).shouldHave(text("6"));
$(withTagAndName("XCUIElementTypeStaticText", "Answ")).shouldHave(text("6"));
$(byTagAndName("XCUIElementTypeStaticText", "Answer")).shouldHave(text("6"));
}
}