• Save
RichFaces - Testing on Mobile Devices
Upcoming SlideShare
Loading in...5
×
 

RichFaces - Testing on Mobile Devices

on

  • 11,299 views

Slides from my talk on Red Hat Developer Conference 2012 in Brno.

Slides from my talk on Red Hat Developer Conference 2012 in Brno.

Statistics

Views

Total Views
11,299
Views on SlideShare
3,334
Embed Views
7,965

Actions

Likes
0
Downloads
0
Comments
1

9 Embeds 7,965

http://blog.pavol.pitonak.com 7930
http://5409509891600954773_e46c3ba0bff7dd70fd97fe02d5ba6f849ae1844c.blogspot.com 15
http://translate.googleusercontent.com 13
http://131.253.14.66 2
http://us-w1.rockmelt.com 1
http://www.onlydoo.com 1
http://feeds.feedburner.com 1
http://webcache.googleusercontent.com 1
http://plus.url.google.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • oH!!!!!!!!!! wHAT A nIce WinDoW It Is ! EverY OnE MAY bE LIke It ,UsE It For tHeIr DAily Life AAnd Earn Knowladge, honer. Thanks All
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Smart phones Laptops 209.6 Desktops 112.4 Tablets 63.2 Netbooks 29.4
  • Karel showed you what Arquillian is, what it can do ... He showed Drone extension – WebDriver, Selenium, Ajocado I'll show you how we test RichFaces, a Java Server Faces web framework using Arq on desktop in various browsers I'll explain you how we use all the technologies on this slide for testing Then, after you will get familiar with testing web applications on desktop, I'll introduce you to testing on mobile devices (Android) First I'll show you how to test in emulator and then how to speed up your tests Ajocado – works with Selenium 1 which doesn't support mobile browsers
  • When you need to test your Java web app, you need to build your application and create a WAR archive which can be then deployed to a container In last talk Karel showed you how to start a container and deploy you application According to the version of Selenium you are using, you need to start Selenium server Selenium uses JavaScript to automate web pages. runs inside the JavaScript sandbox, Selenium-RC server to get around the same-origin policy, can sometimes cause issues with browser setup WebDriver on the other hand uses native automation from each language. While this means it takes longer to support new browsers/languages, it does offer a much closer ‘feel’ to the browser. If you’re happy with WebDriver, stick with it, it’s the future. There are limitations and bugs right now, but if they’re not stopping you, go for it. Open web browsers – Selenium 2 supports all major browsers run your tests – TestNG / Junit, integration with Arq, Jenkins Review test results – TestNG report, Jenkins plugin for TestNG
  • Sample RichFaces 4 application built using latest Java EE 6 technologies – JSF2, RichFaces 4, CDI, Bean validation Currency converted which converts 30+ currencies from/to Euros Currency converter, exchange rates list, historical chart Downloads data from ECB Tested on JBoss AS 7.0.2 and 7.1.0.Final released this week Screenshot of desktop version
  • This uses default testng.xml
  • Since it is split, it allows us to run tests multiple times on Jenkins i.e. Unit tests once Functional tests with every container and browser Not implemented yet, just a proof of concept
  • You can either use prepared package or construct war yourself If want to use prepared package, you need to run tests after Maven phase package
  • You can either use prepared package or construct war yourself If want to use prepared package, you need to run tests after Maven phase package
  • Include all classes All xhtml files All images, javascript, css All descriptors, e.g. Bean.xml, web.xml, faces-config.xml All Maven dependencies
  • You can use whichever driver that is supported by Drone Firefox Chrome Internet Explorer Android We didn't test OperaDriver yet
  • Althought simple webdriver test might look like this, it's is better to use page factory pattern for creating tests
  • Do you still remember mobile version of RichRates? If we implemented test using page objects, such a object could Select a date Insert an amount Click the “Calculate” button Select a currency Swap currencies Verify the result of calculation
  • I focus on emulators because we need to run our tests in continuous integration server (Jenkins) and physical devices don't scale
  • As you could see, it is not very fast, mainly because it is an emulator – it emulate an ARM processor. However, there is a solution which can speed up your Android.
  • You can download several prepared images which you can install to a virtual machine, e.g. VirtualBox I tried both Android 3.2 and 4.0 4.0 latest release doesn't work, can be installed but cannot be started Nightly build of 4.0 works like a charm I used an image for Asus EEE, it's netbook but I set up it to have lower resolution so it behaves like a mobile phone It's not ARM but good enough for testing web Fast !!! Unfortunately not as fast as desktop browsers
  • The only drawback is that it sends user agent string as a tablet so e.g. Google serves you a tablet version of search
  • Android-server-2.6.0.apk for Android 2.2,2.3 Android-server-newest.apk for Android 3+
  • Arquillian TestNG tests are fully supported by TestNG Eclipse plugin so it's possible to run whole test suite, selected class or selected method
  • Since TestNG is supported well in Eclipse, debugging is very easy. One can debug tests running in both emulator and android-x86
  • Android eclipse plugin helps a lot with creating new emulators, starting them etc However, it is manual process. Karel created Arq extension that can automate also this part of testing. It was created last week so it's still hot. Unfortunately, we didn't manage to integrate it to RichRates application.
  • Unit tests should run very fast so it doesn't make sense to log which tests is running...it would slower test execution. On the other hand, functional tests usually run much longer (on Android even few seconds). We find it useful to be able to watch test execution progress, especially on Jenkins.
  • After method, always run Result status check Captures screenshots on all major browsers including Android Screenshot contains whole page, not only visible area Dalo by sa implementovat ako Testng listener?
  • Currently we use android plugin on Jenkins You need to install Android SDK on Jenkins slave We run a script that deploys android-server.apk and runs the application

