在我的代码从另一个类调用函数的位置从命令行运行我的脚本时获取配置失败。
我正在使用Eclipse Neon 2,Selenium Webdriver和Testng。
当我从eclipse执行它时,我的脚本运行正常。当我删除那些函数调用并在命令行执行时在同一个类中添加相应的代码时,它也可以正常工作,但是当我尝试执行时它会失败并且这些函数调用来自命令行或.bat文件的脚本。
在我的项目结构下面看起来像;
我在包中有3个不同的类
Testing
Survey
selection (package)
-Class Variable_cfg (this is to define different variables)
-Class Reuse_fuctions (I am adding all re-useable functions like send_email into this)
-Class Main_test (this is main test, I will have many like this in future)
public class Variable_cfg()
{
public static void variables() {....}
}
public class Reuse_functions()
{
public static void sendMail() {...}
public static String generateRandomChars() throws IOException {}
public static void clickScreenshot(String filename, WebDriver driver) throws IOException {}
public static void startDeleting() throws IOException {}
}
public class Main_test()
{
@Parameters({ "browser" })
@BeforeTest
public void openbrowser(String browser) throws IOException {}
@DataProvider(name = "runtimeparams")
@BeforeTest
public Object[][] createData1() {}
@Test(priority=1,groups={"Chrome","Firefox","IE"},dataProvider="runtimeparams")
public void runtest(String env) throws IOException {
//here I am calling functions from Reuse_Functions class like
selection.Reuse_functions.generateRandomChars()...}
@AfterMethod
public void exittest(ITestResult result){
//here I am calling functions from Reuse_Functions class like
selection.Reuse_functions.sendMail()
}
如果你能帮助我找到解决方案。谢谢!
以下是我的NIA_Main.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="false" >
<test name="Test01">
<parameter name="browser" value="Chrome" />
<classes>
<class name="selection.Main_test" />
</classes>
</test>
</suite> <!-- Suite -->
我的bat文件看起来像
set ProjectPath=C:\Users\*******\workspace\Testing
set classpath=%ProjectPath%\bin;%ProjectPath%\Lib\*
java org.testng.TestNG %ProjectPath%\NIA_Main.xml
我正在尝试创建一个bat文件,因为我想让其他功能QAs执行。否则我通过命令行运行它,我在执行它之前设置了projectath和classpath变量。