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

removed name locator strategy from android and ios drivers along with tests #313

Merged
merged 7 commits into from
Feb 10, 2016
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
String uiAutomator() default "";
String accessibility() default "";
String id() default "";
String name() default "";
@Deprecated
/**
* By.name selector is not supported by Appium server node since 1.5.x.
* So this option is going to be removed further. Be careful.
*/String name() default "";
String className() default "";
String tagName() default "";
String xpath() default "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.appium.java_client.pagefactory;

import org.openqa.selenium.InvalidSelectorException;
import org.openqa.selenium.StaleElementReferenceException;

import java.lang.reflect.InvocationTargetException;
Expand All @@ -28,7 +29,11 @@ static boolean isInvalidSelectorRootCause(Throwable e) {
return false;
}

if (String.valueOf(e.getMessage()).contains(INVALID_SELECTOR_PATTERN)) {
if (InvalidSelectorException.class.isAssignableFrom(e.getClass())) {
return true;
}

if (String.valueOf(e.getMessage()).contains(INVALID_SELECTOR_PATTERN) || String.valueOf(e.getMessage()).contains("Locator Strategy \\w+ is not supported")) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
String uiAutomator() default "";
String accessibility() default "";
String id() default "";
String name() default "";
@Deprecated
/**
* By.name selector is not supported by Appium server node since 1.5.x.
* So this option is going to be removed further. Be careful.
*/String name() default "";
String className() default "";
String tagName() default "";
String xpath() default "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.appium.java_client.pagefactory_tests;

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.pagefactory.*;
import io.appium.java_client.remote.AutomationName;
import io.appium.java_client.remote.MobileCapabilityType;
Expand All @@ -37,7 +38,7 @@
import static org.junit.Assert.*;

public class SelendroidModeTest {
private static int SELENDROID_PORT = 9999;
private static int SELENDROID_PORT = 9999;

private static WebDriver driver;
private static AppiumDriverLocalService service;
Expand All @@ -63,30 +64,30 @@ public class SelendroidModeTest {
private WebElement textXpath;

@SelendroidFindBys({
@SelendroidFindBy(id = "text1")})
@SelendroidFindBy(id = "text1")})
private WebElement textIds;

@SelendroidFindAll({
@SelendroidFindBy(id = "text1")})
@SelendroidFindBy(id = "text1")})
private WebElement textAll;

@SelendroidFindAll({
@SelendroidFindBy(id = "text1")})
@SelendroidFindBy(id = "text1")})
private List<WebElement> textsAll;

@SelendroidFindBy(className = "android.widget.TextView")
private WebElement textClass;

@SelendroidFindBy(tagName = "TextView")
private WebElement textTag;

@SelendroidFindBy(linkText = "Accessibility")
private WebElement textLink;

@SelendroidFindBy(partialLinkText = "ccessibilit")
private WebElement textPartialLink;

