TA的每日心情 | 开心 2018-9-2 15:58 |
---|
签到天数: 1 天 连续签到: 1 天 [LV.1]测试小兵
|
给个简单的例子吧:
1)功能代码,也就是你的登录和添加操作的代码:
//登录
package MyScript;
import com.thoughtworks.selenium.*;
public class Login{
public void myLogin(Selenium selenium){
selenium.open("/");
selenium.type("//input[@id='userId' and @value='' and @type='text']", "sgf");
selenium.type("id=password", "111111");
selenium.type("//input[@id='organization' and @value='' and @type='text']", "sgf");
selenium.click("name=submitForm");
}
}
//添加
package MyScript;
import com.thoughtworks.selenium.*;
public class CreateUC
{
public void myCreateUC(Selenium selenium){
selenium.waitForPageToLoad("30000");
System.out.println("CreateUC-1");
selenium.selectFrame("mainFrame");
selenium.selectFrame("commandlist");
selenium.click("//table[@id='urgentcast']/tbody/tr/td[2]/b");
selenium.selectFrame("relative=up");
selenium.selectFrame("detail");
selenium.waitForPageToLoad("30000");
selenium.selectFrame("ucToolbar");
selenium.click("id=newUrgentLink");
selenium.selectFrame("relative=up");
selenium.selectFrame("ucFrame");
selenium.selectFrame("ucList");
selenium.click("link=New Urgent Cast");
selenium.selectFrame("relative=up");
selenium.selectFrame("ucDetail");
selenium.waitForPageToLoad("30000");
selenium.type("id=name", "a");
//selenium.waitForPageToLoad("10000");
selenium.type("id=text", "aaaaaaaaaaaaaa");
selenium.select("id=selDurationSecond", "label=03");
selenium.selectFrame("relative=up");
selenium.selectFrame("relative=up");
selenium.selectFrame("ucToolbar");
selenium.click("id=saveLink");
System.out.println("CreateUC-2");
}
}
//创建一个selenium对象,去调用这两个方法(登录,添加)
package Test;
import MyScript.CreateUC;
import MyScript.Login;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;
import junit.framework.TestCase;
public class TestMyScript extends TestCase{
static Selenium selenium = null; //关键,一定要是静态的
public TestMyScript(String strFunctionName){
super(strFunctionName);
if (selenium == null) {//这个判断也很关键
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://192.168.2.100/");
selenium.start();
}
}
public void testLogin(){
Login login = new Login();
login.myLogin(selenium);
}
public void testCreateUC(){
CreateUC createUC = new CreateUC();
createUC.myCreateUC(selenium);
}
}
//加入testsuite
package Test;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
public class RunWithTestSuite{
public TestSuite testLogin(){
TestSuite suite = new TestSuite();
suite.addTest(new TestMyScript("testLogin"));
suite.addTest(new TestMyScript("testCreateUC"));
return suite;
}
public static void main(String[] args){
RunWithTestSuite myTestSuite = new RunWithTestSuite();
TestSuite suite = myTestSuite.testLogin();
TestRunner.run(suite);
}
} |
|