简体   繁体   English

testng.xml没有运行类

[英]testng.xml not running class

I am right clicking on my testng.xml and running as a testng Suite, but the class inside it doesn't run. 我右键单击testng.xml并以testng Suite身份运行,但其中的类未运行。

This is my xml file: 这是我的xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="mytestpack" >

 <test name="Firefox Test">

 <parameter name="browser" value="Firefox"/> 

 <classes>

 <class name="mytestpack.MyTestClass" />

 </classes>

 </test>


</suite>

This is the MyTestClass code: 这是MyTestClass代码:

package testing_pack;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class MyTestClass {

    private static WebDriver driver;

    @Parameters({"browser"})
    @BeforeTest
    public void setup(String browser) {

         System.out.println(browser);

              // If the browser is Firefox, then do this

              if(browser.equalsIgnoreCase("firefox")) {

                  driver = new FirefoxDriver();

              // If browser is IE, then do this   

              }
         }


    @Test
    public static void test() {

          driver.get("http://only-testing-blog.blogspot.in");
          String i = driver.getCurrentUrl();
          System.out.println(i);

    }
    @AfterTest
    public void teardown() {
        driver.close();
    }
    }

The class runs perfectly fine on it's own. 该类本身运行得很好。 Don't understand why testng isn't running it. 不明白为什么testng没有运行它。 It doesn't throw any errors it just displays: 它不会抛出任何错误,只会显示:

[TestNG] Running:
  C:\Users\Laptops\Desktop\eclipse\workspace\testproject\src\mytestpack\testng.xml


===============================================
mytestpack
Total tests run: 0, Failures: 0, Skips: 0
===============================================

Thanks 谢谢

Change your suite name in testng.xml from mytestpack to testing_pack . 在更改您的套件名称testng.xmlmytestpacktesting_pack The class MyTestClass is under different package. MyTestClass在不同的程序包下。

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

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