Java字符串将存储值重置为null
我是Java新手,但在C#方面有3年的经验,我遇到了一个问题,即字符串不能保留其赋值(使用Getter/Setter方法) 我的对象类看起来是这样的Java字符串将存储值重置为null,java,getter-setter,encapsulation,Java,Getter Setter,Encapsulation,我是Java新手,但在C#方面有3年的经验,我遇到了一个问题,即字符串不能保留其赋值(使用Getter/Setter方法) 我的对象类看起来是这样的 public class filePathPojo { private String FilePath; public void setFilePath(String _Path){ this.FilePath = _Path; } public String getFilePa
public class filePathPojo {
private String FilePath;
public void setFilePath(String _Path){
this.FilePath = _Path;
}
public String getFilePath(){
return this.FilePath;
}
}
我有一个单独的类文件,有两种方法,一种是根据使用应用程序的用户创建具有唯一值的目录路由,然后使用集合存储路径,下一种方法是捕获屏幕截图并移动到新目录。每次screenshot方法运行并调用“Get”时,它都返回NULL!对于如此简单的事情来说,这是相当令人沮丧的
其他班级看起来也是这样
public class folderSetup extends filePathPojo {
public void SetupDirectory(String ScenarioName){
String Root = "C:\\Users\\" + SomeIdentifier + "\\GherkinEvidence\\SomeProject\\";
String Today = DateTime.now().toString("dd:MM:yyyy");
Today = Today.replace(":", "-");
String dtNOW = DateTime.now().toString("HH:mm:ss");
dtNOW = dtNOW.replace("/", "-").replace(":", "");
File file = new File(Root + Today + "\\" + dtNOW + " " + ScenarioName);
boolean dirCreated = file.mkdirs();
System.out.println("***Attemping To Create Directory: " + file.getAbsolutePath());
FilePath = file.getAbsolutePath();
setFilePath(FilePath);
}
public String takeScreenshot(String screenshotName, WebDriver driver){
String path = getFilePath();
System.out.print("Filepath for screenshot picked up is" + path);
try {
WebDriver augmentedDriver = new Augmenter().augment(driver);
File source = ((TakesScreenshot)augmentedDriver).getScreenshotAs(OutputType.FILE);
//path = "./target/screenshots/" + source.getName();
FileUtils.copyFile(source, new File(path + "\\" + screenshotName + ".png"));
}
catch(IOException e) {
//path = "Failed to capture screenshot: " + e.getMessage();
}
return path;
}
}
请问有人有什么想法吗?
方法在这里调用
包含的i步骤定义@Before(FolderSetup)
您调用了getFilePath(),但似乎以前没有在实例上调用setFilePath()。另外,我建议您阅读命名约定,在给定的
folderSetup
实例上,在takeScreenshot
之前调用SetupDirectory
吗?您好,是的,SetupDirectory是从Hook之前调用的,接下来就是屏幕截图。请记住,如果这是您的代码,它将永远不会编译,更不用说运行了。这是考试班吗?您使用的@Before注释是什么?在Java中,这不会编译:公共类性能测试可能您的测试配置不正确。我找不到在变量上而不是在方法上使用Inject的任何示例,也找不到关于您调用getFilePath()的注释的任何文档,但很可能您以前没有在实例上调用setFilePath()。另外,我建议您阅读命名约定,在给定的folderSetup
实例上,在takeScreenshot
之前调用SetupDirectory
吗?您好,是的,SetupDirectory是从Hook之前调用的,接下来就是屏幕截图。请记住,如果这是您的代码,它将永远不会编译,更不用说运行了。这是考试班吗?您使用的@Before注释是什么?在Java中,这不会编译:公共类性能测试可能您的测试配置不正确。我找不到在变量上而不是在方法上使用Inject的任何示例,也找不到任何关于注释的文档
Public Class PerformanceSteps{
@Inject private folderSetup folderSetup;
@Before
public void FolderSetup(Scenario scenario){
System.out.print("***Performing Evidence Directory Setup***");
System.out.println("ScenarioName = " + scenario.getName().toString() + "**");
folderSetup.SetupDirectory(scenario.getName());
}
}
public class Navigate extends BasePage {
@Inject private com.test.utilities.folderSetup folderSetup;
public void toAppianHomePage(){
System.out.println("Navigating to Appian URL " + LoadProperties.Appian_URL);
driver.navigate().to(LoadProperties.Appian_URL);
driver.manage().window().maximize();
folderSetup.takeScreenshot("Navigate Appian Home", driver);
}