1、class类A代码如下。需要通过public static来修饰字符串变量。
public static String editTitleName;
public class BoYue {
WebDriver driver;
Actions action;
//需要传递的变量字符串参数editTitleName
public static String editTitleName;
public void editData() throws InterruptedException {
Thread.sleep(1500);
//点击修改按钮
driver.findElement(By.xpath("(//*[text()='修改'])[last()]")).click();
//修改舆情标题
Random random = new Random();
int randomT = random.nextInt(500);
//每次运行A方法给需要传递的字符串editTitleName 变量赋值
editTitleName = "修改自动化舆情标题" + randomT + "";
}
2、class类B代码如下,通过BoYue.editTitleName;BoYue类来调用字符串变量并传值给eName,
String eName= BoYue.editTitleName;
public class JiaoXuan {
@Test(priority = 2,dependsOnMethods = "com.xmt.entity.BoYue.issueData")
public void issueData() throws InterruptedException, IOException {
//通过BoYue类来直接调用editTitleName字符串变量
String eName= BoYue.editTitleName;
System.out.println("引用的参数为"+eName);
}
}
3、传递的前提条件是,BoYue类中的方法先运行,