@BeforeClass
@BeforeClass
public static void beforeClass() throws Exception {
AppiumServiceBuilder builder = new AppiumServiceBuilder().withArgument(GeneralServerFlag.AUTOMATION_NAME, AutomationName.SELENDROID);
service = builder.build();
Expand Down Expand Up @@ -123,8 +124,8 @@ public static void afterClass() throws Exception {
public void findByIdElementTest() {
assertNotEquals(null, textId.getAttribute("text"));
}
@Test

@Test
public void findBySelendroidSelectorTest() {
assertNotEquals(null, textSelendroidId.getAttribute("text"));
}
Expand Down Expand Up @@ -173,15 +174,15 @@ public void findByElementByCalssTest() {
public void findByElementByTagTest() {
assertNotEquals(null, textTag.getAttribute("text"));
}

@Test
public void findBySelendroidAnnotationOnlyTest() {
assertNotEquals(null, textSelendroidId.getAttribute("text"));
}

@Test
public void findBySelendroidLinkTextTest() {
assertEquals("Accessibility", textLink.getText());

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@

public class iOSPageObjectTest {

private static WebDriver driver;
private static AppiumDriverLocalService service;
private boolean populated = false;
private static WebDriver driver;
private static AppiumDriverLocalService service;
private boolean populated = false;

@FindBy(className = "UIAButton")
private List<WebElement> uiButtons;
Expand Down Expand Up @@ -67,9 +67,9 @@ public class iOSPageObjectTest {
private List<RemoteWebElement> remoteElementViews;

@AndroidFindBys({
@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"android:id/list\")"),
@AndroidFindBy(className = "android.widget.TextView")
})
@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"android:id/list\")"),
@AndroidFindBy(className = "android.widget.TextView")
})
private List<WebElement> chainElementViews;


Expand All @@ -92,11 +92,11 @@ public class iOSPageObjectTest {
@iOSFindBy(uiAutomator = ".elements()[0]")
private MobileElement mobileButton;

@iOSFindBy(uiAutomator = ".elements()[0]")
private TouchableElement touchableButton;
@iOSFindBy(uiAutomator = ".elements()[0]")
private TouchableElement touchableButton;

@iOSFindBy(uiAutomator = ".elements()[0]")
private List<TouchableElement> touchableButtons;
@iOSFindBy(uiAutomator = ".elements()[0]")
private List<TouchableElement> touchableButtons;

@FindBy(className = "UIAButton")
private MobileElement mobiletFindBy_Button;
Expand All @@ -105,69 +105,70 @@ public class iOSPageObjectTest {
private RemoteWebElement remotetextVieW;

@AndroidFindBys({
@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"android:id/list\")"),
@AndroidFindBy(className = "android.widget.TextView")
})
@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"android:id/list\")"),
@AndroidFindBy(className = "android.widget.TextView")
})
private WebElement chainElementView;

@iOSFindBy(uiAutomator = ".elements()[0]")
private IOSElement iosButton;

@iOSFindBy(uiAutomator = ".elements()[0]")
private List<IOSElement> iosButtons;

@iOSFindAll({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this test passing?

@iOSFindBy(xpath = "ComputeSumButton_Test"),
@iOSFindBy(name = "ComputeSumButton") //it is real locator
@iOSFindBy(xpath = "ComputeSumButton_Test"),
@iOSFindBy(name = "ComputeSumButton") //it is real locator
})
private WebElement findAllElement;

@iOSFindAll({
@iOSFindBy(xpath = "ComputeSumButton_Test"),
@iOSFindBy(name = "ComputeSumButton") //it is real locator
@iOSFindBy(xpath = "ComputeSumButton_Test"),
@iOSFindBy(name = "ComputeSumButton") //it is real locator
})
private List<WebElement> findAllElements;

@AndroidFindBy(className = "android.widget.TextView")
@FindBy(css = "e.e1.e2")
private List<WebElement> elementsWhenAndroidLocatorIsNotDefinedAndThereIsInvalidFindBy;

@AndroidFindBy(className = "android.widget.TextView")
@FindBy(css = "e.e1.e2")
private WebElement elementWhenAndroidLocatorIsNotDefinedAndThereIsInvalidFindBy;


@BeforeClass
public static void beforeClass() throws Exception {
service = AppiumDriverLocalService.buildDefaultService();
service.start();
@AndroidFindBy(className = "android.widget.TextView")
@FindBy(css = "e.e1.e2")
private List<WebElement> elementsWhenAndroidLocatorIsNotDefinedAndThereIsInvalidFindBy;

File appDir = new File("src/test/java/io/appium/java_client");
File app = new File(appDir, "TestApp.app.zip");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "");
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "8.4");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone Simulator");
capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
driver = new IOSDriver<>(service.getUrl(), capabilities);
}
@AndroidFindBy(className = "android.widget.TextView")
@FindBy(css = "e.e1.e2")
private WebElement elementWhenAndroidLocatorIsNotDefinedAndThereIsInvalidFindBy;


