|
所写代码:
import com.thoughtworks.selenium.*;
import org.testng.annotations.*;
import static org.testng.Assert.*;
import java.util.regex.Pattern;
import com.thoughtworks.selenium.SeleneseTestBase;
//extends SeleneseTestNgHelper
public class swpu extends SeleneseTestNgHelper{
public Selenium selenium = new DefaultSelenium("localhost", 8080, "*firefox", "http://www.swpu.edu.cn");
@Test public void testSwpu() throws Exception {
selenium.open("/");
selenium.clickAt("//div[@id='sasFlashFocus27']/embed[@id='27']", "");//媒体模块
selenium.click("//div[@id='imglinkone']/a[1]/img");//主页的 学生世界
clickAndSelectModalDialog("//div[@id='imglinkone']/a[1]/img");
selenium.mouseMoveAt("//div[@id='menudiv']/ul/li[1]/a", "");//学生世界页面
selenium.click("link=入学指南");
}
public void clickAndSelectModalDialog(String locator){
clickForModalDialog(locator);
selenium.selectWindow("name=modal");
}
private void clickForModalDialog(String locator){
String overrideShowModalDialogJs="if(selenium.browserbot.getCurrentWindow().showModalDialog){";
overrideShowModalDialogJs += "selenium.browserbot.getCurrentWindow().showModalDialog = function( sURL, vArguments, sFeatures)";
overrideShowModalDialogJs +="selenium.browserbot.getCurrentWindow().open(sURL, 'modal', sFeatures);";
overrideShowModalDialogJs += "};}";
//showModalDialog方法进行覆盖
selenium.getEval(overrideShowModalDialogJs);
selenium.openWindow("/page/yxc.shtml","modal");
selenium.waitForPopUp("modal","15000");
selenium.selectWindow("modal");
}
public void acceptModalValue(String locator,String[] values){
String overrideShowModalDialogJs="if(selenium.browserbot.getCurrentWindow().showModalDialog(){";
overrideShowModalDialogJs += "selenium.browserbot.getCurrentWindow().showModalDialog = function( sURL, vArguments, sFeatures)";
overrideShowModalDialogJs +="{ "+generateModalDialogReturnObject(values)+"return temp";
overrideShowModalDialogJs += "};}";
//showModalDialog方法进行覆盖
selenium.getEval(overrideShowModalDialogJs);
selenium.click(locator);
}
private String generateModalDialogReturnObject (String[] values){
StringBuffer returnObject=new StringBuffer();
returnObject.append("var temp=new Array();");
for(int i=0;i<values.length;i++){
returnObject.append("temp["+i+"]='"+values+"';");
}
return returnObject.toString();
}
/*//点击后弹出部门选择框的图片
String depChooseLocator="…/img";
<span style="color: rgb(0, 0, 0);">//点击并选中该弹出网页
clickAndSelectModalDialog(depChooseLocator);
</span>
//执行部门树的操作
//获取该对话框要返回给父页面的值
String name = selenium.getEval("window.seltree.GetAllCheckText();");
String id=selenium.getEval("window.seltree.GetAllNodeId();");
<span style="color: rgb(0, 0, 0);">//关闭部门选择对话框
closeModalDialog();
</span>
//返回父页面
selenium.selectWindow("name=main95598");
//组装返回值
String[] returnValues=new String[2];
returnValues[0]=name;
returnValues[1]=id;
//父页面获取对话框返回值
<span style="color: rgb(0, 0, 0);">
acceptModalValue(depChooseLocator, returnValues);
</span>
private void clickAndSelectModalDialog(String string) {
// TODO Auto-generated method stub
}
*/
}
控制台消息:
[Parser] Running:
C:\Documents and Settings\pliu\Local Settings\Temp\testng-eclipse\testng-customsuite.xml
[[TestNGClassFinder]] Unable to read methods on class swpu - unable to resolve class reference junit/framework/AssertionFailedError
java.lang.NoClassDefFoundError: junit/framework/AssertionFailedError
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetPublicMethods(Unknown Source)
at java.lang.Class.getMethods(Unknown Source)
at org.testng.internal.TestNGClassFinder.<init>(TestNGClassFinder.java:59)
at org.testng.TestRunner.initMethods(TestRunner.java:305)
at org.testng.TestRunner.init(TestRunner.java:251)
at org.testng.TestRunner.init(TestRunner.java:221)
at org.testng.TestRunner.<init>(TestRunner.java:183)
at org.testng.remote.RemoteTestNG$1.newTestRunner(RemoteTestNG.java:105)
at org.testng.remote.RemoteTestNG$DelegatingTestRunnerFactory.newTestRunner(RemoteTestNG.java:158)
at org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:551)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:241)
at org.testng.SuiteRunner.run(SuiteRunner.java:195)
at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:903)
at org.testng.TestNG.runSuitesLocally(TestNG.java:872)
at org.testng.TestNG.run(TestNG.java:780)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:75)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:127)
===============================================
selenium_M123
Total tests run: 0, Failures: 0, Skips: 0
===============================================
|
|