[英]How to get string value from another class using selenium and testng in java
I'm trying to get the value of string in first class and use it to another class. Below is my code我试图在第一个 class 中获取字符串的值并将其用于另一个 class。下面是我的代码
public class Add extends driver { public static String reportV1; public class 添加扩展驱动程序 { public static String reportV1;
@Test
public String export() throws InterruptedException, IOException {
// Report Name
WebElement report1 = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#nReportName")));
reportV1 = report1.getAttribute("value");
if (reportV1.equals(reportV)) {
System.out.println(" PASSED - Report Name: " + reportV1);
} else {
System.out.println(" FAILED - Report Name: " + reportV1);
soft.assertTrue(false);
}
soft.assertAll();
return reportV1;
I'm new to java so can someone help me to get the value of string.我是 java 的新手,所以有人可以帮助我获取字符串的值。 Thank you in advance
先感谢您
I think you should read about static fields first to get clear picture about this thing.我认为您应该先阅读 static 字段,以清楚地了解这件事。 Anyway, static variables can be accessed by calling with the class name ClassName.VariableName.
总之,static个变量可以通过调用class这个名字ClassName.VariableName来访问。
Add.reportV1 in your case. Add.reportV1在你的情况下。 Btw in your example reportV1 is not initialized yet, fyi.
顺便说一句,在您的示例中, reportV1尚未初始化,仅供参考。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.