Skip to content

Commit

Permalink
Update steps for appium 1.9.0 and java-client 6.1.0 (#50)
Browse files Browse the repository at this point in the history
* add systemPort for android parallel testing

* make boolean checkElementExist public for using in other steps

* add driversSettings to additionalAndroidCapabilities for using systemPort

* add checkTextCaseInsensitive method

* change checkTextCaseInsensitive method

* rename strings with ABC

* remove jitpack

* change string name

* add comment to translate xpath

* add comment to translate xpath

* fix input text steps

* change and add new ios steps

* change android buttons

* refactor sendKeys method

* remove log annotation
  • Loading branch information
etrotsenko authored and Yaromudr committed Oct 11, 2018
1 parent 4fd34ac commit 2ab4e28
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 35 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ repositories {
}

dependencies {
compile "io.appium:java-client:5.0.4"
compile "io.appium:java-client:6.1.0"
compile "org.jbehave:jbehave-core:4.3.3"
compile "org.jbehave:jbehave-spring:4.3.3"
compile "org.projectlombok:lombok:1.16.18"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

public abstract class BaseAndroidDriverConfigurator extends AbsDriverConfigurator {

@Override
public AppiumDriver createDriver(DriversSettings driversSettings, AppSettings appSettings) {
DesiredCapabilities capabilities = createCapabilities(driversSettings);
additionalAndroidCapabilities(appSettings, capabilities, driversSettings);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package ru.colibri.ui.steps.android;

import org.jbehave.core.annotations.Named;
import org.jbehave.core.annotations.When;
import org.openqa.selenium.By;
import org.springframework.stereotype.Component;
import ru.colibri.ui.steps.general.TextFieldSteps;
import ru.yandex.qatools.allure.annotations.Step;

@Component
public class AndroidTextFieldSteps extends TextFieldSteps {

private static final By editTextLocator = By.xpath("//*[contains(@class,'EditText')]");

@Step
@When("ввод текста с клавиатуры \"$textOrKeyword\"")
public void sendKeyboardText(@Named("$textOrKeyword") String textOrKeyword) {
sendText(textOrKeyword, editTextLocator);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package ru.colibri.ui.steps.android;

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidKeyCode;
import io.appium.java_client.android.nativekey.AndroidKey;
import io.appium.java_client.android.nativekey.KeyEvent;
import org.jbehave.core.annotations.When;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
Expand All @@ -16,25 +17,25 @@ public class BaseAndroidSystemButtonsSteps extends AbsSteps implements ISystemBu
@Step
@When("выполнено нажатие на Меню")
public void systemMenuClick() {
((AndroidDriver) driver).pressKeyCode(AndroidKeyCode.MENU);
((AndroidDriver) driver).pressKey(new KeyEvent(AndroidKey.MENU));
}

@Step
@When("выполнено нажатие на Хоум")
public void systemHomeClick() {
((AndroidDriver) driver).pressKeyCode(AndroidKeyCode.HOME);
((AndroidDriver) driver).pressKey(new KeyEvent(AndroidKey.HOME));
}

@Override
@Step
@When("выполнено нажатие на Назад")
public void systemBackClick() {
((AndroidDriver) driver).pressKeyCode(AndroidKeyCode.BACK);
((AndroidDriver) driver).pressKey(new KeyEvent(AndroidKey.BACK));
}

@Step
@When("выполнено нажатие на Enter")
public void systemEnterClick() {
((AndroidDriver) driver).pressKeyCode(AndroidKeyCode.KEYCODE_ENTER);
((AndroidDriver) driver).pressKey(new KeyEvent(AndroidKey.ENTER));
}
}
6 changes: 4 additions & 2 deletions src/main/java/ru/colibri/ui/steps/general/ButtonsSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

import java.util.List;

import static io.appium.java_client.touch.offset.ElementOption.element;

@Component
public class ButtonsSteps extends AbsSteps {

Expand All @@ -35,7 +37,7 @@ public void optionalButtonClick(@Named("$button") String button) {
@Step
@When("выполнен лонгтап на \"$button\"")
public void buttonLongtap(@Named("$button") String button) {
new TouchAction(driver).longPress(getWebElementByName(button)).release().perform();
new TouchAction(driver).longPress(element(getWebElementByName(button))).release().perform();
}

@Step
Expand All @@ -44,6 +46,6 @@ public void listItemLongtap(String fieldName, int index) {
IElement element = getCurrentPage().getElementByName(fieldName);
List<WebElement> elementsFound = finder.findWebElements(element);
WebElement firstElement = elementsFound.get(index);
new TouchAction(driver).longPress(firstElement).release().perform();
new TouchAction(driver).longPress(element(firstElement)).release().perform();
}
}
16 changes: 10 additions & 6 deletions src/main/java/ru/colibri/ui/steps/general/SwipeSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,30 @@

import java.time.Duration;

import static io.appium.java_client.touch.WaitOptions.waitOptions;
import static io.appium.java_client.touch.offset.ElementOption.element;
import static io.appium.java_client.touch.offset.ElementOption.point;

@Component
public class SwipeSteps extends AbsSteps {


protected void verticalSwipe(String elementName, int swipeLength, int duration) {
WebElement webElement = getWebElementByName(elementName);
new TouchAction(driver)
.press(webElement)
.waitAction(Duration.ofSeconds(duration))
.moveTo(0, swipeLength)
.press(element(webElement))
.waitAction(waitOptions(Duration.ofSeconds(duration)))
.moveTo(point(0, swipeLength))
.release().perform();

}

protected void horizontalSwipe(String elementName, int swipeLength, int duration) {
WebElement webElement = getWebElementByName(elementName);
new TouchAction(driver)
.press(webElement)
.waitAction(Duration.ofSeconds(duration))
.moveTo(swipeLength, 0)
.press(element(webElement))
.waitAction(waitOptions(Duration.ofSeconds(duration)))
.moveTo(point(swipeLength, 0))
.release().perform();
}

Expand Down
50 changes: 33 additions & 17 deletions src/main/java/ru/colibri/ui/steps/general/TextFieldSteps.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,48 @@
package ru.colibri.ui.steps.general;

import io.appium.java_client.MobileElement;
import lombok.extern.java.Log;
import org.jbehave.core.annotations.Named;
import org.jbehave.core.annotations.When;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Keyboard;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import ru.colibri.ui.core.steps.AbsSteps;
import ru.colibri.ui.settings.general.PropertyUtils;
import ru.yandex.qatools.allure.annotations.Step;

import java.util.List;
import java.util.logging.Level;

@Log
@Component
public class TextFieldSteps extends AbsSteps {

@Autowired
private PropertyUtils propertyUtils;

@When("очистить \"$fieldName\"")
public void clearField(@Named("$fieldName") String fieldName) {
WebElement webElement = getWebElementByName(fieldName);
try {
webElement.clear();
} catch (WebDriverException ignored) {
}
for (int i = webElement.getText().length(); i > 0; i--) {
webElement.sendKeys(Keys.BACK_SPACE);
}
}

@Step
@When("поле \"$field\" заполняется значением \"$valueOrKeyword\"")
public void sendKeys(@Named("$field") String field, @Named("$valueOrKeyword") String valueOrKeyword) {
WebElement webElement = getWebElementByName(field);
String value = propertyUtils.injectProperties(valueOrKeyword);
((MobileElement) webElement).setValue(value);
webElement.sendKeys(value);
}


@Step
@When("(Optional) поле \"$field\" заполняется значением \"$valueOrKeyword\"")
public void optionalSendKeys(@Named("$field") String field, @Named("$valueOrKeyword") String valueOrKeyword) {
Expand All @@ -36,20 +53,19 @@ public void optionalSendKeys(@Named("$field") String field, @Named("$valueOrKeyw
}
}

@Step
@When("ввод текста с клавиатуры \"$textOrKeyword\"")
public void sendText(@Named("$textOrKeyword") String textOrKeyword) {
protected void sendText(String textOrKeyword, By editTextLocator) {
String text = propertyUtils.injectProperties(textOrKeyword);
driver.getKeyboard().sendKeys(text);
}

@When("очистить \"$fieldName\"")
public void clearField(@Named("$fieldName") String fieldName) {
WebElement webElement = getWebElementByName(fieldName);
webElement.clear();
Keyboard keyboard = driver.getKeyboard();
for (int i = webElement.getText().length(); i > 0; i--) {
keyboard.sendKeys(Keys.BACK_SPACE);
List elements = driver.findElements(editTextLocator);
WebElement activeElement = null;
boolean isFocused = false;
for (int i = 0; !isFocused && i < elements.size(); i++) {
activeElement = (WebElement) elements.get(i);
isFocused = Boolean.valueOf(activeElement.getAttribute("focused"));
}
if (isFocused) {
activeElement.sendKeys(text);
} else {
log.log(Level.SEVERE, "Нет активных полей ввода!");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import ru.colibri.ui.core.steps.AbsSteps;
import ru.yandex.qatools.allure.annotations.Step;

import static io.appium.java_client.touch.offset.PointOption.point;

@Component
public class BaseIOSPickerWheelSteps extends AbsSteps {

Expand Down Expand Up @@ -42,7 +44,7 @@ public void setFirstPickerWheelValue() {
int height = size.getHeight();
Point target = new Point(center.getX(), center.getY() - (int) (height * stepToLast));
TouchAction touchAction = new TouchAction(driver);
touchAction.press(target.getX(), target.getY()).release();
touchAction.press(point(target.getX(), target.getY())).release();
touchAction.perform();
}

Expand All @@ -55,7 +57,7 @@ public void setLastPickerWheelValue() {
int height = size.getHeight();
Point target = new Point(center.getX(), center.getY() + (int) (height * stepToLast));
TouchAction touchAction = new TouchAction(driver);
touchAction.press(target.getX(), target.getY()).release();
touchAction.press(point(target.getX(), target.getY())).release();
touchAction.perform();
}

Expand All @@ -74,7 +76,7 @@ public void setNextPickerWheelValue(WebElement pickerWheelElement, double step)
Dimension size = pickerWheelElement.getSize();
int height = size.getHeight();
TouchAction touchAction = new TouchAction(driver);
touchAction.press(center.getX(), center.getY() + (int) (height * step)).release();
touchAction.press(point(center.getX(), center.getY() + (int) (height * step))).release();
touchAction.perform();
}

Expand All @@ -84,7 +86,7 @@ public void setPrevPickerWheelValue(WebElement pickerWheelElement, double step)
Dimension size = pickerWheelElement.getSize();
int height = size.getHeight();
TouchAction touchAction = new TouchAction(driver);
touchAction.press(center.getX(), center.getY() - (int) (height * step)).release();
touchAction.press(point(center.getX(), center.getY() - (int) (height * step))).release();
touchAction.perform();
}
}
11 changes: 11 additions & 0 deletions src/main/java/ru/colibri/ui/steps/ios/IOSButtonSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ public void clickOnReadyButton() {
driver.findElement(MobileBy.iOSNsPredicateString(readyButton)).click();
}

@Step
@When("(Optional) нажата кнопка Готово")
public void clickOnReadyButtonOptional() {
decreaseImplicitlyWait();
try {
clickOnReadyButton();
} catch (Exception ignored) {
}
increaseImplicitlyWait();
}

@Step
@When("нажата кнопка Отмена")
public void clickOnCancelButton() {
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/ru/colibri/ui/steps/ios/IOSTextFieldSteps.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ru.colibri.ui.steps.ios;

import io.appium.java_client.MobileBy;
import org.jbehave.core.annotations.Named;
import org.jbehave.core.annotations.When;
import org.openqa.selenium.By;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import ru.colibri.ui.settings.general.PropertyUtils;
import ru.colibri.ui.steps.general.TextFieldSteps;
import ru.yandex.qatools.allure.annotations.Step;

@Component
public class IOSTextFieldSteps extends TextFieldSteps {

private static final By editTextLocator = MobileBy.iOSNsPredicateString("type like 'XCUIElementTypeTextField'");

@Autowired
private PropertyUtils propertyUtils;

@Step
@When("ввод текста с клавиатуры \"$textOrKeyword\"")
public void sendKeyboardText(@Named("$textOrKeyword") String textOrKeyword) {
sendText(textOrKeyword, editTextLocator);
}
}

0 comments on commit 2ab4e28

Please sign in to comment.