import org.testng.annotations.Test;
public class A{
private final static Logger log = LoggerFactory.getLogger(A.class);
public static String temp = "";
@Test
public static void someMethod(){
JavascriptExecutor btn = (JavascriptExecutor)driver;
btn.executeScript("document.getElementById('someBtn').click();");
// B.otherMethod is called
log.info("temp|"+temp);
}
}
-----------------------------------------------------------------
org.springframework.stereotype.Controller
@Controller
public class B{
@ResponseBody
@RequestMapping(value = "/public/something/othermehtod", method = RequestMethod.POST)
public otherMethod(){
A.temp = "helloworld";
}
}
如标题所示,
- 当我使用TestNG 运行这个类时
- 前端的按钮是click, B.otherMethod被调用
temp是空的,尽管我已经把它设置在b类中。我不明白为什么,希望有人能给它一些阴影。
注意事项:类A和类B是独立的java文件。otherMethod在前端被someemethod 调用import org.testng.annotations.Test;
public class A{
private final static Logger log = LoggerFactory.getLogger(A.class);
public static String otherMethod(){
return "helloworld";
}
@Test
public static void someMethod(){
String temp = otherMethod();
log.info("temp|"+temp);
}
}
通过直接在类A中声明该方法将打印helloworld。我希望这能对某人有所帮助。