假设您想从选项中选择
Pending
。你可以这样做:
WebElement option = driver.findElement(By.id("select_option_93"));
option.click();
以下代码给出了来自selenium驱动程序的perfecto设备连接
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import com.perfectomobile.selenium.api.IMobileDevice;
import com.perfectomobile.selenium.api.IMobileDriver;
import com.perfectomobile.selenium.api.IMobileWebDriver;
import com.perfectomobile.selenium.params.analyze.text.MobileTextMatchMode;
public class BofaApp_app extends PerfectoMobileBasicTest implements Runnable{
/*
*
* Class Name : PerfectoMobileBasicTest
* Author : Uzi Eilon <[email protected]>
* Date : Dec 6th 2013
*
* Description :
* Mobile Native application test
* The test open the BOFA app (on a real device) and looks for an ATM.
* This test contains IMobileWebDriver (extension to webdriver), which allows the to get native and visual objects on mobile app
*
*/
public BofaApp_app(IMobileDriver driver) {
super(driver);
}
@Override
public void execTest() {
IMobileDevice device = ((IMobileDriver) _driver).getDevice(_DeviceId);
device.open();
device.home();
IMobileWebDriver webDriver = _driver.getDevice(_DeviceId).getVisualDriver();
webDriver.findElement(By.linkText("Bofa")).click();
IMobileWebDriver init = _driver.getDevice(_DeviceId).getVisualDriver();
init.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
init.manageMobile().visualOptions().textMatchOptions().setMode(MobileTextMatchMode.LAST);
init.findElement(By.linkText("Account")).click();
webDriver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
webDriver.findElement(By.linkText("Save this online"));
webDriver.manageMobile().visualOptions().textMatchOptions().setMode(MobileTextMatchMode.LAST);
webDriver.findElement(By.linkText("Locations")).click();
webDriver.findElement(By.linkText("Find Bank of America ATMs"));
IMobileWebDriver zip = _driver.getDevice(_DeviceId).getVisualDriver();
zip.manageMobile().visualOptions().textMatchOptions().setMode(MobileTextMatchMode.LAST);
zip.findElement(By.linkText("zip code")).click();
sleep(2000);
zip.findElement(By.linkText("zip code")).click();
sleep(2000);
webDriver.manageMobile().visualOptions().textMatchOptions().setMode(MobileTextMatchMode.LAST);
webDriver.manageMobile().visualOptions().ocrOptions().setLevelsLow(120);
webDriver.findElement(By.linkText("Code")).sendKeys("02459");
zip.findElement(By.linkText("Done")).click();
zip.findElement(By.linkText("Go")).click();
webDriver.findElement(By.linkText("Newton MA"));
}
}*
public class Constants
{
/** Project Constants */
public static final String REPORT_LIB = "C:\\Test\\";
public static final String HTML_REPORT_NAME = "Total.html";
public static final String PM_USER = "[email protected]";
public static final String PM_PASSWORD = "*************";
public static final String PM_CLOUD = "prerelease.perfectomobile.com";
}
public interface ExecutionReporter {
/*
*
* Class Name : ExecutionReporter
* Author : Uzi Eilon <[email protected]>
* Date : Dec 6th 2013
*
* Description :
* Reporter allows you to build an summary report which aggregate all the executions the results and the link for the specific test report
* You can find an HTML reporter in this project
*
*/
public void reportHeader (String title);
public void addLine(String testName,String deviceID,String repID,boolean status);
public void closeRep();
}
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
/*
*
* Class Name : HTMLReporter
* Author : Uzi Eilon <[email protected]>
* Date : Dec 6th 2013
*
* Description :
* implements ExecutionReporter and create an HTML summary report
*
*/
public class HTMLReporter implements ExecutionReporter {
BufferedWriter _bw = null;
public HTMLReporter (String title )
{
reportHeader(title);
}
public void reportHeader (String title)
{
String repName = Constants.REPORT_LIB+ Constants.HTML_REPORT_NAME;
File f = new File (repName) ;
try {
_bw = new BufferedWriter(new FileWriter(f));
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Calendar cal = Calendar.getInstance();
_bw.write("<p> Date :"+dateFormat.format(cal.getTime())+" </p>");
_bw.write("<p> Test Name: "+title+"</p>");
_bw.write("<p>");
_bw.write("<p>");
_bw.write("<table border=\"1\">");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void addLine(String testName,String deviceID,String repID,boolean status)
{
try {
_bw.write("<tr>");
_bw.write("<td>"+testName+"</td>");
_bw.write("<td>"+deviceID+"</td>");
_bw.write("<td> <a href=\""+repID+"\">Report</a></td>");
_bw.write("<td>"+status+"</td>");
_bw.write("</tr>");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void closeRep()
{
try {
_bw.write("</table></p></body></html>");
_bw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
import java.lang.reflect.Constructor;
import com.perfectomobile.selenium.*;
import com.perfectomobile.selenium.api.*;
public class MobileTest {
/*
*
* Class Name : MobileTest
* Author : Uzi Eilon <[email protected]>
* Date : Dec 6th 2013
*
* Description :
* Mobile Executer gets list of test and devices and execute it on the available devices
* in this example the list arrive form array [] []
* The tests run on real devices in Perfecto Mobile cloud
*/
public static void main(String[] args) {
System.out.println("Script started");
String host = Constants.PM_CLOUD;
String user = Constants.PM_USER;
String password = Constants.PM_PASSWORD;
String[] [] testcase ={
// {"PerfectoTestCheckFlight","3230D2D238BECF6D"},
// {"PerfectoTestCheckFlight","4A8203C8DBAB382EE6BB8021B825A736CA734484"},
{"BofaApp_app","4A8203C8DBAB382EE6BB8021B825A736CA734484"},
// {"usAirways","3230D2D238BECF6D"}
};
ExecutionReporter reporter = new HTMLReporter("Regression Test Tesults");
try {
for(int i =0; i < testcase.length; i++)
{
IMobileDriver driver = new MobileDriver(host, user, password);
String className = testcase[i][0];
String device = testcase[i][1];
PerfectoMobileBasicTest test = null;
Constructor con = null;
try {
con = Class.forName(className).getConstructor(IMobileDriver.class);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
test = (PerfectoMobileBasicTest)con.newInstance(driver);
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
//PerfectoMobileBasicTest test = new PerfectoTestCheckFlight(driver);
test.setDeviceID(device);
Thread t = new Thread(test);
t.start();
reporter.addLine(className,device,test.getRepName(),test.getStatus());
}
} catch (Exception e) {
e.printStackTrace();
} finally {
reporter.closeRep();
}
}
}
import java.io.File;
import java.io.InputStream;
import com.perfectomobile.httpclient.MediaType;
import com.perfectomobile.httpclient.utils.FileUtils;
import com.perfectomobile.selenium.api.IMobileDriver;
/*
*
* Class Name : PerfectoMobileBasicTest
* Author : Uzi Eilon <[email protected]>
* Date : Dec 6th 2013
*
* Description :
Basic abstract perfecto mobile test - Each test need to extend this class and implement the actual test in the PerfectoMobileBasicTest
* This basic test handles the driver and the device
*/
public abstract class PerfectoMobileBasicTest implements Runnable{
String _DeviceId = null;
IMobileDriver _driver;
boolean _status = true;
@Override
public void run() {
try
{
execTest();
}catch (Exception e)
{
_status = false;
}
closeTest();
getRep(MediaType.HTML);
}
public PerfectoMobileBasicTest (IMobileDriver driver)
{
_driver = driver;
}
public Boolean getStatus() {
return _status ;
}
public void setDeviceID(String Device) {
_DeviceId= Device;
}
public String getRepName() {
String className = this.getClass().getName();
String name = Constants.REPORT_LIB+className+_DeviceId+".HTML";
return name;
}
public void getRep(MediaType Type) {
InputStream reportStream = ((IMobileDriver) _driver).downloadReport(Type);
if (reportStream != null) {
File reportFile = new File(getRepName());
FileUtils.write(reportStream, reportFile);
}
}
public void sleep(long millis) {
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
}
}
public void closeTest( ) {
_driver.quit();
}
public abstract void execTest() throws Exception ;
}*
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import com.perfectomobile.selenium.api.IMobileDevice;
import com.perfectomobile.selenium.api.IMobileDriver;
import com.perfectomobile.selenium.api.IMobileWebDriver;
/*
*
* Class Name : PerfectoTestCheckFlight
* Author : Uzi Eilon <[email protected]>
* Date : Dec 6th 2013
*
* Description :
* Mobile web test
* the test go to united.com (on a real device) and check the status of flights number 84
* it use a web driver which connected to Perfecto Mobile cloud.
* the test is based on a webDriver test
*/
public class PerfectoTestCheckFlight extends PerfectoMobileBasicTest implements Runnable{
public PerfectoTestCheckFlight(IMobileDriver driver) {
super(driver);
}
@Override
public void execTest() {
IMobileDevice device = ((IMobileDriver) _driver).getDevice(_DeviceId);
device.open();
device.home();
//device.getScreenText()
//device.checkpointText("search");
WebDriver webDriver = device.getDOMDriver ("www.united.com");
webDriver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
webDriver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);
//sleep(2000);
question?
String url = webDriver.getCurrentUrl();
String title = webDriver.getTitle();
System.out.println("url: " + url + ", title: " + title);
WebElement webElement = webDriver.findElement(By.xpath("(//#text)[53]"));
webElement.click();
webElement = webDriver.findElement(By.xpath("(//@id=\"FlightNumber\")[1]"));
webElement.sendKeys("84");
webDriver.findElement(By.xpath("(//INPUT)[5]")).click();
}*
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Supported Documents</title>
<style>
body {
font-family: Arial, sans-serif;
}
.container {
width: 80%;
margin: auto;
padding-top: 20px;
}
h1 {
color: #333;
}
ul {
list-style: none;
padding: 0;
}
li {
margin-bottom: 10px;
}
.alphabet-nav {
position: fixed;
top: 20px;
right: 50px;
background: #f7f7f7;
padding: 10px;
border-radius: 5px;
}
.alphabet-nav a {
text-decoration: none;
padding: 5px;
display: inline-block;
color: #007bff;
}
section {
margin-top: 20px;
}
</style>
</head>
<body>
<div class="container">
<h1>Full List of Supported Documents</h1>
<div class="alphabet-nav">
<a href="#C">C</a>
<a href="#I">I</a>
<a href="#U">U</a>
</div>
<section>
<h2>Canada 🇨🇦</h2>
<ul>
<li>Driver License</li>
<li>Identification Card</li>
<li>Passport</li>
<li>Residence Permit</li>
</ul>
</section>
<section>
<h2>India 🇮🇳</h2>
<ul>
<li>Passport</li>
</ul>
</section>
<section>
<h2>United Kingdom 🇬🇧</h2>
<ul>
<li>Driver License</li>
<li>Passport</li>
<li>Residence Permit Card</li>
</ul>
</section>
<section>
<h2>United States 🇺🇸</h2>
<ul>
<li>Driver License</li>
<li>Identification Card</li>
<li>Passport</li>
<li>Passport Card</li>
<li>Permanent Resident Card</li>
</ul>
</section>
</div>
</body>
</html>