WebDrive Selenium browser automation tool that offers a simple and elegant web application testing. WebDrive Selenium is now available as an extra SDK Android SDK, and supports 2.3 (Gingerbread) and beyond!
If your site is optimized for mobile browsers, you can be sure that users will access the server from their phones and tablets. WebDrive makes it easy to write automated tests that are responsible for your site works correctly when viewed from the browser on Android. We will guide you through some basics about WebDrive and see it in action.
Basic WebDrive
WebDrive tests are end to end tests that exercise of the Web application as a real user would. WebDrive models of user interactions with a website, such as motion of the fingers, move the finger and press a lot. You can rotate the screen and interact with HTML5 features like local storage and session storage cache implementation. These tests are run as part of a test based on Android and Junit. They can be launched from Eclipse or the command line. WebDrive tests can be connected with a continuous integration system can run on phones and tablets emulators or real devices. Once the test starts, WebDrive WebView opens a browser set to run Android and the evidence against him.
WebDrive is an additional and Android SDK can be installed using these instructions. Once you've done that you're ready to write tests! It is a complete guide on the site user WebDrive of selenium, but let's start with a basic example to www.google.com to give an idea of what is possible.
Getting Started
First, create an Android project containing an empty activity without design.
public class SimpleAppActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } }
Now we will see our test in action! WebDrive will create a WebView with the same configuration as the Android browser on the thread of the main user interface, ie the thread of activity. WebView activity displayed on the screen, allowing you to view the Web application, the test code is running.
Then create the test project containing the tests Android. WebDrive creates the WebView and set design automatically in the main activity.
Let's write a test that opens the main page of Google in Android and performs a query for "Weather in San Francisco." The test will verify that Google returns search results, and the first result that is taking the weather in San Francisco.
public class SimpleGoogleTest extends ActivityInstrumentationTestCase2<SimpleAppActivity> { public void testGoogleShouldWork() { // Create a WebDriver instance with the activity in which we want the test to run WebDriver driver = new AndroidDriver(getActivity()); // Let’s open a web page driver.get("http://www.google.com"); // Lookup for the search box by its name WebElement searchBox = driver.findElement(By.name("q")); // Enter a search query and submit searchBox.sendKeys("weather in san francisco"); searchBox.submit(); // Making sure that Google shows 11 results WebElement resultSection = driver.findElement(By.id("ires")); List<WebElement> searchResults = resultSection.findElements(By.tagName("li")); assertEquals(11, searchResults.size()); // Let’s ensure that the first result shown is the weather widget WebElement weatherWidget = searchResults.get(0); assertTrue(weatherWidget.getText().contains("Weather for San Francisco, CA")); } }
Now we will see our test in action! WebDrive will create a WebView with the same configuration as the Android browser on the thread of the main user interface, ie the thread of activity. WebView activity displayed on the screen, allowing you to view the Web application, the test code is running.
Testing the interaction
We mentioned that WebDrive supports creating advanced gestures to interact with the device. We will use WebDrive to throw an image on the screen horizontally triggering, and ensure that the following picture gallery shows.
We mentioned that WebDrive supports creating advanced gestures to interact with the device. We will use WebDrive to throw an image on the screen horizontally triggering, and ensure that the following picture gallery shows.
WebElement toFlick = driver.findElement(By.id("image"));
// 400 pixels left at normal speed
Action flick = getBuilder(driver).flick(toFlick, 0, -400, FlickAction.SPEED_NORMAL)
.build();
flick.perform();
WebElement secondImage = driver.findElement(“secondImage”);
assertTrue(secondImage.isDisplayed());
Now, let's rotate the screen and make sure the image on the screen is resized.
assertEquals(landscapeSize, secondImage.getSize())
((Rotatable) driver).rotate(ScreenOrientation.PORTRAIT);
assertEquals(portraitSize, secondImage.getSize());
What if the test shows an error? You can take a screenshot to help debug future:
File tempFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
Komentar Facebook
0 Komentar untuk "The Introduction of Android WebDrive"