RichFaces - Testing on Mobile Devices RichFaces - Testing on Mobile Devices Presentation Transcript

  • RichFaces – Testing on Mobile Devices Pavol Pitoňák Quality Assurance Engineer, Red Hat 17 Feb 2012
  • Why Are We Doing This?
    • canalys.com
  •  
  • Testing a Java Web Application
    • Build archive
    • Start a container
    • Deploy archive
    • Open web browser
    • Run tests (continuously)
    • Review test results
  • RichRates
    • github.com/qa/richrates
    • richrates-ppitonak.rhcloud.com
    • richrates-ppitonak.rhcloud.com
    • richrates-ppitonak.rhcloud.com
    • richrates-ppitonak.rhcloud.com
    • richrates-ppitonak.rhcloud.com
    • richrates-ppitonak.rhcloud.com
  • Project Structure
    • Standard Maven structure
    • testng.xml
    • testng-ftest.xml
    • testng-all.xml
  • Running Unit Tests
      mvn clean package testng.xml
  • Running Functional Tests
      mvn clean package -P jbossas-managed-71,ftest testng-ftest.xml
  • Running All Tests
      mvn clean package -P jbossas-managed-71,all-tests testng-all.xml
  • Sample Unit Test
      public class UAgentInfoTest {
    • @Test
    • public void testIPad() {
    • Assert.assertTrue(...);
    • }
    • }
  • Sample Arquillian Test
      public class SkinBeanTest extends Arquillian {
    • @Inject private SkinBean skinBean;
    • @Deployment
    • public static JavaArchive createTestArchive() {
    • return ...;
    • }
    • @Test
    • public void testDefaultSkin() {
    • Assert.assertEquals(skinBean.getSkin(), "blueSky");
    • }
    • }
  • Sample WebDriver Test public class SampleTest extends Arquillian { @Drone public WebDriver driver; @ArquillianResource private URL deployedRoot; @Deployment public static WebArchive createTestArchive() { return ...; } @Test public void testDefaultSkin() { driver.get(“http://devconf.cz”); ... } }
  • Deployment
    • @Deployment(testable = false)
    • public static WebArchive createTestArchive() {
    • WebArchive war = ShrinkWrap.createFromZipFile(WebArchive.class, new File("target/richrates.war"));
    • }
    • ... or construct the WAR yourself :)
  • Deployment
    • @Deployment(testable = false)
    • public static WebArchive createTestArchive() {
    • WebArchive war = ShrinkWrap.createFromZipFile(WebArchive.class, new File("target/richrates.war"));
    • }
    • ... or construct the WAR yourself :)
  • Deployment 2
    • @Deployment(testable = false)
    • public static WebArchive createTestArchive() {
    • MavenDependencyResolver resolver = DependencyResolvers.use(MavenDependencyResolver.class).loadMetadataFromPom( "pom.xml");
    • WebArchive war = ShrinkWrap.create(WebArchive.class, "richrates.war");
    • war.addPackage("org.richfaces.examples.richrates");
    • war.addPackage("org.richfaces.examples.richrates.annotation");
    • war.addPackages(true, "org.slf4j");
    • war.merge(ShrinkWrap.create(ExplodedImporter.class, "tmp1.war").importDirectory("src/main/webapp").as(WebArchive.class));
    • war.merge(ShrinkWrap.create(ExplodedImporter.class, "tmp2.war").importDirectory("src/main/resources").as(WebArchive.class), "WEB-INF/classes");
    • war.addAsLibraries(resolver.artifact("org.richfaces.ui:richfaces-components-ui").resolveAsFiles());
    • war.addAsLibraries(resolver.artifact("org.richfaces.core:richfaces-core-impl").resolveAsFiles());
    • war.addAsLibraries(resolver.artifact("org.jdom:jdom").resolveAsFiles());
    • war.addAsLibraries(resolver.artifact("joda-time:joda-time").resolveAsFiles());
    • return war;
    • }
  • Arquillian.xml
    • <extension qualifier=&quot;webdriver&quot;>
    • <property name=&quot;implementationClass&quot;> org.openqa.selenium.firefox.FirefoxDriver </property>
    • </extension>
    • -Darquillian.browser.implementation.class=...
  • Arquillian.xml
    • Define your containers
    • Maven profiles
  • Sample WebDriver Test public class SampleTest extends Arquillian { @Drone public WebDriver driver; @ArquillianResource private URL deployedRoot; @Deployment public static WebArchive createTestArchive() { return ...; } @Test public void testDefaultSkin() { driver.get(“http://devconf.cz”); ... } }
  • Page Factory
    • @Test
    • public void googleSearchTest {
    • WebDriver driver = ...
    • driver.get(&quot;http://www.google.com/&quot;);
    • GoogleSearchPage page = PageFactory.initElements(driver,GoogleSearchPage.class);
    • page.searchFor(&quot;Cheese&quot;);
    • }
    • Page Factory
  • Page Object
    • public class CalculatorPage extends AbstractPage {
    • @FindBy(id = &quot;calculator:amount&quot;)
    • private WebElement amountInput;
    • @FindBy(xpath = &quot;//div[contains(@class, 'result')]&quot;)
    • private WebElement resultOutput;
    • @FindBy(id = &quot;calculator:calculateButton&quot;)
    • private WebElement submitButton;
    • ...
    • }
  • Mobile Web Testing
    • Almost no changes in Arquillian config
    • Android 1.x not supported
    • Android 2.x – phones
    • Android 3.x – tablets
    • Android 4.x – phones and tablets
    • Physical device vs. emulator
  • Physical Devices
    • Windows – install USB drivers
    • Linux – set up udev
    • Mac OS X – no setup needed
  • Android Emulator
    • Part of Android Software Development Kit
    • Android 1.5 – 4.0.3
    • <sdk_path>/tools/android
    • Eclipse plugins
  • Emulators
    • 2.2
      • Relatively fast
      • Works with selenium-server 2.6
    • 2.3
      • Unreliable
    • 3.x
      • Slow
    • 4.x
      • Relatively fast
      • Works well with newest Selenium
  • Demo Creating and launching a new emulator
  • Android-x86 Project
    • www.android-x86.org
    • Project porting Android to x86 platform
  • Demo Launching Android in VirtualBox
  • AndroidDriver Config
    • <extension qualifier=&quot;webdriver&quot;>
    • <property name=&quot;implementationClass&quot;> org.openqa.selenium.android.AndroidDriver </property>
    • <property name=&quot;remoteAddress&quot;>
    • http://localhost:4444/wd/hub
    • </property>
    • </extension>
  • Emulator Configuration
    • Install android-server.apk
    • Launch WebDriver application in emulator
    • platform-tools/adb forward tcp:4444 tcp:8080
    • Use 10.0.2.2 for host's localhost
  • VirtualBox Configuration
    • Set up network
    • platform-tools/adb connect <android_ip>
    • Install android-server.apk
    • Launch WebDriver application in emulator
    • platform-tools/adb forward tcp:4444 tcp:8080
    • Tests need server IP address
  • Demo Tests running with Firefox, Android emulator and Android-x86
  • Fast, Faster, Fastest
  • Eclipse
    • Plugins
      • Android
      • JBoss Tools
      • m2e
      • TestNG
    • Supports both emulator and Android-x86
  • Demo Running tests in Eclipse
  • Debugging
    • You already know how :)
  • Demo Debugging
  • Arquillian Android Extension
    • github.com/kpiwko/arquillian-extenstion-android
    • Hot news!
    • Create emulator
    • Start emulator
    • Install Android server
    • Start Android server
    • Can connect to real device
  • Console Logging Listener
    • Usual console log:
  • Console Logging Listener
    • Our console log:
    • [10:47:54] STARTED: ftest.ExchangeRatesTest.testInit()
    • [10:47:54] SUCCESS: ftest.ExchangeRatesTest.testInit()
    • [10:47:55] STARTED: ftest.ExchangeRatesTest.testNextAndPrevious()
    • [10:47:57] SUCCESS: ftest.ExchangeRatesTest.testNextAndPrevious()
    • [10:48:09] STARTED: ftest.CalculatorTest.testCalculate()
    • [10:48:12] SUCCESS: ftest.CalculatorTest.testCalculate()
  • Console Logging Listener
    • Register in pom.xml or in test class
    • @Listeners(ConsoleStatusTestListener.class)
    • public abstract class AbstractWebDriverTest<P extends Page> extends Arquillian {
    • ...
    • }
  • Screenshot on Failure
    • @AfterMethod(alwaysRun = true, groups = &quot;arquillian&quot;)
    • public void handleTestError(ITestResult result) {
    • if (result.getStatus() == ITestResult.SUCCESS) {
    • return;
    • }
    • ...
    • File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
    • FileUtils.copyFile(scrFile, imageOutputFile);
    • }
  • Jenkins Android Plugin
  • Jenkins Android Plugin
  • Mobile Browser Simulator
    • JBoss Tools 3.3 M5
    • Simulates mobile phones and tablets
    • Perfect for layout testing
    • Not for automation
  • Mobile Browser Simulator
  • Conclusion
    • Arquillian + Selenium 2
    • Run from console and Eclipse
    • How to create Android emulator
    • Android-x86
    • Emulator snapshots
    • ID locators, Xpath locators, CSS locators
  • [email_address] @ppitonak jboss.org/richfaces Q/A