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 runAppInBackground method implementation for XCUITest #593

Merged
merged 1 commit into from
Mar 18, 2017
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 src/main/java/io/appium/java_client/MobileCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class MobileCommand {
protected static final String SET_VALUE;
protected static final String PULL_FILE;
protected static final String PULL_FOLDER;
protected static final String RUN_APP_IN_BACKGROUND;
public static final String RUN_APP_IN_BACKGROUND;
protected static final String PERFORM_TOUCH_ACTION;
protected static final String PERFORM_MULTI_TOUCH;
protected static final String IS_APP_INSTALLED;
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/io/appium/java_client/ios/IOSDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.appium.java_client.ios;

import static io.appium.java_client.MobileCommand.RUN_APP_IN_BACKGROUND;
import static io.appium.java_client.MobileCommand.prepareArguments;

import io.appium.java_client.AppiumDriver;
Expand Down Expand Up @@ -164,6 +165,24 @@ public IOSDriver(Capabilities desiredCapabilities) {
new TouchAction(this).press(startx, starty).waitAction(duration).moveTo(xOffset, yOffset).release().perform();
}

/**
* Runs the current app as a background app for the number of seconds
* or minimizes the app
*
* @param seconds if seconds >= 0: Number of seconds to run App in background.
* This method call will block main thread and restore the application under
* test after the timeout expires.
* if seconds < 0: any negative number of seconds will put the application
* under test into background and return immediately, so iOS dashboard
* will remain on-screen (this, actually, simulates click on Home button)
*/
@Override public void runAppInBackground(int seconds) {
// timeout parameter is expected to be in milliseconds
// float values are allowed
execute(RUN_APP_IN_BACKGROUND,
prepareArguments("seconds", prepareArguments("timeout", seconds * 1000)));
}

@Override public TargetLocator switchTo() {
return new InnerTargetLocator();
}
Expand Down
23 changes: 20 additions & 3 deletions src/test/java/io/appium/java_client/ios/XCUIAutomationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@

package io.appium.java_client.ios;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import org.junit.After;
import org.junit.Test;
import org.openqa.selenium.DeviceRotation;

import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.empty;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertNotNull;

public class XCUIAutomationTest extends AppXCUITTest {

@After public void afterMethod() {
Expand Down Expand Up @@ -51,6 +56,18 @@ public class XCUIAutomationTest extends AppXCUITTest {
}
}

@Test public void testPutIntoBackgroundAndRestore() {
final long msStarted = System.currentTimeMillis();
driver.runAppInBackground(4);
assertThat(System.currentTimeMillis() - msStarted, greaterThan(3000L));
}

@Test public void testPutIntoBackgroundWithoutRestore() {
assertThat(driver.findElementsById("IntegerA"), is(not(empty())));
driver.runAppInBackground(-1);
assertThat(driver.findElementsById("IntegerA"), is(empty()));
}

@Test public void doubleTapTest() {
IOSElement firstField = driver.findElementById("IntegerA");
firstField.sendKeys("2");
Expand Down