我有三个程序,
首先进行硒测试
import com.thoughtworks.selenium.*;
import java.util.regex.Pattern;
import junit.framework.*;
public class MyTest extends SeleneseTestCase {
int flag_eco;
public void setUp() throws Exception {
setUp("http://www.mysite.com/", "*iexplore");
}
public void testMyTest() throws Exception {
selenium.open("/pages/static/homepage_logout.html");
selenium.type("username", "myuser");
selenium.type("password", "password");
selenium.click("//input[@value='LOGIN']");
selenium.waitForPageToLoad("30000");
selenium.click("Confirm");
selenium.waitForPageToLoad("30000");
selenium.click("link=Applications");
selenium.waitForPageToLoad("30000");
selenium.click("link=Journey");
selenium.waitForPageToLoad("30000");
selenium.click("link=Launch Application (MUST BE LOGGED IN)");
selenium.waitForPageToLoad("30000");
if((selenium.isTextPresent("Please enter one of the following:")))
{
System.out.println("Journey Working Fine");
flag_test= 0;
}
else
{
System.out.println("Journey Failed");
flag_test = 1;
}
selenium.selectFrame("topmenu");
selenium.click("link=Home");
}
public static Test suite() {
//method added
return new TestSuite(MyTest.class);
}
public void tearDown(){
//Added . Will be called when the test will complete
selenium.stop();
}
}
然后sendmail从硒测试中获取值
import java.util.*;
public class SendMail
{
public void send()
{
MyTest Test = new MyTest();
if (Test.flag_test==1)
{
System.out.println("Journey Failed");
}
else if(Test.flag_test==0)
{
System.out.println("Journey Working Fine");
}
} }
主要类同时调用
import java.io.*;
import javax.servlet.*;
public class Test
{
public static void main(String args[])
{
MyTest tes = new MyTest();
junit.textui.TestRunner.run(tes.suite());
SendMail se = new SendMail();
se.send();
}
}
如何将标记值从MyTest传递到SendMail
答案 0 :(得分:1)
标志应该是public static
(我没有在你提供的代码中看到它定义) - 即。
public class MyTest {
public static int flag;
// the rest of the code
}
send()
{li> 您可以使用MyTest.flag_test
请注意,这不是传递数据的好方法,但在您的情况下,没有更好的方法。
我认为你正在做一些根本不应该做的事情。这就是我的建议:
SendMail
中。因此,您无需调用测试即可获得标记。
答案 1 :(得分:0)
实现这一目标的三种方法 1.将测试作为参数传递给SendMail(已提及) 2.在测试中编写一个监听器,(java中的Observable pattern / PropertyChangeSupport)并将其挂起。 (最佳IMO) 3.写入静态对象,该对象充当白板并从那里读取。 (一个穷人的消息队列)