writing my first test. agenda introduction – selenium & perfecto mobile get up and running...
Post on 22-Dec-2015
235 Views
Preview:
TRANSCRIPT
Writing My First Test
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)
MobileCloud Web Driver Architecture
Mobile web driver Java code
Running in Eclipse
HTTP command level
API MCM
HTTPHSS
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
MobileCloud Class Relations Diagram
MobileCloud Web Driver
Mobile Device
Web Driver DOM Native Visual
Web Element
Keyboard
Touch Screen
Timers
Virtual Network
Vitals
Reservation
Pre-requisites
• Eclipse Working environment• MobileCloud for Eclipse plugin
MobileCloud Plugin and Credentials
• Setup your MobileCloud credentials– New project wizard– Workspace settings
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
MobileCloud Project Template MobileTest
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
Select Device
1
2
3
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
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
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
Understanding the test
• Select Device• Open device• Home• Browser go to• Edit set text X2• Button click• Text checkpoint• Close device
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();
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);
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();
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");
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
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();
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"));
Validations and Validation Parameters
• Sync and Check are Validations
• Timeout is a Validation Parameter
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
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
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);
}}
Saving your Media files
• Repository folders– Public– Group– Private
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);}
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
Thank You
top related