Java tutorial
/* * Copyright 2015 TOYAMA Sumio * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * 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 com.nowsprinting.hellotesting.appiumtest.selendroid.page; import static org.junit.Assert.*; import io.appium.java_client.android.AndroidDriver; import org.openqa.selenium.By; import org.openqa.selenium.TimeoutException; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.ExpectedConditions; import com.nowsprinting.hellotesting.appiumtest.appium.page.DetailPage; import com.nowsprinting.hellotesting.appiumtest.appium.page.Gender; import com.nowsprinting.hellotesting.appiumtest.appium.page.PreviewPage; public class SelendroidDetailPage extends DetailPage { public SelendroidDetailPage(AndroidDriver driver) { super(driver); } @Override public boolean waitUntilLoad() { // ??????????? try { mWait.until(ExpectedConditions.visibilityOfElementLocated(By.name("name textfield"))); } catch (TimeoutException e) { return false; } return true; } @Override public DetailPage inputName(String name) { if (name != null) { WebElement nameTextField = mDriver.findElement(By.name("name textfield")); nameTextField.sendKeys(name); } return this; } @Override public DetailPage inputMailAddress(String mailAddress) { if (mailAddress != null) { WebElement mailTextField = mDriver.findElement(By.name("mail textfield")); mailTextField.sendKeys(mailAddress); } return this; } @Override public DetailPage inputAge(int age) { /* * --------------------------- * NumberPicker * Button (1??) * EditText (?: 4?) * Button (1??) * --------------------------- * ??????????? * NumberPicker??EditText???? */ WebElement numberPicker = mDriver.findElement(By.className(WIDGET_NUMBER_PICKER)); WebElement ageTextField = numberPicker.findElement(By.className(WIDGET_EDIT_TEXT)); ageTextField.sendKeys(String.valueOf(age)); ageTextField.click(); return this; } @Override public DetailPage selectGender(Gender gender) { /* * --------------------------- * RadioGroup (contentDescription="gender segmentedcontrol") * RadioButton ("") * RadioButton ("") * --------------------------- * ??????????? * contentDescrption?"gender segmentedcontrol"??????? * ???????????? */ if (gender != null) { WebElement genderRadioGroup = mDriver.findElement(By.name("gender segmentedcontrol")); genderRadioGroup.findElement(By.linkText(gender.getRadioButtonText())).click(); } return this; } @Override public PreviewPage saveAndPreview() { mDriver.findElement(By.name("preview")).click(); PreviewPage newPage = new PreviewPage(mDriver); assertTrue(newPage.waitUntilLoad()); return newPage; } }