Kaydet (Commit) 428f563b authored tarafından Liu Zhe's avatar Liu Zhe

#120234# - testcommon enhancement: uno api test support, multiple instances support.

AppUtil.initApp is removed.  Should use VclApp.start in future test case development. e.g.
@Before
public void setUp() {
üst 00d282ea
......@@ -56,66 +56,15 @@ public class AppUtil extends Tester {
} else if (SystemUtil.isLinux()) {
}
// patch();
}
/**
* This method is used to start OpenOffice and make it ready for testing.
*
* @param cleanUserInstallation if use a totally clean user installation data
* @param userInstallation Specify user installation directory. If it's null, the default will be used.
*/
public static void initApp(boolean cleanUserInstallation, String userInstallation) {
File newUserInstallation = userInstallation == null ? app.getDefaultUserInstallation() : new File(fullPath(userInstallation));
if (!newUserInstallation.equals(app.getUserInstallation())) {
// user installation changed...
app.kill();
app.setUserInstallation(userInstallation == null ? null : newUserInstallation);
}
patch(cleanUserInstallation);
//try to reset application
for (int i = 0; i < 3; i++) {
try {
if (app.exists()) {
app.reset();
openStartcenter();
if (startcenter.exists(2))
return;
}
} catch (Exception e){
}
app.kill();
if (app.start() != 0)
throw new Error("OpenOffice can't be started! Testing aborted!");
sleep(3); // this sleep is important.
app.waitForExistence(30, 5);
}
}
/**
* @see initApp(boolean cleanUserInstallation, String userInstallation)
*/
public static void initApp(boolean cleanUserInstallation) {
initApp(cleanUserInstallation, System.getProperty("openoffice.userinstallation"));
}
/**
* @see initApp(boolean cleanUserInstallation, String userInstallation)
*/
public static void initApp() {
initApp(false);
}
public static void openStartcenter() {
if (startcenter.exists())
return;
if (SystemUtil.isMac()) {
SystemUtil.execScript("osascript -e 'tell app \"OpenOffice.org\" to activate'", false);
SystemUtil.execScript("osascript -e 'tell app \"OpenOffice.org\" to activate'");
typeKeys("<command n>");
}
......@@ -191,30 +140,6 @@ public class AppUtil extends Tester {
sleep(1);
}
/**
* In order to automatically test OO, some settings/files need to be modified
*/
public static void patch(boolean force) {
File userInstallationDir = app.getUserInstallation();
File patchMark = new File(userInstallationDir, "automationenabled");
if (!force && patchMark.exists())
return;
// remove user installation dir
app.kill();
sleep(1);
FileUtil.deleteFile(userInstallationDir);
app.start();
sleep(10);
app.kill();
sleep(1);
FileUtil.copyFile(new File("patch/Common.xcu"), new File(userInstallationDir, "user/registry/data/org/openoffice/Office/Common.xcu"));
FileUtil.copyFile(new File("patch/Setup.xcu"), new File(userInstallationDir, "user/registry/data/org/openoffice/Setup.xcu"));
FileUtil.copyFile(new File("patch/registrymodifications.xml"), new File(userInstallationDir, "user/registrymodifications.xcu"));
FileUtil.writeStringToFile(patchMark.getAbsolutePath(), "patched for automation");
}
public static void handleBlocker(final VclWindow... windows) {
new Condition() {
@Override
......
......@@ -26,13 +26,17 @@ package testlib;
import static org.openoffice.test.vcl.Tester.*;
import static testlib.UIMap.*;
import java.lang.reflect.Array;
import java.util.StringTokenizer;
import java.util.logging.Logger;
public class CalcUtil {
private static Logger LOG = Logger.getLogger(CalcUtil.class.getName());
/**
* Select a range.
*
......@@ -221,7 +225,34 @@ public class CalcUtil {
break;
}
}
LOG.info("Text of range [" + range + "]:\n" + arrayToString(texts));
return texts;
}
private static String arrayToString(Object array) {
if (array == null)
return "null";
if (!array.getClass().isArray())
return array.toString();
int len = Array.getLength(array);
String ret = "{";
for (int i= 0; i < len; i++) {
Object el = Array.get(array, i);
if (el == null) {
ret += "null";
} else if (el.getClass().isArray()) {
ret += arrayToString(el);
} else {
ret += "\"" + el + "\"";
}
if (i + 1 != len)
ret += ",";
}
ret += "}";
return ret;
}
}
\ No newline at end of file
......@@ -19,13 +19,10 @@
*
*************************************************************/
package testlib;
import java.io.File;
import java.io.IOException;
import java.util.logging.ConsoleHandler;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
......@@ -33,14 +30,14 @@ import java.util.logging.SimpleFormatter;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import org.openoffice.test.OpenOffice;
import org.openoffice.test.common.GraphicsUtil;
import org.openoffice.test.vcl.client.CommunicationException;
/**
* The class is used to capture extra information during the testing, including
* 1. Take a screenshot when testing is failed.
* 2. Collect data as the clue when oo crashes.
* 1. Take a screenshot when testing is failed. 2. Collect data as the clue when
* oo crashes.
*
*/
public class Log extends TestWatcher {
......@@ -48,24 +45,24 @@ public class Log extends TestWatcher {
static File logOutput = null;
static Logger logger;
static {
screenshotOutput = Testspace.getFile("output/screenshot");
screenshotOutput = Testspace.getFile("output/screenshot");
screenshotOutput.mkdirs();
logOutput = Testspace.getFile("output/logs");
logOutput.mkdirs();
try {
logger = Logger.getLogger("vclauto");
FileHandler fh = new FileHandler(logOutput.getAbsolutePath()+ "/" + "%u.log", true);
FileHandler fh = new FileHandler(logOutput.getAbsolutePath() + "/" + "%u.log", true);
logger.addHandler(fh);
logger.setLevel(Level.ALL);
SimpleFormatter sf = new SimpleFormatter();
fh.setFormatter(sf);
// ConsoleHandler ch = new ConsoleHandler();
// logger.addHandler(ch);
// logger.setLevel(Level.ALL);
// ch.setFormatter(sf);
// ConsoleHandler ch = new ConsoleHandler();
// logger.addHandler(ch);
// logger.setLevel(Level.ALL);
// ch.setFormatter(sf);
} catch (IOException e) {
//ignore;
// ignore;
}
}
......@@ -85,15 +82,15 @@ public class Log extends TestWatcher {
screenshotType = "error";
}
File file = new File(screenshotOutput, description.getClassName()+"."+description.getMethodName()+"." + screenshotType + ".png");
File file = new File(screenshotOutput, description.getClassName() + "." + description.getMethodName() + "." + screenshotType + ".png");
GraphicsUtil.screenShot(file.getAbsolutePath());
logger.log(Level.SEVERE, "Testing is failed. Screenshot: " + file.getAbsolutePath(), e);
// Check if crash occurs!
if (e instanceof CommunicationException) {
logger.severe("Pay attention! OpenOffice maybe crashed or freezed. ");
// If testcase is failed, kill AOO to avoid impacting the following test cases.
UIMap.app.kill();
// If testcase is failed, kill AOO to avoid impacting the following
// test cases.
OpenOffice.killAll();
}
}
......
......@@ -24,13 +24,17 @@
package testlib;
import java.io.File;
import org.openoffice.test.OpenOffice;
import org.openoffice.test.vcl.IDList;
import org.openoffice.test.vcl.client.Constant;
import org.openoffice.test.vcl.widgets.VclApp;
import org.openoffice.test.vcl.widgets.VclButton;
import org.openoffice.test.vcl.widgets.VclComboBox;
import org.openoffice.test.vcl.widgets.VclControl;
import org.openoffice.test.vcl.widgets.VclDialog;
import org.openoffice.test.vcl.widgets.VclDockingWin;
import org.openoffice.test.vcl.widgets.VclEditBox;
import org.openoffice.test.vcl.widgets.VclField;
import org.openoffice.test.vcl.widgets.VclListBox;
import org.openoffice.test.vcl.widgets.VclMenuItem;
import org.openoffice.test.vcl.widgets.VclMessageBox;
......@@ -39,8 +43,6 @@ import org.openoffice.test.vcl.widgets.VclTabControl;
import org.openoffice.test.vcl.widgets.VclTabPage;
import org.openoffice.test.vcl.widgets.VclToolBox;
import org.openoffice.test.vcl.widgets.VclWindow;
import org.openoffice.test.vcl.widgets.VclField;
import org.openoffice.test.vcl.widgets.VclDockingWin;
/**
* Define all UI controls in the class.
......@@ -49,9 +51,9 @@ import org.openoffice.test.vcl.widgets.VclDockingWin;
*/
public class UIMap {
private static IDList idList = new IDList(new File("./ids"));
public static final VclMessageBox ActiveMsgBox = new VclMessageBox(idList.getId("UID_ACTIVE"));
public static final VclMessageBox MsgBox_AdditionalRowsNotSaved = new VclMessageBox(idList.getId("UID_ACTIVE"), "Additional rows were not saved.");
public static final VclTabControl ActiveTabControl = new VclTabControl(idList.getId("UID_ACTIVE"));
public static final VclMessageBox ActiveMsgBox = new VclMessageBox(Constant.UID_ACTIVE);
public static final VclMessageBox MsgBox_AdditionalRowsNotSaved = new VclMessageBox(Constant.UID_ACTIVE, "Additional rows were not saved.");
public static final VclTabControl ActiveTabControl = new VclTabControl(Constant.UID_ACTIVE);
public static VclEditBox editbox(String id) {
return new VclEditBox(idList.getId(id));
......@@ -71,7 +73,7 @@ public class UIMap {
}
public static VclTabPage tabpage(String id) {
return new VclTabPage(idList.getId(id), ActiveTabControl);
return new VclTabPage(idList.getId(id));
}
public static VclListBox listbox(String id) {
......@@ -112,8 +114,8 @@ public class UIMap {
public static VclDockingWin dockingwin(String id){
return new VclDockingWin(idList.getId(id));
}
public static final VclApp app = new VclApp(null);
public static final OpenOffice oo = new OpenOffice(null);
public static final VclApp app = VclApp.getDefault();
public static final VclWindow writer = window("SW_HID_EDIT_WIN");
public static final VclWindow startcenter = window("FWK_HID_BACKINGWINDOW");
public static final VclWindow calc = window("SC_HID_SC_WIN_GRIDWIN");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment