testng.xml 不能 运行 类
testng.xml can't run classes
我在我的 testng.xml 中是正确的 运行ning 并且作为一个 testng 套件,但是它里面的 class 不是 运行。
testng.xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="TestAll">
<test name="Test">
<parameter name="first-name" value="Here we Go is not displayed after log in!!! "/>
<classes>
<class name="tests.LogIn">
</class>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
我正在为 class 使用额外的 Appium 和 JUnit 库。
Java代码class:
package tests;
import java.net.URL;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Parameters;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import static common.Helper.*;
import static common.Element.*;
public class LogIn {
private static final String USERNAME = "string";
private static final String USERPASSWORD = "string";
//Config and Setup a AppiumDriverInstance
public AppiumDriver<MobileElement> driver;
public WebDriverWait wait;
@Before
public void setUp() throws Exception {
// set up appium for ios instance
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone 5s");
capabilities.setCapability(MobileCapabilityType.APP, "/path/to/file");
driver = new IOSDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
wait = new WebDriverWait(driver, 30);
}
@After
public void tearDown() throws Exception {
driver.quit();
}
@Parameters({ "first-name" })
@Test
public void findFirstElement() throws InterruptedException {
//check if FTU "Here We go" is shown
iOsAssertExists(WELTBILD_DE_HEREWEGO_XPATH,"Here we Go is not displayed after log in!!! ", driver);
//tab on screen to close FTU "Here we go"
driver.findElementByXPath(WELTBILD_DE_HEREWEGO_XPATH).tap(1,100);
Thread.sleep(3000);
}
}
class 运行 非常好,但我不知道为什么 testng 没有 运行 宁它。这是 运行ning:
的结果
[TestNG] Running:
/Users/vorse/nga/ProductFamilyTests/AutomationTests/AppiumTest/testng.xml
===============================================
TestAll
Total tests run: 0, Failures: 0, Skips: 0
===============================================
您正在创建 testNG.xml 并使用 junit 注释,这就是它不起作用的原因,
你需要导入这个:import org.testng.annotations.*;
你还需要使用testNg的@Test,@BeforeTest/@BeforeClass代替@Before,@After的类似情况--> @AfterTest/@AfterClass
来自 TestNG 文档 5.12 - JUnit tests:
TestNG can run JUnit 3 and JUnit 4 tests. All you need to do is put the JUnit jar file on the classpath, specify your JUnit test classes in the testng.classNames
property and set the testng.junit
property to true:
<test name="Test1" junit="true">
<classes>
<!-- ... -->
我在我的 testng.xml 中是正确的 运行ning 并且作为一个 testng 套件,但是它里面的 class 不是 运行。 testng.xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="TestAll">
<test name="Test">
<parameter name="first-name" value="Here we Go is not displayed after log in!!! "/>
<classes>
<class name="tests.LogIn">
</class>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
我正在为 class 使用额外的 Appium 和 JUnit 库。 Java代码class:
package tests;
import java.net.URL;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Parameters;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import static common.Helper.*;
import static common.Element.*;
public class LogIn {
private static final String USERNAME = "string";
private static final String USERPASSWORD = "string";
//Config and Setup a AppiumDriverInstance
public AppiumDriver<MobileElement> driver;
public WebDriverWait wait;
@Before
public void setUp() throws Exception {
// set up appium for ios instance
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone 5s");
capabilities.setCapability(MobileCapabilityType.APP, "/path/to/file");
driver = new IOSDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
wait = new WebDriverWait(driver, 30);
}
@After
public void tearDown() throws Exception {
driver.quit();
}
@Parameters({ "first-name" })
@Test
public void findFirstElement() throws InterruptedException {
//check if FTU "Here We go" is shown
iOsAssertExists(WELTBILD_DE_HEREWEGO_XPATH,"Here we Go is not displayed after log in!!! ", driver);
//tab on screen to close FTU "Here we go"
driver.findElementByXPath(WELTBILD_DE_HEREWEGO_XPATH).tap(1,100);
Thread.sleep(3000);
}
}
class 运行 非常好,但我不知道为什么 testng 没有 运行 宁它。这是 运行ning:
的结果[TestNG] Running:
/Users/vorse/nga/ProductFamilyTests/AutomationTests/AppiumTest/testng.xml
===============================================
TestAll
Total tests run: 0, Failures: 0, Skips: 0
===============================================
您正在创建 testNG.xml 并使用 junit 注释,这就是它不起作用的原因, 你需要导入这个:import org.testng.annotations.*;
你还需要使用testNg的@Test,@BeforeTest/@BeforeClass代替@Before,@After的类似情况--> @AfterTest/@AfterClass
来自 TestNG 文档 5.12 - JUnit tests:
TestNG can run JUnit 3 and JUnit 4 tests. All you need to do is put the JUnit jar file on the classpath, specify your JUnit test classes in the
testng.classNames
property and set thetestng.junit
property to true:<test name="Test1" junit="true"> <classes> <!-- ... -->