从项目上传文件 - Selenium WebDriver Visual Studio 2010 C#

Upload File from Project - Selenium WebDriver Visual Studio 2010 C#

你知道我是否可以使用带有 VisualStudio10 的 Selenium WebDriver 将文件上传到网页,而无需在我的计算机中写入文件位置的路径。我的意思是,将此文件添加到项目中并从代码中调用它而无需编写文件路径。我需要它,例如,如果我的测试将由使用不同机器的人运行进行,他们不必用自己的路径重写文件路径,可以直接从项目上传而无需修改。不知道这是否清楚,但我尝试了。提前致谢!

埃尔班迪多

我会在编译时将文件配置为输出。 您可以通过在解决方案资源管理器中选择文件并打开属性面板来执行此操作。 将 Build Action 设置为 Embedded Resource

Copy to Output Directory 设置为 Copy if newer

您可以像这样引用文件:

string folder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string filePath = Path.Combine(folder, "file.txt");