|
3#
楼主 |
发表于 2010-5-17 17:02:44
|
只看该作者
测试类
import com.thoughtworks.selenium.*;
import org.testng.annotations.*;
import static org.testng.Assert.*;
import java.util.regex.Pattern;
import com.thoughtworks.selenium.HttpCommandProcessor;
import com.thoughtworks.selenium.DefaultSelenium;
//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=入学指南");
selenium.wait(300000000);
//HttpCommandProcessor commandProcessor=new HttpCommandProcessor(null, 0, null, null);
//commandProcessor.executeCommandOnServlet(arg0);
}
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(locator,"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();
} |
|