简体   繁体   English

如何使用selenium和java中的testng从另一个class获取字符串值

[英]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.

相关问题 如何在硒webdriver中从一个java类(页面)到另一个TestNG类(test)调用下拉值? - How to call dropdown value from one java class(page) to another TestNG class(test) in selenium webdriver? 如何在Java中使用TestNG将字符串从主类传递到另一个类? - How can I pass a string from main class to another class using TestNG in java? 如何为硒脚本从另一个类文件传递字符串值 - How to pass string value from another class file for selenium script 使用TestNG和Java从另一个类调用方法 - Calling a method from another class using TestNG and Java 如何使用testNG从Selenium中的xml中传递单选按钮值 - how to pass radio button value from xml in selenium using testNG 我如何从Java集获取返回值 <String> 在java的另一个类中 - how i can get the return value from java set<String> in another class in java 尝试从另一个 class Java Selenium Z0F10ECB77876532AE8AZAE1B48 调用方法后出现 NullPointerException 错误 - NullPointerException error after trying to call a method from another class Java Selenium TestNG 在Java中使用TestNG在另一个类中调用方法 - Calling a Method in another class using TestNG in Java 如何从中获取价值<h1>在 Selenium WebDriver、Java 中使用类标记 - How to get value from <h1> tag using class in Selenium WebDriver, Java 如何在Java中将字符串值从一个类调用到另一个类 - How to call String value from one class to another in Java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM