Skip to content

Commit

Permalink
#30 is finished.
Browse files Browse the repository at this point in the history
  • Loading branch information
TikhomirovSergey committed Mar 2, 2015
1 parent 69c2e5c commit 15009d4
Show file tree
Hide file tree
Showing 8 changed files with 287 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,37 @@
import org.openqa.selenium.support.PageFactory;

import com.saucelabs.appium.page_object.android.ApiDemosListViewScreenByAllPossible;
import com.saucelabs.appium.page_object.android.ApiDemosListViewScreenChaided;
import com.saucelabs.appium.page_object.android.ApiDemosListViewScreenSimple;
import com.saucelabs.appium.page_object.ios.UICatalogScreenSimple;

/**
* Please read about Page Object design pattern here:
* https://code.google.com/p/selenium/wiki/PageObjects
*
* Please look at:
* {@link ApiDemosListViewScreenSimple}
* {@link ApiDemosListViewScreenChaided}
* {@link ApiDemosListViewScreenByAllPossible}
* {@link UICatalogScreenSimple}
*
*/
public class AndroidPageObjectTest_ByAllPossible {

private WebDriver driver;
private ApiDemosListViewScreenByAllPossible apiDemosPageObject;

@Before
public void setUp() throws Exception {
File appDir = new File("src/test/java/io/appium/java_client");
File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "../../../apps/ApiDemos/bin");
File app = new File(appDir, "ApiDemos-debug.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

apiDemosPageObject = new ApiDemosListViewScreenByAllPossible();
//This time out is set because test can be run on slow Android SDK emulator
PageFactory.initElements(new AppiumFieldDecorator(driver, 5, TimeUnit.SECONDS),
apiDemosPageObject);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,38 @@
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.PageFactory;

import com.saucelabs.appium.page_object.android.ApiDemosListViewScreenByAllPossible;
import com.saucelabs.appium.page_object.android.ApiDemosListViewScreenChaided;
import com.saucelabs.appium.page_object.android.ApiDemosListViewScreenSimple;
import com.saucelabs.appium.page_object.ios.UICatalogScreenSimple;

/**
* Please read about Page Object design pattern here:
* https://code.google.com/p/selenium/wiki/PageObjects
*
* Please look at:
* {@link ApiDemosListViewScreenSimple}
* {@link ApiDemosListViewScreenChaided}
* {@link ApiDemosListViewScreenByAllPossible}
* {@link UICatalogScreenSimple}
*
*/
public class AndroidPageObjectTest_Chained {

private WebDriver driver;
private ApiDemosListViewScreenChaided apiDemosPageObject;

@Before
public void setUp() throws Exception {
File appDir = new File("src/test/java/io/appium/java_client");
File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "../../../apps/ApiDemos/bin");
File app = new File(appDir, "ApiDemos-debug.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

apiDemosPageObject = new ApiDemosListViewScreenChaided();
//This time out is set because test can be run on slow Android SDK emulator
PageFactory.initElements(new AppiumFieldDecorator(driver, 5, TimeUnit.SECONDS),
apiDemosPageObject);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
package com.saucelabs.appium;

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.pagefactory.AppiumFieldDecorator;
import io.appium.java_client.remote.MobileCapabilityType;

import java.io.File;
import java.net.URL;
import java.util.NoSuchElementException;
import java.util.concurrent.TimeUnit;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.PageFactory;

import com.saucelabs.appium.page_object.android.ApiDemosListViewScreenByAllPossible;
import com.saucelabs.appium.page_object.android.ApiDemosListViewScreenChaided;
import com.saucelabs.appium.page_object.android.ApiDemosListViewScreenSimple;
import com.saucelabs.appium.page_object.ios.UICatalogScreenSimple;

/**
* Please read about Page Object design pattern here:
* https://code.google.com/p/selenium/wiki/PageObjects
*
* Please look at:
* {@link ApiDemosListViewScreenSimple}
* {@link ApiDemosListViewScreenChaided}
* {@link ApiDemosListViewScreenByAllPossible}
* {@link UICatalogScreenSimple}
*
*/
public class AndroidPageObjectTest_PageObjectLikeComplexElement {

private WebDriver driver;
private ApiDemosListViewScreenSimple apiDemosPageObject;

@Before
public void setUp() throws Exception {
File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "../../../apps/ApiDemos/bin");
File app = new File(appDir, "ApiDemos-debug.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

apiDemosPageObject = new ApiDemosListViewScreenSimple();
PageFactory.initElements(new AppiumFieldDecorator(driver.
findElement(By.id("android:id/list")) /*(!!!)*/
, 5, TimeUnit.SECONDS),
apiDemosPageObject);
}

@After
public void tearDown() throws Exception {
driver.quit();
}

@Test
public void findByElementsTest() {
Assert.assertNotEquals(0, apiDemosPageObject.textVieWs.size());
}

@Test
public void findByElementTest() {
Assert.assertNotEquals(null, apiDemosPageObject.textView.getAttribute("text"));
}


@Test
public void androidFindByElementsTest(){
Assert.assertNotEquals(0, apiDemosPageObject.androidTextViews.size());
}

@Test
public void androidFindByElementTest(){
Assert.assertNotEquals(null, apiDemosPageObject.androidTextView.getAttribute("text"));
}

@Test
public void checkThatElementsWereNotFoundByIOSUIAutomator(){
Assert.assertEquals(0, apiDemosPageObject.iosTextViews.size());
}

@Test
public void checkThatElementWasNotFoundByIOSUIAutomator(){
NoSuchElementException nsee = null;
try{
apiDemosPageObject.iosTextView.getAttribute("text");
}
catch (Exception e){
nsee = (NoSuchElementException) e;
}
Assert.assertNotNull(nsee);
}

@Test
public void androidOrIOSFindByElementsTest(){
Assert.assertNotEquals(0, apiDemosPageObject.androidOriOsTextViews.size());
}

@Test
public void androidOrIOSFindByElementTest(){
Assert.assertNotEquals(null, apiDemosPageObject.androidOriOsTextView.getAttribute("text"));
}

@Test
public void androidFindByUIAutomatorElementsTest(){
Assert.assertNotEquals(0, apiDemosPageObject.androidUIAutomatorViews.size());
}

@Test
public void androidFindByUIAutomatorElementTest(){
Assert.assertNotEquals(null, apiDemosPageObject.androidUIAutomatorView.getAttribute("text"));
}

@Test
public void areMobileElementsTest(){
Assert.assertNotEquals(0, apiDemosPageObject.mobileElementViews.size());
}

@Test
public void isMobileElementTest(){
Assert.assertNotEquals(null, apiDemosPageObject.mobileElementView.getAttribute("text"));
}

@Test
public void areMobileElements_FindByTest(){
Assert.assertNotEquals(0, apiDemosPageObject.mobiletextVieWs.size());
}

@Test
public void isMobileElement_FindByTest(){
Assert.assertNotEquals(null, apiDemosPageObject.mobiletextVieW.getAttribute("text"));
}

@Test
public void areRemoteElementsTest(){
Assert.assertNotEquals(0, apiDemosPageObject.remoteElementViews.size());
}

@Test
public void isRemoteElementTest(){
Assert.assertNotEquals(null, apiDemosPageObject.remotetextVieW.getAttribute("text"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,33 @@
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.PageFactory;

import com.saucelabs.appium.page_object.android.ApiDemosListViewScreenByAllPossible;
import com.saucelabs.appium.page_object.android.ApiDemosListViewScreenChaided;
import com.saucelabs.appium.page_object.android.ApiDemosListViewScreenSimple;
import com.saucelabs.appium.page_object.ios.UICatalogScreenSimple;

/**
* Please read about Page Object design pattern here:
* https://code.google.com/p/selenium/wiki/PageObjects
*
* Please look at:
* {@link ApiDemosListViewScreenSimple}
* {@link ApiDemosListViewScreenChaided}
* {@link ApiDemosListViewScreenByAllPossible}
* {@link UICatalogScreenSimple}
*
*/
public class iOSPageObjectTest {

private WebDriver driver;
private UICatalogScreenSimple uiCatalog;

@Before
public void setUp() throws Exception {
File appDir = new File("src/test/java/io/appium/java_client");
File app = new File(appDir, "TestApp.app.zip");
File appDir = new File(System.getProperty("user.dir"),
"../../../apps/TestApp/build/Release-iphonesimulator");
File app = new File(appDir, "TestApp.app");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "");
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "7.1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,43 @@
import io.appium.java_client.MobileElement;

import java.util.List;

import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.pagefactory.AndroidFindAll;
import io.appium.java_client.pagefactory.AndroidFindBy;

/**
*
* @author TikhomirovSergey
* Here is the common sample shows how to use
* {@link AndroidFindAll} annotation to describe all possible
* locators of a target element. This feature should help to
* reduce the number of page PageObject-classes
*
* It demonstrates how to declare screen elements using Appium
* page objects facilities.
*
* About Page Object design pattern read here:
* https://code.google.com/p/selenium/wiki/PageObjects
*
*/
public class ApiDemosListViewScreenByAllPossible {

@AndroidFindAll({
@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"android:id/Fakecontent\")"),
@AndroidFindBy(id = "android:id/Faketext1"),
@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"android:id/list\")"), //by this locator element is found
@AndroidFindBy(id = "android:id/FakeId")
})
}) //If here is a list then it will be filled by all elements
//which are found using all declared locators
public List<MobileElement> findAllElementViews;

@AndroidFindAll({
@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"android:id/Fakecontent\")"),
@AndroidFindBy(id = "android:id/Faketext1"),
@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"android:id/list\")"), //by this locator element is found
@AndroidFindBy(id = "android:id/FakeId")
})
}) //If here is a single element then it will find the first
//element that is found by any of declared locators
public AndroidElement findAllElementView;
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,38 @@
package com.saucelabs.appium.page_object.android;

import io.appium.java_client.android.AndroidElement;

import java.util.List;

import org.openqa.selenium.WebElement;

import io.appium.java_client.pagefactory.AndroidFindBy;
import io.appium.java_client.pagefactory.AndroidFindBys;
import io.appium.java_client.pagefactory.iOSFindBy;
import io.appium.java_client.pagefactory.iOSFindBys;

/**
*
* @author TikhomirovSergey
* Here is the common sample shows how to use
* {@link AndroidFindBys} annotation to describe the chain of the
* searching for the target element of a native Android app content.
*
* It demonstrates how to declare screen elements using Appium
* page objects facilities.
*
* About Page Object design pattern read here:
* https://code.google.com/p/selenium/wiki/PageObjects
*
*/
public class ApiDemosListViewScreenChaided {


@AndroidFindBys({
@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"android:id/list\")"),
@AndroidFindBy(className = "android.widget.TextView")
@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"android:id/list\")"), //the searching
//starts here
@AndroidFindBy(className = "android.widget.TextView") //this element is nested
//and so on
})
public List<WebElement> chainElementViews;

Expand Down
Loading

0 comments on commit 15009d4

Please sign in to comment.