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

Update Page object tools to XCUIT mode #545

Merged
merged 2 commits into from
Dec 27, 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
2 changes: 1 addition & 1 deletion google-style.xml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
</module>
<module name="AbbreviationAsWordInName">
<property name="ignoreFinal" value="false"/>
<property name="allowedAbbreviationLength" value="5"/>
<property name="allowedAbbreviationLength" value="8"/>
</module>
<module name="OverloadMethodsDeclarationOrder"/>
<module name="VariableDeclarationUsageDistance"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import static io.appium.java_client.pagefactory.utils.WebDriverUnpackUtility
.unpackWebDriverFromSearchContext;

import com.google.common.collect.ImmutableList;

import io.appium.java_client.HasSessionDetails;
import io.appium.java_client.MobileElement;
import io.appium.java_client.TouchableElement;
Expand Down Expand Up @@ -58,22 +60,9 @@
*/
public class AppiumFieldDecorator implements FieldDecorator {

private static final List<Class<? extends WebElement>> availableElementClasses =
new ArrayList<Class<? extends WebElement>>() {
private static final long serialVersionUID = 1L;

{
add(WebElement.class);
add(RemoteWebElement.class);
add(MobileElement.class);
add(TouchableElement.class);
add(AndroidElement.class);
add(IOSElement.class);
add(WindowsElement.class);
}

};

private static final List<Class<? extends WebElement>> availableElementClasses = ImmutableList.of(WebElement.class,
RemoteWebElement.class, MobileElement.class, TouchableElement.class, AndroidElement.class,
IOSElement.class, WindowsElement.class);
public static long DEFAULT_IMPLICITLY_WAIT_TIMEOUT = 1;
public static TimeUnit DEFAULT_TIMEUNIT = TimeUnit.SECONDS;
private final WebDriver originalDriver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ private static By buildMobileBy(LocatorGroupStrategy locatorGroupStrategy, Annot
}
}

if (isIOSXcuit()) {
iOSXCUITFindBy[] xCuitFindByArray = annotatedElement.getAnnotationsByType(iOSXCUITFindBy.class);
if (xCuitFindByArray != null && xCuitFindByArray.length > 0) {
return buildMobileBy(howToUseLocators != null ? howToUseLocators.iOSXCUITAutomation() : null,
xCuitFindByArray);
}
}

if (isIOS()) {
iOSFindBy[] iOSFindByArray = annotatedElement.getAnnotationsByType(iOSFindBy.class);
//should be kept for some time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,11 @@
* or the searching by all possible locators.
*/
LocatorGroupStrategy windowsAutomation() default LocatorGroupStrategy.CHAIN;

/**
* @return the strategy which defines how to use locators which are described by
* the {@link iOSXCUITFindBy} annotation. These annotations can define the chained searching
* or the searching by all possible locators.
*/
LocatorGroupStrategy iOSXCUITAutomation() default LocatorGroupStrategy.CHAIN;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.appium.java_client.pagefactory.bys.builder;

import static io.appium.java_client.remote.AutomationName.IOS_XCUI_TEST;
import static io.appium.java_client.remote.AutomationName.SELENDROID;
import static io.appium.java_client.remote.MobilePlatform.ANDROID;
import static io.appium.java_client.remote.MobilePlatform.IOS;
Expand Down Expand Up @@ -180,6 +181,10 @@ protected boolean isIOS() {
return IOS.equalsIgnoreCase(platform);
}

protected boolean isIOSXcuit() {
return isIOS() && IOS_XCUI_TEST.equalsIgnoreCase(automation);
}

protected boolean isWindows() {
return WINDOWS.equalsIgnoreCase(platform);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ enum Strategies {
return MobileBy
.windowsAutomation(getValue(annotation, this));
}
},
BY_NS_PREDICATE("iOSNsPredicate") {
@Override By getBy(Annotation annotation) {
return MobileBy
.iOSNsPredicateString(getValue(annotation, this));
}
};

private final String valueName;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.appium.java_client.pagefactory;

import java.lang.annotation.ElementType;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME) @Target({ElementType.FIELD, ElementType.TYPE})
@Repeatable(iOSXCUITFindBySet.class)
public @interface iOSXCUITFindBy {

/**
* The NSPredicate class is used to define logical conditions used to constrain
* a search either for a fetch or for in-memory filtering.
*/
String iOSNsPredicate() default "";

/**
* It an UI automation accessibility Id which is a convenient to iOS.
* About iOS accessibility
* {@link "https://developer.apple.com/library/ios/documentation/UIKit/Reference/
* UIAccessibilityIdentification_Protocol/index.html"}
*/
String accessibility() default "";

/**
* It is an id of the target element.
*/
String id() default "";

/**
* It is a name of a type/class of the target element.
*/
String className() default "";

/**
* It is a desired element tag.
*/
String tagName() default "";

/**
* It is a xpath to the target element.
*/
String xpath() default "";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.appium.java_client.pagefactory;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME) @Target({ElementType.FIELD, ElementType.TYPE})
public @interface iOSXCUITFindBySet {
/**
* @return an array of {@link iOSXCUITFindBy} which builds a sequence of
* the chained searching for elements or a set of possible locators
*/
iOSXCUITFindBy[] value();
}