Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/409.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用TestNG从Selenium中的主类调用全局方法到类_Javascript_Selenium Webdriver_Testng - Fatal编程技术网

Javascript 如何使用TestNG从Selenium中的主类调用全局方法到类

Javascript 如何使用TestNG从Selenium中的主类调用全局方法到类,javascript,selenium-webdriver,testng,Javascript,Selenium Webdriver,Testng,package com.MavenLearning.Login; 导入静态org.testng.Assert.assertEquals; 导入org.openqa.selenium.By; 导入org.openqa.selenium.WebDriver; 导入org.openqa.selenium.firefox.FirefoxDriver; 导入org.testng.annotations.Test; 公共类LoginOne{ @试验 公共无效登录系统() { { System.setProp


package com.MavenLearning.Login;
导入静态org.testng.Assert.assertEquals;
导入org.openqa.selenium.By;
导入org.openqa.selenium.WebDriver;
导入org.openqa.selenium.firefox.FirefoxDriver;
导入org.testng.annotations.Test;
公共类LoginOne{
@试验
公共无效登录系统()
{
{
System.setProperty(“webdriver.gecko.driver”,“C:\\webdriver\\geckodriver.exe”);
WebDriver=newfirefoxdriver();
驱动程序。获取(“http://www.demo.guru99.com/v4/");
驱动程序.findElement(按名称(“uid”)).sendKeys(“mngr105709”);
driver.findElement(按名称(“密码”)).sendKeys(“jajeten”);
driver.findElement(By.name(“btnLogin”))。单击();
assertEquals(driver.getTitle(),“Guru99银行经理主页”);
字符串A=driver.getTitle();
系统输出打印项次(A);
String B=“Guru99银行经理主页”;
系统输出打印ln(B);
如果(A等于(B))
System.out.println(“页面标题匹配”);
其他的
System.out.println(“页面标题不匹配”);
}
}

}
来自Global如果您的意思是
公共静态
,那么您只需要按如下方式调用它:

ClassName.functionName()
如果不是静态的,则需要创建该类的对象,然后调用如下函数:

MyClass my = new MyClass();
my.MyFunctionName();
更新

您需要创建一个xml文件,特别是需要执行的所有类

xml示例

<?xml version="1.0" encoding="UTF-8"?>
<suite name="example suite 1" verbose="1" >
  <test name="Regression suite 1" >
    <classes>
      <class name="com.first.example.demoOne"/>
      <class name="com.first.example.demoTwo"/>
      <class name="com.second.example.demoThree"/>
    </classes>
 </test>
</suite>

资料来源:

视频教程:


Shubham,我创建了一个新的TestNG类来调用该方法,但仍然不确定如何实现它。对不起,我是Java的新手。请看下面的脚本。感谢您的时间和帮助。package com.MavenLearning.Login;导入com.MavenLearning.Login.*;导入org.testng.annotations.Test;公共类CallMethodToLogin{@Test public void f(){}谢谢Shubham,所以在TestNG中,所有的事情都发生在xml文件中的更改上?不是所有的。。。只需在脚本中传递的注释以及所有其他功能,如并行执行、添加侦听器、添加参数,这些都是使用XML可以实现的。。。它是java,通过正确的实现,你可以实现任何你想要的东西。。