![Page 1: Writing My First Test. Agenda Introduction – Selenium & Perfecto Mobile Get up and running with the MobileCloud WebDriver plugin –Download & setup Write](https://reader033.vdocuments.us/reader033/viewer/2022061616/56649d775503460f94a58c5d/html5/thumbnails/1.jpg)
Writing My First Test
![Page 2: Writing My First Test. Agenda Introduction – Selenium & Perfecto Mobile Get up and running with the MobileCloud WebDriver plugin –Download & setup Write](https://reader033.vdocuments.us/reader033/viewer/2022061616/56649d775503460f94a58c5d/html5/thumbnails/2.jpg)
Agenda
• Introduction – Selenium & Perfecto Mobile• Get up and running with the MobileCloud
WebDriver plugin– Download & setup
• Write our first test – Get introduced to some basic commands (14-22)– Add a validation at the end of the test (23)– Run, view and share report (images, run view,
video etc.) (24-28)
• References & Samples (29)
![Page 3: Writing My First Test. Agenda Introduction – Selenium & Perfecto Mobile Get up and running with the MobileCloud WebDriver plugin –Download & setup Write](https://reader033.vdocuments.us/reader033/viewer/2022061616/56649d775503460f94a58c5d/html5/thumbnails/3.jpg)
MobileCloud Web Driver Architecture
Mobile web driver Java code
Running in Eclipse
HTTP command level
API MCM
HTTPHSS
![Page 4: Writing My First Test. Agenda Introduction – Selenium & Perfecto Mobile Get up and running with the MobileCloud WebDriver plugin –Download & setup Write](https://reader033.vdocuments.us/reader033/viewer/2022061616/56649d775503460f94a58c5d/html5/thumbnails/4.jpg)
What’s new?
• The Selenium WebDriver has been extended to mobile• The new extension is called MobileDriver
– This is the initial access point to the MobileCloud Automation
• The IMobileDriver interface provides methods for:– Getting devices– Uploading/downloading items to/from the media repository– Downloading the execution report
• Use the quit method of the driver at the end of your test– Part of the code template that’s created as part of the
MobileCloud project
• Download the execution report after quitting the driver
![Page 5: Writing My First Test. Agenda Introduction – Selenium & Perfecto Mobile Get up and running with the MobileCloud WebDriver plugin –Download & setup Write](https://reader033.vdocuments.us/reader033/viewer/2022061616/56649d775503460f94a58c5d/html5/thumbnails/5.jpg)
MobileCloud Class Relations Diagram
MobileCloud Web Driver
Mobile Device
Web Driver DOM Native Visual
Web Element
Keyboard
Touch Screen
Timers
Virtual Network
Vitals
Reservation
![Page 6: Writing My First Test. Agenda Introduction – Selenium & Perfecto Mobile Get up and running with the MobileCloud WebDriver plugin –Download & setup Write](https://reader033.vdocuments.us/reader033/viewer/2022061616/56649d775503460f94a58c5d/html5/thumbnails/6.jpg)
Pre-requisites
• Eclipse Working environment• MobileCloud for Eclipse plugin
![Page 7: Writing My First Test. Agenda Introduction – Selenium & Perfecto Mobile Get up and running with the MobileCloud WebDriver plugin –Download & setup Write](https://reader033.vdocuments.us/reader033/viewer/2022061616/56649d775503460f94a58c5d/html5/thumbnails/7.jpg)
MobileCloud Plugin and Credentials
• Setup your MobileCloud credentials– New project wizard– Workspace settings
![Page 8: Writing My First Test. Agenda Introduction – Selenium & Perfecto Mobile Get up and running with the MobileCloud WebDriver plugin –Download & setup Write](https://reader033.vdocuments.us/reader033/viewer/2022061616/56649d775503460f94a58c5d/html5/thumbnails/8.jpg)
MobileCloud for Eclipse Plugin Interface
• How do I start?– The MobileCloud project template -
MobileTest– Getting to know the MobileCloud project
views– Opening devices– Record mode– Perfecto Mobile commands - an extension
of WebDriver
![Page 9: Writing My First Test. Agenda Introduction – Selenium & Perfecto Mobile Get up and running with the MobileCloud WebDriver plugin –Download & setup Write](https://reader033.vdocuments.us/reader033/viewer/2022061616/56649d775503460f94a58c5d/html5/thumbnails/9.jpg)
MobileCloud Project Template MobileTest
![Page 10: Writing My First Test. Agenda Introduction – Selenium & Perfecto Mobile Get up and running with the MobileCloud WebDriver plugin –Download & setup Write](https://reader033.vdocuments.us/reader033/viewer/2022061616/56649d775503460f94a58c5d/html5/thumbnails/10.jpg)
The MobileCloud Project views
• The MobileCloud project contains two views:– MobileCloud Recording
used for:• Opening devices • Recording operations
– MobileCloud Dashboardused for:
• Viewing devices during execution
![Page 11: Writing My First Test. Agenda Introduction – Selenium & Perfecto Mobile Get up and running with the MobileCloud WebDriver plugin –Download & setup Write](https://reader033.vdocuments.us/reader033/viewer/2022061616/56649d775503460f94a58c5d/html5/thumbnails/11.jpg)
Select Device
1
2
3
![Page 12: Writing My First Test. Agenda Introduction – Selenium & Perfecto Mobile Get up and running with the MobileCloud WebDriver plugin –Download & setup Write](https://reader033.vdocuments.us/reader033/viewer/2022061616/56649d775503460f94a58c5d/html5/thumbnails/12.jpg)
Writing a test on a MobileCloud device
• Record mode• Code refactoring
– For example:• Rename (Alt + Shift + r) - rename every
instance of a variable within your script • Extract local variable (Alt Shift + l)• Extract constant
![Page 13: Writing My First Test. Agenda Introduction – Selenium & Perfecto Mobile Get up and running with the MobileCloud WebDriver plugin –Download & setup Write](https://reader033.vdocuments.us/reader033/viewer/2022061616/56649d775503460f94a58c5d/html5/thumbnails/13.jpg)
Writing a test on a MobileCloud device
• Select Device according to device attributes, instead of a specific device ID– Device may be
busy or unavailable
– Easy to switch
How to do it Select Device function finds a device according to criteria Accepts multiple criteria & regex Value provided to open device command that makes device available for script Close device at end of script
![Page 14: Writing My First Test. Agenda Introduction – Selenium & Perfecto Mobile Get up and running with the MobileCloud WebDriver plugin –Download & setup Write](https://reader033.vdocuments.us/reader033/viewer/2022061616/56649d775503460f94a58c5d/html5/thumbnails/14.jpg)
Sample Script
• Create a new MobileCloud Project in Eclipse
• Add the sample java file to your project– Available here: http://
help.perfectomobile.com/article/AA-02842
• Open the dashboard to view the device• Run the test• Review the run results
– in report ("C:\test\report.pdf") and Eclipse console
![Page 15: Writing My First Test. Agenda Introduction – Selenium & Perfecto Mobile Get up and running with the MobileCloud WebDriver plugin –Download & setup Write](https://reader033.vdocuments.us/reader033/viewer/2022061616/56649d775503460f94a58c5d/html5/thumbnails/15.jpg)
Understanding the test
• Select Device• Open device• Home• Browser go to• Edit set text X2• Button click• Text checkpoint• Close device
![Page 16: Writing My First Test. Agenda Introduction – Selenium & Perfecto Mobile Get up and running with the MobileCloud WebDriver plugin –Download & setup Write](https://reader033.vdocuments.us/reader033/viewer/2022061616/56649d775503460f94a58c5d/html5/thumbnails/16.jpg)
Defining the MobileDriver
• Two ways to define a MobileDriver– Use the host, username and password
that were provided in the project preferences
– Use a different host, user and password
• Ensure the device is closed in the recording view when the latter constructor is used // The default empty constructor of MobileDriver should be used when running the code inside
Eclipse.// The user must have the ECLIPSE role in this case.// Otherwise, use the constructor that receives the host, user and password. E.g.// MobileDriver driver = new MobileDriver(host, user, password);MobileDriver driver = new MobileDriver();
![Page 17: Writing My First Test. Agenda Introduction – Selenium & Perfecto Mobile Get up and running with the MobileCloud WebDriver plugin –Download & setup Write](https://reader033.vdocuments.us/reader033/viewer/2022061616/56649d775503460f94a58c5d/html5/thumbnails/17.jpg)
Selecting devices for your test
• Use IMobileDriver• Method 1:
– Get a specific device, using the device ID
• Method 2:– Find a device according to device
attributes
IMobileDevice device = driver.getDevice("72B4463CF6DC2AFEF876A6B6F0131BD91C82650C");
device.open();
// work on the device
device.close();
MobileDeviceFindOptions options = new MobileDeviceFindOptions();
options.setOS(MobileDeviceOS.IOS);
IMobileDevice device = driver.findDevice(options);
![Page 18: Writing My First Test. Agenda Introduction – Selenium & Perfecto Mobile Get up and running with the MobileCloud WebDriver plugin –Download & setup Write](https://reader033.vdocuments.us/reader033/viewer/2022061616/56649d775503460f94a58c5d/html5/thumbnails/18.jpg)
Open device and Navigate Home
• Open device• Home
– Navigates device to idle screen– Unlocks device– Recommended to always use before
actual script begins
//Open the selected devicedevice.open();
//Navigate device to home screendevice.home();
![Page 19: Writing My First Test. Agenda Introduction – Selenium & Perfecto Mobile Get up and running with the MobileCloud WebDriver plugin –Download & setup Write](https://reader033.vdocuments.us/reader033/viewer/2022061616/56649d775503460f94a58c5d/html5/thumbnails/19.jpg)
The functions in our test
• Browser go to– Opens a URL– Browser parameter
options• OS –
Chrome/Safari/Explorer• Default – According to
what is set on the device• Perfecto Mobile –
Legacy browser//Browse to "http://nxc.co.il/demoaut/index.php" with OS native browser
IMobileWebDriver domDriver = device.getDOMDriver(MobileBrowserType.OS);
domDriver.get("http://nxc.co.il/demoaut/index.php");
![Page 20: Writing My First Test. Agenda Introduction – Selenium & Perfecto Mobile Get up and running with the MobileCloud WebDriver plugin –Download & setup Write](https://reader033.vdocuments.us/reader033/viewer/2022061616/56649d775503460f94a58c5d/html5/thumbnails/20.jpg)
The functions in our test
• Open the Object spy• Webpage.Element.Set
– Find the edit field element on the webpage using the name property
– Set the text
//Login to web application - set username and passwordWebElement nameElement = domDriver.findElement(By.name("username"));nameElement.sendKeys("John");
WebElement passwordElement = domDriver.findElement(By.name("password"));passwordElement.sendKeys("Perfecto1");c
![Page 21: Writing My First Test. Agenda Introduction – Selenium & Perfecto Mobile Get up and running with the MobileCloud WebDriver plugin –Download & setup Write](https://reader033.vdocuments.us/reader033/viewer/2022061616/56649d775503460f94a58c5d/html5/thumbnails/21.jpg)
The functions in our test
• Open the Object spy• Webpage.Element.Cli
ck– Find the button
element on the webpage using the text property
//click "Sign in" button
WebElement textElement = domDriver.findElement(By.linkText("Sign in"));
textElement.click();
![Page 22: Writing My First Test. Agenda Introduction – Selenium & Perfecto Mobile Get up and running with the MobileCloud WebDriver plugin –Download & setup Write](https://reader033.vdocuments.us/reader033/viewer/2022061616/56649d775503460f94a58c5d/html5/thumbnails/22.jpg)
The functions in our test
• Text Checkpoint– Validates text
appears on screen– Uses OCR to find
text– Timeout defines
how long to wait for text to appear
//Text checkpoint on "Welcome back John"
IMobileWebDriver visualDriver = device.getVisualDriver();
visualDriver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
visualDriver.findElement(By.linkText("Welcome back John"));
![Page 23: Writing My First Test. Agenda Introduction – Selenium & Perfecto Mobile Get up and running with the MobileCloud WebDriver plugin –Download & setup Write](https://reader033.vdocuments.us/reader033/viewer/2022061616/56649d775503460f94a58c5d/html5/thumbnails/23.jpg)
Validations and Validation Parameters
• Sync and Check are Validations
• Timeout is a Validation Parameter
![Page 24: Writing My First Test. Agenda Introduction – Selenium & Perfecto Mobile Get up and running with the MobileCloud WebDriver plugin –Download & setup Write](https://reader033.vdocuments.us/reader033/viewer/2022061616/56649d775503460f94a58c5d/html5/thumbnails/24.jpg)
How to work with functions
• Javadoc documentationhttp://www.perfectomobile.com/javadoc/
• Question mark links to online function reference– Each command has full documentation
of all parameters and usage
• Advanced parameters– Use only when needed– Allow customizations
![Page 25: Writing My First Test. Agenda Introduction – Selenium & Perfecto Mobile Get up and running with the MobileCloud WebDriver plugin –Download & setup Write](https://reader033.vdocuments.us/reader033/viewer/2022061616/56649d775503460f94a58c5d/html5/thumbnails/25.jpg)
Reports
• Each run generates a MobileCloud report– Can be shared and downloaded– Contain line by line breakdown of
execution– Some commands (e.g. checkpoint)
automatically generate screenshots in report
![Page 26: Writing My First Test. Agenda Introduction – Selenium & Perfecto Mobile Get up and running with the MobileCloud WebDriver plugin –Download & setup Write](https://reader033.vdocuments.us/reader033/viewer/2022061616/56649d775503460f94a58c5d/html5/thumbnails/26.jpg)
Reports cont.
• downloadReport() method– Used after calling driver.quit()
...MobileDriver driver = new MobileDriver();try {// write your code here} catch (Exception e) {
e.printStackTrace();} finally {
driver.quit();downloadReport(driver);
}}private static void downloadReport(IMobileDriver driver) {
InputStream reportStream = driver.downloadReport(MediaType.PDF);if (reportStream != null) {
File reportFile = new File("C:\\test\\report.pdf");FileUtils.write(reportStream, reportFile);
}}
![Page 27: Writing My First Test. Agenda Introduction – Selenium & Perfecto Mobile Get up and running with the MobileCloud WebDriver plugin –Download & setup Write](https://reader033.vdocuments.us/reader033/viewer/2022061616/56649d775503460f94a58c5d/html5/thumbnails/27.jpg)
Saving your Media files
• Repository folders– Public– Group– Private
![Page 28: Writing My First Test. Agenda Introduction – Selenium & Perfecto Mobile Get up and running with the MobileCloud WebDriver plugin –Download & setup Write](https://reader033.vdocuments.us/reader033/viewer/2022061616/56649d775503460f94a58c5d/html5/thumbnails/28.jpg)
Media files cont.
• downloadMedia()
• uploadMedia()
• deleteMedia()String repositoryKey = "PRIVATE:myImage.jpg";driver.deleteMedia(repositoryKey);
String repositoryKey = "PRIVATE:myImage.jpg";File file = new File("C:\\test\\images\\myImage.jpg");driver.uploadMedia(repositoryKey, file);
String repositoryKey = "PRIVATE:myImage.jpg";InputStream fileDownload = driver.downloadMedia(repositoryKey);if (fileDownload != null) { File file = new File("C:\\test\\images\\myImage.jpg"); FileUtils.write(fileDownload, file);}
![Page 29: Writing My First Test. Agenda Introduction – Selenium & Perfecto Mobile Get up and running with the MobileCloud WebDriver plugin –Download & setup Write](https://reader033.vdocuments.us/reader033/viewer/2022061616/56649d775503460f94a58c5d/html5/thumbnails/29.jpg)
References
• Setup guideshttp://help.perfectomobile.com/category/259– Video - Intro to MobileCloud WebDriver– Setup and Configuration Troubleshooting– Developing MobileCloud Automation Code
• Javadochttp://www.perfectomobile.com/javadoc/
• GitHub repositoryhttps://github.com/perfectomobile
![Page 30: Writing My First Test. Agenda Introduction – Selenium & Perfecto Mobile Get up and running with the MobileCloud WebDriver plugin –Download & setup Write](https://reader033.vdocuments.us/reader033/viewer/2022061616/56649d775503460f94a58c5d/html5/thumbnails/30.jpg)
Thank You