Ready for demo
git-svn-id: svn://10.0.0.236/trunk@228752 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* ConditionMet.java
|
||||
*
|
||||
* Created on June 26, 2007, 2:12 PM
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: Condition.java,v 1.1 2007-06-26 12:39:04 edburns%acm.org Exp $
|
||||
*/
|
||||
|
||||
/*
|
||||
* The contents of this file are subject to the terms
|
||||
* of the Common Development and Distribution License
|
||||
* (the License). You may not use this file except in
|
||||
* compliance with the License.
|
||||
*
|
||||
* You can obtain a copy of the License at
|
||||
* https://javaserverfaces.dev.java.net/CDDL.html or
|
||||
* legal/CDDLv1.0.txt.
|
||||
* See the License for the specific language governing
|
||||
* permission and limitations under the License.
|
||||
*
|
||||
* When distributing Covered Code, include this CDDL
|
||||
* Header Notice in each file and include the License file
|
||||
* at legal/CDDLv1.0.txt.
|
||||
* If applicable, add the following below the CDDL Header,
|
||||
* with the fields enclosed by brackets [] replaced by
|
||||
* your own identifying information:
|
||||
* "Portions Copyrighted [year] [name of copyright owner]"
|
||||
*
|
||||
* [Name of File] [ver.__] [Date]
|
||||
*
|
||||
* Copyright 2005 Sun Microsystems Inc. All Rights Reserved
|
||||
*/
|
||||
|
||||
package org.mozilla.mcp;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author edburns
|
||||
*/
|
||||
public class Condition {
|
||||
|
||||
protected boolean conditionMet = false;
|
||||
public boolean isConditionMet() {
|
||||
return conditionMet;
|
||||
}
|
||||
|
||||
public void setConditionMet(boolean newValue) {
|
||||
conditionMet = newValue;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: MCP.java,v 1.15 2007-06-26 11:29:27 edburns%acm.org Exp $
|
||||
* $Id: MCP.java,v 1.16 2007-06-26 12:39:04 edburns%acm.org Exp $
|
||||
*/
|
||||
|
||||
/*
|
||||
@@ -403,6 +403,17 @@ public class MCP {
|
||||
*/
|
||||
|
||||
public Element findElement(String id) {
|
||||
currentElement = findElementById(id);
|
||||
if (null == currentElement) {
|
||||
Document dom = getCurrentPage().getDOM();
|
||||
|
||||
currentElement = getDOMTreeDumper().findFirstElementWithName(dom, id);
|
||||
}
|
||||
|
||||
return currentElement;
|
||||
}
|
||||
|
||||
public Element findElementById(String id) {
|
||||
Document dom = getCurrentPage().getDOM();
|
||||
try {
|
||||
currentElement = dom.getElementById(id);
|
||||
@@ -410,10 +421,6 @@ public class MCP {
|
||||
catch (Exception e) {
|
||||
|
||||
}
|
||||
if (null == currentElement) {
|
||||
currentElement = getDOMTreeDumper().findFirstElementWithName(dom, id);
|
||||
}
|
||||
|
||||
return currentElement;
|
||||
}
|
||||
|
||||
@@ -440,27 +447,17 @@ public class MCP {
|
||||
|
||||
}
|
||||
|
||||
public void appendToCurrentElementText(String toAppend) {
|
||||
public void appendKeyCodeToCurrentElementText(int keyCode) {
|
||||
if (null == currentElement) {
|
||||
throw new IllegalStateException("You must find an element before you can set its text.");
|
||||
}
|
||||
|
||||
int i,len,x,y;
|
||||
Robot robot = getRobot();
|
||||
len = toAppend.length();
|
||||
for (i = 0; i < len; i++) {
|
||||
}
|
||||
|
||||
// PENDING(edburns): make it so each character in toAppend
|
||||
// is translated into a keyCode.
|
||||
if (toAppend.equals("8")) {
|
||||
robot.keyPress(KeyEvent.VK_8);
|
||||
robot.keyRelease(KeyEvent.VK_8);
|
||||
}
|
||||
if (toAppend.equals("0")) {
|
||||
robot.keyPress(KeyEvent.VK_0);
|
||||
robot.keyRelease(KeyEvent.VK_0);
|
||||
}
|
||||
robot.keyPress(keyCode);
|
||||
robot.keyRelease(keyCode);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -676,14 +673,20 @@ public class MCP {
|
||||
requestFocus();
|
||||
}
|
||||
|
||||
public void waitUntilTextPresent(String textToFind) {
|
||||
public boolean waitUntilConditionMet(Condition condition) {
|
||||
boolean found = false;
|
||||
long
|
||||
maxWait = getTimeout(),
|
||||
timeWaited = 0,
|
||||
waitInterval = getTimeoutWaitInterval();
|
||||
try {
|
||||
|
||||
Thread.currentThread().sleep(3000);
|
||||
} catch (InterruptedException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
while (!(found = getCurrentPage().find(textToFind, true, true))) {
|
||||
while (!(found = condition.isConditionMet())) {
|
||||
try {
|
||||
Thread.currentThread().sleep(waitInterval);
|
||||
timeWaited += waitInterval;
|
||||
@@ -696,6 +699,7 @@ public class MCP {
|
||||
}
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
private void requestFocus() {
|
||||
|
||||
Reference in New Issue
Block a user