@BeforeClass
public static void beforeClass() throws Exception {
service = AppiumDriverLocalService.buildDefaultService();
service.start();

File appDir = new File("src/test/java/io/appium/java_client");
File app = new File(appDir, "TestApp.app.zip");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "");
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "7.1");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone Simulator");
capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
driver = new IOSDriver(service.getUrl(), capabilities);
}

@SuppressWarnings("rawtypes")
@Before
public void setUp() throws Exception {
if (!populated)
PageFactory.initElements(new AppiumFieldDecorator(driver), this);
if (!populated)
PageFactory.initElements(new AppiumFieldDecorator(driver), this);

populated = true;
populated = true;
}

@AfterClass
public static void afterClass() throws Exception {
if (driver != null)
driver.quit();
@AfterClass
public static void afterClass() throws Exception {
if (driver != null)
driver.quit();

if (service != null)
service.stop();
}
if (service != null)
service.stop();
}

@Test
public void findByElementsTest() {
Expand Down Expand Up @@ -273,7 +274,7 @@ public void checkThatElementWasNotFoundByAndroidUIAutomator_Chain(){
}
Assert.assertNotNull(nsee);
}

@Test
public void isIOSElementTest(){
Assert.assertNotEquals(null, iosButton.getText());
Expand All @@ -294,38 +295,38 @@ public void findAllElementTest(){
Assert.assertNotEquals(null, findAllElement.getText());
}

@Test
public void isTouchAbleElement(){
Assert.assertNotEquals(null, touchableButton.getText());
}
@Test
public void isTouchAbleElement(){
Assert.assertNotEquals(null, touchableButton.getText());
}

@Test
public void areTouchAbleElements(){
Assert.assertNotEquals(0, touchableButtons.size());
}
@Test
public void areTouchAbleElements(){
Assert.assertNotEquals(0, touchableButtons.size());
}

@Test
@SuppressWarnings("unused")
public void isTheFieldIOSElement(){
@Test
public void isTheFieldIOSElement(){
@SuppressWarnings("unused")
IOSElement iOSElement = (IOSElement) mobileButton; //declared as MobileElement
iOSElement = (IOSElement) iosUIAutomatorButton; //declared as WebElement
iOSElement = (IOSElement) remotetextVieW; //declared as RemoteWebElement
iOSElement = (IOSElement) touchableButton; //declared as TouchABLEElement
}

@Test
public void checkThatTestWillNotBeFailedBecauseOfInvalidFindBy(){
try {
Assert.assertNotEquals(null, elementWhenAndroidLocatorIsNotDefinedAndThereIsInvalidFindBy.getAttribute("text"));
}
catch (NoSuchElementException ignored){
return;
}
throw new RuntimeException(NoSuchElementException.class.getName() + " has been expected.");
}

@Test
public void checkThatTestWillNotBeFailedBecauseOfInvalidFindBy_List(){
Assert.assertEquals(0, elementsWhenAndroidLocatorIsNotDefinedAndThereIsInvalidFindBy.size());
}
}
iOSElement = (IOSElement) iosUIAutomatorButton; //declared as WebElement
iOSElement = (IOSElement) remotetextVieW; //declared as RemoteWebElement
iOSElement = (IOSElement) touchableButton; //declared as TouchABLEElement
}

@Test
public void checkThatTestWillNotBeFailedBecauseOfInvalidFindBy(){
try {
Assert.assertNotEquals(null, elementWhenAndroidLocatorIsNotDefinedAndThereIsInvalidFindBy.getAttribute("text"));
}
catch (NoSuchElementException ignored){
return;
}
throw new RuntimeException(NoSuchElementException.class.getName() + " has been expected.");
}

@Test
public void checkThatTestWillNotBeFailedBecauseOfInvalidFindBy_List(){
Assert.assertEquals(0, elementsWhenAndroidLocatorIsNotDefinedAndThereIsInvalidFindBy.size());
}
}