Skip to content
This repository has been archived by the owner on May 29, 2023. It is now read-only.

Commit

Permalink
Indent code with 2 spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
rosolko committed May 29, 2017
1 parent a5aecf5 commit b092777
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 161 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Expand Up @@ -2,7 +2,7 @@ root = true

[*]
indent_style = space
indent_size = 4
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
Expand Down
53 changes: 27 additions & 26 deletions build.gradle
@@ -1,6 +1,7 @@
plugins {
id 'java-library'
id 'maven'
id 'java'
id 'java-library'
id 'maven'
}

defaultTasks 'check', 'test', 'install'
Expand All @@ -13,57 +14,57 @@ sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

ext {
encoding = 'UTF-8'
log4jVersion = '2.8.2'
encoding = 'UTF-8'
log4jVersion = '2.8.2'
}

compileJava {
options.incremental = true
options.encoding = encoding
options.incremental = true
options.encoding = encoding
}

compileTestJava {
options.encoding = encoding
options.encoding = encoding
}

javadoc {
options.encoding = encoding
failOnError = false
options.encoding = encoding
failOnError = false
}

repositories {
jcenter()
mavenCentral()
jcenter()
mavenCentral()
}

dependencies {
implementation('com.codeborne:selenide:4.4.3')
implementation('io.appium:java-client:5.0.0-BETA8')
implementation('com.codeborne:selenide:4.4.3')
implementation('io.appium:java-client:5.0.0-BETA8')
}

jar {
manifest {
attributes(
"Implementation-Title": project.group + '.' + project.name,
"Implementation-Version": version,
"Implementation-Vendor": "Codeborne")
}
manifest {
attributes(
"Implementation-Title": project.group + '.' + project.name,
"Implementation-Version": version,
"Implementation-Vendor": "Codeborne")
}
}

task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allJava
classifier = 'sources'
from sourceSets.main.allJava
}

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
classifier = 'javadoc'
from javadoc.destinationDir
}

artifacts {
archives jar
archives sourcesJar
archives javadocJar
archives jar
archives sourcesJar
archives javadocJar
}

wrapper.gradleVersion = '3.5'
94 changes: 47 additions & 47 deletions deploy.gradle
@@ -1,67 +1,67 @@
plugins {
id 'signing'
id 'signing'
}
apply from: 'build.gradle'

defaultTasks 'clean', 'uploadArchives'

signing {
sign configurations.archives
sign configurations.archives
}

uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

repository(url: project.version.endsWith("-SNAPSHOT") ?
'https://oss.sonatype.org/content/repositories/snapshots/' :
'https://oss.sonatype.org/service/local/staging/deploy/maven2/') {
authentication(userName: "$sonatypeUsername", password: "$sonatypePassword")
}
repository(url: project.version.endsWith("-SNAPSHOT") ?
'https://oss.sonatype.org/content/repositories/snapshots/' :
'https://oss.sonatype.org/service/local/staging/deploy/maven2/') {
authentication(userName: "$sonatypeUsername", password: "$sonatypePassword")
}

pom.project {
name archivesBaseName
packaging 'jar'
description 'Selenide adaptor for Appium framework'
url 'https://github.com/codeborne/selenide-appium'
pom.project {
name archivesBaseName
packaging 'jar'
description 'Selenide adaptor for Appium framework'
url 'https://github.com/codeborne/selenide-appium'

scm {
url 'scm:git@github.com:codeborne/selenide-appium.git'
connection 'scm:git@github.com:codeborne/selenide-appium.git'
developerConnection 'scm:git@github.com:codeborne/selenide-appium.git'
}
scm {
url 'scm:git@github.com:codeborne/selenide-appium.git'
connection 'scm:git@github.com:codeborne/selenide-appium.git'
developerConnection 'scm:git@github.com:codeborne/selenide-appium.git'
}

licenses {
license {
name 'MIT'
url 'https://opensource.org/licenses/MIT'
distribution 'repo'
}
}
licenses {
license {
name 'MIT'
url 'https://opensource.org/licenses/MIT'
distribution 'repo'
}
}

developers {
developer {
id 'asolntsev'
name 'Andrei Solntsev'
}
}
}
developers {
developer {
id 'asolntsev'
name 'Andrei Solntsev'
}
}
}

//mess with the generated pom to set the 'packaging' tag
pom.withXml { XmlProvider xmlProvider ->
def xml = xmlProvider.asString()
def pomXml = new XmlParser().parse(new ByteArrayInputStream(xml.toString().bytes))
//mess with the generated pom to set the 'packaging' tag
pom.withXml { XmlProvider xmlProvider ->
def xml = xmlProvider.asString()
def pomXml = new XmlParser().parse(new ByteArrayInputStream(xml.toString().bytes))

pomXml.version[0] + { packaging('jar') }
pomXml.version[0] + { packaging('jar') }

def newXml = new StringWriter()
def printer = new XmlNodePrinter(new PrintWriter(newXml))
printer.preserveWhitespace = true
printer.print(pomXml)
xml.setLength(0)
xml.append(newXml.toString())
}
}
def newXml = new StringWriter()
def printer = new XmlNodePrinter(new PrintWriter(newXml))
printer.preserveWhitespace = true
printer.print(pomXml)
xml.setLength(0)
xml.append(newXml.toString())
}
}
}
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
@@ -1,4 +1,4 @@
#Fri May 26 09:30:44 MSK 2017
#Sat May 27 08:24:29 MSK 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Expand Down
@@ -1,5 +1,13 @@
package com.codeborne.selenide.appium;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

