简体   繁体   English

无法使用Selenium创建本地Windows目录结构

[英]Unable to create local windows directory structure using Selenium

Trying to follow the examples outlined here and here to ensure that the directory I'm putting my results reports in is always present for a given user. 尝试遵循此处此处概述的示例,以确保对于给定的用户始终存在要放入结果报告的目录。

new File(sampleFolder).mkdir();

Where sampleFolder is showing in the Eclipse debugger as "C:\\Users\\CurrentUser\\workspace\\Automation_Framework//Reports//output//TestCasesHtmlReports//" sampleFolder在Eclipse调试器中显示为“ C:\\ Users \\ CurrentUser \\ workspace \\ Automation_Framework // Reports // output // TestCasesHtmlReports //”

and is populated from the variable definition 并从变量定义中填充

public static String sampleFolder = System.getProperty("user.dir") + "//Reports//output//TestCasesHtmlReports//";

However when I run the script the folder structure is NOT being created, any ideas what I'm doing wrong? 但是,当我运行脚本时,没有创建文件夹结构,我在做什么错了吗? Do I need to run Eclipse as an administrator? 我需要以管理员身份运行Eclipse吗?

You need to make two changes: 您需要进行两项更改:

Change 1: 变更1:

You are inputting the slashes incorrectly. 您输入的斜杠不正确。 I am not sure how the '//' gets parsed. 我不确定如何解析“ //”。 On windows the "\\" gets resolved to a "\\" because the first backslash is used as a escape character. 在Windows上,“ \\”被解析为“ \\”,因为第一个反斜杠用作转义字符。

You could compose the File path in a standard way as below. 您可以按以下标准方式编写文件路径。 File.separator is Platform dependent default name-separator character as String. File.separator是依赖于平台的默认名称分隔符,为String。 For windows, it's '\\' and for unix it's '/' 对于Windows,它是“ \\”,对于Unix,它是“ /”

 public static String sampleFolder = System.getProperty("user.dir") + File.separator + "Reports" + File.separator + "output" + File.separator+ "TestCasesHtmlReports";

Information about Java separator's in this thread . 有关此线程中 Java分隔符的信息。

Change 2: 变更2:

You need to use File.mkdirs instead of File.mkdir 您需要使用File.mkdirs而不是File.mkdir

The problem is with the API you are using. 问题在于您使用的API。 File.mkdir Javadoc reads File.mkdir Javadoc读取

public boolean mkdir() 公共布尔mkdir()

Creates the directory named by this abstract pathname. 创建以此抽象路径名命名的目录。

Returns: 返回值:

true if and only if the directory was created; 当且仅当创建目录时为true;否则为true。 false otherwise 否则为假

File.mkdirs Javadoc reads File.mkdirs Javadoc读取

public boolean mkdirs() 公共布尔mkdirs()

Creates the directory named by this abstract pathname, including any necessary but nonexistent parent directories. 创建以此抽象路径名命名的目录,包括任何必需但不存在的父目录。 Note that if this operation fails it may have succeeded in creating some of the necessary parent directories. 请注意,如果此操作失败,则可能已成功创建了一些必要的父目录。

Returns: 返回值:

true if and only if the directory was created, along with all necessary parent directories; 当且仅当创建目录以及所有必要的父目录时才为true;否则为true。 false otherwise 否则为假

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM