When an action is atomic it means the entire action happens without interruption. For example, if I have:
driver.get(url); waitForLoadingToFinish(); This code appears to be fine. If we assume the waitForLoadingToFinish() works then this is good. However, what happens if the page loads so fast that the loading icon does not appear. So sometimes I need to wait for the icon to appear then wait for it to disappear. Other times if I wait for it to appear it never appears. The code inside waitForLoadingToFinish() is NOT atomic. It is checking for two or more events but not at once. It will check the first event, then check the second event. If something changes between the first check and the second check it could cause a deadlock or starvation (pre-emptive operating system terms) to occur. There are ways to deal with preventing deadlock or starvation but now you are making your code more difficult to maintain. Usually what happens is you get the test to work with the timing on your development machine. When you push it to the build environment it fails because it has different timing. Or it works for one developer but not another developer. Or it works for months then you get a system update, timing changes and the test starts failing 50% of the time. Additionally, if you don't fully understand the entire technology stack, you might have missed a scenario and the error condition still exists. The error condition might happen less frequently but this is really frustrating. If the test suite fails occasionally and it turns out to be a bad test, the developers will start to mistrust the tests. If the code is always working and the tests are occasionally failing, the developers will start trusting their coding ability and ignoring the test results.
5 Comments
Last 5 and 6 November 2011 was the Saigon MDC 2011(http://www.mobiledevcamp-vn.org/?lang=en). Over I took a training session on android webdriver automation test training session. That training's session slides are attached here. If you missed that training session then also I hope this slide will help your learning invention . Cheers !
Selenium 2.0 and WebDriverNOTE:
We’re currently working on documenting these sections. We believe the information here is accurate, however be aware we are also still working on this chapter. Additional information will be provided as we go which should make this chapter more solid. In addition, we will be proofreading and reviewing it. Selenium 2.0 FeaturesSelenium 2.0 has many new exciting features and improvements over Selenium 1. These new features are introduced release in the release announcement in the Official Selenium Blog. The primary new feature is the integration of the WebDriver API. This addresses a number of limitations along with providing an alternative, and simpler, programming interface. The goal is to develop an object-oriented API that provides additional support for a larger number of browsers along with improved support for modern advanced web-app testing problems. NOTE: We will add a description of SEL 2.0 new features–for now we refer readers to the release announcement. The Selenium Server – When to Use ItYou may, or may not, need the Selenium Server, depending on how you intend to use Selenium. If you will be strictly using the WebDriver API you do not need the Selenium Server. The Selenium Server provides Selenium-RC functionality, which is primarily used for Selenium 1.0 backwards compatability. Since WebDriver uses completely different technology to interact with the browsers, the Selenium Server is not needed. Selenium-WebDriver makes direct calls to the browser using each browser’s native support for automation. Selenium-RC however requires the Selenium- Server to inject javascript into the browser and to then translate messages from your test program’s language-specific Selenium client library into commands that invoke the javascript commands which in turn, automate the AUT from within the browser. In short, if you’re using Selenium-WebDriver, you don’t need the Selenium-Server. Another reason for using the Selenium-Server is if you are using Selenium-Grid for distributed exectution of your tests. Finally, if you are using Selenium-backed Web-Driver (the WebDriver API but with back-end Selenium technology) you will also need the Selenium Server. These topics are described in more detail later in this chapter. Setting Up a Selenium-WebDriver ProjectTo install Selenium means to set up a project in a development so you can write a program using Selenium. How you do this depends on your programming language and your development environment. Getting Started With Selenium-WebDriver WebDriver is a tool for automating testing web applications, and in particular to verify that they work as expected. It aims to provide a friendly API that’s easy to explore and understand, easier to use than the Selenium-RC (1.0) API, which will help make your tests easier to read and maintain. It’s not tied to any particular test framework, so it can be used equally well in a unit testing or from a plain old “main” method. This section introduces WebDriver’s API and helps get you started becoming familiar with it. Start by setting up a WebDriver project if you haven’t already. This was described in the previous section, Setting Up a Selenium-WebDriver Project. Once your project is set up, you can see that WebDriver acts just as any normal library: it is entirely self-contained, and you usually don’t need to remember to start any additional processes or run any installers before using it, as opposed to the proxy server with Selenium-RC. You’re now ready to write some code. An easy way to get started is this example, which searches for the term “Cheese” on Google and then outputs the result page’s title to the console. how to learning script by Java: plz notice why we used which lines. That make you understand how to learn scripting package org.openqa.selenium.example; // importing selenium in code space import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.ExpectedCondition; import org.openqa.selenium.support.ui.WebDriverWait; public class Selenium2Example { public static void main(String[] args) { // Create a new instance of the Firefox driver // Notice that the remainder of the code relies on the interface, // not the implementation. WebDriver driver = new FirefoxDriver(); // And now use this to visit Google driver.get("http://www.google.com"); // Alternatively the same thing can be done like this // driver.navigate().to("http://www.google.com"); // Find the text input element by its name WebElement element = driver.findElement(By.name("q")); // Enter something to search for element.sendKeys("Cheese!"); // Now submit the form. WebDriver will find the form for us from the element element.submit(); // Check the title of the page System.out.println("Page title is: " + driver.getTitle()); // Google's search is rendered dynamically with JavaScript. // Wait for the page to load, timeout after 10 seconds (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return d.getTitle().toLowerCase().startsWith("cheese!"); } }); // Should see: "cheese! - Google Search" System.out.println("Page title is: " + driver.getTitle()); //Close the browser driver.quit(); }} Moving Between Windows and Frames Some web applications have any frames or multiple windows. WebDriver supports moving between named windows using the “switchTo” method: driver.switchTo().window("windowName");All calls to driver will now be interpreted as being directed to the particular window. But how do you know the window’s name? Take a look at the javascript or link that opened it: <a href="somewhere.html" target="windowName">Click here to open a new window</a> Alternatively, you can pass a “window handle” to the “switchTo().window()” method. Knowing this, it’s possible to iterate over every open window like so:for (String handle : driver.getWindowHandles()) { driver.switchTo().window(handle); } You can also swing from frame to frame (or into iframes):driver.switchTo().frame("frameName");It’s possible to access subframes by separating the path with a dot, and you can specify the frame by its index too. That is: driver.switchTo().frame("frameName.0.child");would go to the frame named “child” of the first subframe of the frame called “frameName”.All frames are evaluated as if from *top*. User Input - Filling In FormsWe’ve already seen how to enter text into a textarea or text field, but what about the other elements? You can “toggle” the state of checkboxes, and you can use “click” to set something like an OPTION tag selected. Dealing with SELECT tags isn’t too bad: WebElement select = driver.findElement(By.xpath("//select")); List<WebElement> allOptions = select.findElements(By.tagName("option")); for (WebElement option : allOptions) { System.out.println(String.format("Value is: %s", option.getAttribute("value"))); option.click(); } This will find the first “SELECT” element on the page, and cycle through each of its OPTIONs in turn, printing out their values, and selecting each in turn. As you will notice, this isn’t the most efficient way of dealing with SELECT elements. WebDriver’s support classes include one called “Select”, which provides useful methods for interacting with these. Select select = new Select(driver.findElement(By.xpath("//select"))); select.deselectAll(); select.selectByVisibleText("Edam"); This will deselect all OPTIONs from the first SELECT on the page, and then select the OPTION with the displayed text of “Edam”. Once you’ve finished filling out the form, you probably want to submit it. One way to do this would be to find the “submit” button and click it: driver.findElement(By.id("submit")).click(); // Assume the button has the ID "submit" :)Alternatively, WebDriver has the convenience method “submit” on every element. If you call this on an element within a form, WebDriver will walk up the DOM until it finds the enclosing form and then calls submit on that. If the element isn’t in a form, then the NoSuchElementException will be thrown: Do you have interest in glassfish Admin GUI with selenium and experience the differences between silk testt and Selenium tools
1. Run Selenium from the build If you build admin-gui module you can find the README.SeleniumRC file under the ../glassfish/admin-gui/tests directory. Just follow the instruction from the file, you should be able to setup and run Selenium JBI tests with Glassfish Admin GUI. If you encounter a failure from your browser, open selenium test case files under java directory and replace statement selenium.waitForCondition("Selenium.browserbot.isNewPageLoaded()", TIMEOUT_PERIOD) by selenium.waitForPageToLoad( TIMEOUT_PERIOD) 2. Run Selenium with Glassfish V2 binary bit 1. You must setup the environment by installing Selenium IDE on your Firefox browser 2. Having ant 1.6.5 and jdk1.5.0_11 or latest version installed on your system 3. Create a AdminGUITest directory on your system and copy the following 4 files to the ../AdminGUITest/lib directory selenium-server.jar , selenium-java-client.jar, selenium-java-client-driver-tests.jar and testng-5.5-jdk15.jar andjunit.jar 4. Copy the simple test harness (AdminGUITest.jar file) to your AdminGUI directory and unjar the file 5. Update build.properties file with your setup environment 6. Start the selenium remote server (assume you're using a window system) cd %AdminGUITest.home% java -jar selenium-server.jar 7. Start glassfish domain1 8. Run the first AdminGUI test case cd %AdminGUITest.home% ant run-test 3. Differences between SilkTest and Selenium There are several steps required to prepare the android device or emulator, the environment and the computer. These include: · Installing android-server.apk (the actual filename may differ e.g. if you use a prebuilt version it will include the release name). If you want to use an emulator, we currently recommend using one with Android 2.2 installed. The server doesn’t support earlier versions any more (it used to but limitations with the platform e.g. lack of support for XPath meant the project team have chosen to target a minimum of 2.2). There’s currently an issue with the Java-to-JavaScript bridge in version 2.3 of the emulator, so again we don’t recommend using it currently.) · Configuring port forwarding so your tests can communicate with the device or running instance of the emulator. · Starting the WebDriver Server on the Android emulator (or on a device). Configuring your eclipse project You will need to include the various jar files from the selenium project in order for your tests to use ‘RemoteWebdriver’. The AndroidDriver implements the RemoteWebdriver protocol. You can download a zip file from the selenium project site http://code.google.com/p/selenium/downloads/list e.g. selenium-java-2.0b1.zip currently. This file needs to be unzipped, which will unpack to 2 selenium jar files (the code and the javadoc documentation) and a series of 27 other jar files. All these files need to be added to the build path in your eclipse project. I suggest copying all the files into a common libs folder for your project. First, let's create an Android Virtual Device (AVD): $cd ~/android_sdk/tools/ $./android create avd -n my_android -t 12 -c 100M -n: specifies the name of the AVD. -t: specifies the platform target. For an exhaustive list of targets, run: ./android list targets Make sure the target level you selected corresponds to a supported SDK platform. -c: specifies the SD card storage space. When prompted "Do you wish to create a custom hardware profile [no]" enter "no". Now, start the emulator. This can take a while, but take a look at the FAQ below for tips on how to improve performance of the emulator. $./emulator -avd my_android & Install the WebDriver APKEvery device or emulator has a serial ID. Run this command to get the serial ID of the device or emulator you want to use: $~/android_sdk/platform-tools/adb devices Download the Android server from selenium download page To install the application do: $./adb -s <serialId> -e install -r android-server.apk Make sure you are allowing installation of application not coming from Android Market. Go to Settings -> Applications, and check "Unknown Sources". Start the Android WebDriver application through the UI of the device or by running this command: $./adb -s <serialId> shell am start -a android.intent.action.MAIN -n org.openqa.selenium.android.app/.MainActivity You can start the application in debug mode, which has more verbose logs by doing: $./adb -s <serialId> shell am start -a android.intent.action.MAIN -n org.openqa.selenium.android.app/.MainActivity -e debug true Sample Code: just put that inside a class and check the magic, Run the Testsimport junit.framework.TestCase; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.android.AndroidDriver; public class OneTest extends TestCase { public void testGoogle() throws Exception { WebDriver driver = new AndroidDriver(); // And now use this to visit Google driver.get("http://www.google.com"); // Find the text input element by its name WebElement element = driver.findElement(By.name("q")); // Enter something to search for element.sendKeys("Cheese!"); // Now submit the form. WebDriver will find the form for us from the element element.submit(); // Check the title of the page System.out.println("Page title is: " + driver.getTitle()); driver.quit(); } }
still confused ??? haha. Really no problem. Check my video tutorial on android webdriver. You will have your all questions answer. |
AuthorI am Masud Parvez. Working as IT Senior Project Manager for RMIT University. Previously I built and run a distributed Test Center. My success was to turn that in to one of the most successful business units of the company. Categories
All
|