import com.codeborne.selenide.ElementsCollection;
import com.codeborne.selenide.ElementsContainer;
import com.codeborne.selenide.Selenide;
Expand All @@ -21,10 +29,6 @@
import org.openqa.selenium.support.pagefactory.DefaultElementLocatorFactory;
import org.openqa.selenium.support.pagefactory.ElementLocatorFactory;

import java.lang.reflect.*;
import java.util.ArrayList;
import java.util.List;

public class SelenideAppiumFieldDecorator extends AppiumFieldDecorator {
private final SearchContext searchContext;
private final ElementLocatorFactory factory;
Expand All @@ -41,20 +45,15 @@ public Object decorate(ClassLoader loader, Field field) {
if (selector instanceof ByIdOrName) {
// throw new IllegalArgumentException("Please define locator for " + field);
return decorateWithAppium(loader, field);
}
else if (WebElement.class.isAssignableFrom(field.getType())) {
} else if (WebElement.class.isAssignableFrom(field.getType())) {
return ElementFinder.wrap(searchContext, selector, 0);
}
else if (ElementsCollection.class.isAssignableFrom(field.getType())) {
} else if (ElementsCollection.class.isAssignableFrom(field.getType())) {
return new ElementsCollection(new BySelectorCollection(searchContext, selector));
}
else if (ElementsContainer.class.isAssignableFrom(field.getType())) {
} else if (ElementsContainer.class.isAssignableFrom(field.getType())) {
return createElementsContainer(selector, field);
}
else if (isDecoratableList(field, ElementsContainer.class)) {
} else if (isDecoratableList(field, ElementsContainer.class)) {
return createElementsContainerList(field);
}
else if (isDecoratableList(field, SelenideElement.class)) {
} else if (isDecoratableList(field, SelenideElement.class)) {
return SelenideElementListProxy.wrap(factory.createLocator(field));
}

Expand All @@ -69,6 +68,26 @@ private Object decorateWithAppium(ClassLoader loader, Field field) {
return appiumElement;
}

private ElementsContainer createElementsContainer(By selector, Field field) {
try {
SelenideElement self = ElementFinder.wrap(searchContext, selector, 0);
return initElementsContainer(field.getType(), self);
} catch (Exception e) {
throw new RuntimeException("Failed to create elements container for field " + field.getName(), e);
}
}

private boolean isDecoratableList(Field field, Class<?> type) {
if (!List.class.isAssignableFrom(field.getType())) {
return false;
}

Class<?> listType = getListGenericType(field);

return listType != null && type.isAssignableFrom(listType)
&& (field.getAnnotation(FindBy.class) != null || field.getAnnotation(FindBys.class) != null);
}

private List<ElementsContainer> createElementsContainerList(Field field) {
try {
List<ElementsContainer> result = new ArrayList<>();
Expand All @@ -83,17 +102,8 @@ private List<ElementsContainer> createElementsContainerList(Field field) {
}
}

private ElementsContainer createElementsContainer(By selector, Field field) {
try {
SelenideElement self = ElementFinder.wrap(searchContext, selector, 0);
return initElementsContainer(field.getType(), self);
} catch (Exception e) {
throw new RuntimeException("Failed to create elements container for field " + field.getName(), e);
}
}

private ElementsContainer initElementsContainer(Class<?> type, SelenideElement self)
throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
Constructor<?> constructor = type.getDeclaredConstructor();
constructor.setAccessible(true);
ElementsContainer result = (ElementsContainer) constructor.newInstance();
Expand All @@ -102,17 +112,6 @@ private ElementsContainer initElementsContainer(Class<?> type, SelenideElement s
return result;
}

private boolean isDecoratableList(Field field, Class<?> type) {
if (!List.class.isAssignableFrom(field.getType())) {
return false;
}

Class<?> listType = getListGenericType(field);

return listType != null && type.isAssignableFrom(listType)
&& (field.getAnnotation(FindBy.class) != null || field.getAnnotation(FindBys.class) != null);
}

private Class<?> getListGenericType(Field field) {
Type genericType = field.getGenericType();
if (!(genericType instanceof ParameterizedType)) return null;
Expand Down
@@ -1,35 +1,35 @@
package com.codeborne.selenide.appium;

import java.net.MalformedURLException;
import java.net.URL;

import com.codeborne.selenide.Configuration;
import com.codeborne.selenide.WebDriverProvider;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.net.MalformedURLException;
import java.net.URL;

import static io.appium.java_client.remote.AndroidMobileCapabilityType.APP_ACTIVITY;
import static io.appium.java_client.remote.AndroidMobileCapabilityType.APP_PACKAGE;

public class AndroidDriverProvider implements WebDriverProvider {
@Override
public WebDriver createDriver(DesiredCapabilities capabilities) {
Configuration.startMaximized = false;
Configuration.captureJavascriptErrors = false;
@Override
public WebDriver createDriver(DesiredCapabilities capabilities) {
Configuration.startMaximized = false;
Configuration.captureJavascriptErrors = false;

capabilities.setCapability(MobileCapabilityType.VERSION, "4.4.2");
capabilities.setCapability("automationName", "Appium");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("deviceName", "0123456789ABCDEF");
capabilities.setCapability(APP_PACKAGE, "com.android.calculator2");
capabilities.setCapability(APP_ACTIVITY, "com.android.calculator2.Calculator");
capabilities.setCapability(MobileCapabilityType.VERSION, "4.4.2");
capabilities.setCapability("automationName", "Appium");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("deviceName", "0123456789ABCDEF");
capabilities.setCapability(APP_PACKAGE, "com.android.calculator2");
capabilities.setCapability(APP_ACTIVITY, "com.android.calculator2.Calculator");

try {
return new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
try {
return new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
}

0 comments on commit b092777

Please sign in to comment.