2017-02-12 2 views
1

В последней версии Intellij IDEA Ultimate я не могу использовать аннотацию @Test, не получая красные строки ошибок. Только так, как это работает, я предоставляю полное имя пакета, как показано ниже:Невозможно использовать тестовую аннотацию TestNG без предоставления полного имени пакета

import org.openqa.selenium.By; 
import org.openqa.selenium.Keys; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.chrome.ChromeDriver; 
import org.testng.annotations.AfterTest; 
import org.testng.annotations.BeforeTest; 

public class Test { 
private WebDriver driver; 

@BeforeTest 
public void setup(){ 
    System.setProperty("webdriver.chrome.driver", "/Users/jeff/IdeaProjects/Practice/src/chromedriver"); 
    driver = new ChromeDriver(); 
    driver.get("http://google.com"); 
} 

@org.testng.annotations.Test 
public void test(){ 
    WebElement searchBox = driver.findElement(By.id("lst-ib")); 
    searchBox.sendKeys("Hello World"); 
    searchBox.sendKeys(Keys.RETURN); 
} 

@AfterTest 
public void tearDown() throws Exception{ 
    Thread.sleep(3000); 
    driver.quit(); 
} 
} 

Другие примечания прекрасно работают, как вы можете видеть. А так как у меня есть варианты Добавить однозначные импорт на лету и импорта Оптимизируйте на лету проверяется в настройках, когда я иду вперед и добавить следующее:

import org.testng.annotations.Test; 

Он получает неактивны, так как это не в использовании ... но.

Вот мой Maven pom.xml файл:

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.Practice</groupId> 
    <artifactId>Practice</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <dependencies> 
     <!-- https://mvnrepository.com/artifact/org.testng/testng --> 
     <dependency> 
      <groupId>org.testng</groupId> 
      <artifactId>testng</artifactId> 
      <version>6.10</version> 
     </dependency> 
     <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java --> 
     <dependency> 
      <groupId>org.seleniumhq.selenium</groupId> 
      <artifactId>selenium-java</artifactId> 
      <version>3.0.1</version> 
     </dependency> 
     <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-chrome-driver --> 
     <dependency> 
      <groupId>org.seleniumhq.selenium</groupId> 
      <artifactId>selenium-chrome-driver</artifactId> 
      <version>3.0.1</version> 
     </dependency> 
     <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-firefox-driver --> 
     <dependency> 
      <groupId>org.seleniumhq.selenium</groupId> 
      <artifactId>selenium-firefox-driver</artifactId> 
      <version>3.0.1</version> 
     </dependency> 
     <dependency> 
      <groupId>com.mashape.unirest</groupId> 
      <artifactId>unirest-java</artifactId> 
      <version>1.4.9</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.httpcomponents</groupId> 
      <artifactId>httpclient</artifactId> 
      <version>4.3.6</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.httpcomponents</groupId> 
      <artifactId>httpasyncclient</artifactId> 
      <version>4.0.2</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.httpcomponents</groupId> 
      <artifactId>httpmime</artifactId> 
      <version>4.3.6</version> 
     </dependency> 
     <dependency> 
      <groupId>org.json</groupId> 
      <artifactId>json</artifactId> 
      <version>20140107</version> 
     </dependency> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.11</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>commons-io</groupId> 
      <artifactId>commons-io</artifactId> 
      <version>2.4</version> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 
</project> 
+0

Не могли бы вы попытаться удалить junit из вашего класса? – juherr

+0

@juherr, похоже, не работает даже после удаления junit. Кажется, что даже когда я создаю автогенератор для тестового метода, он все еще использует полное имя пакета для аннотации. –

ответ

2

Ваш класс называется Test сам, поэтому полное имя класса аннотаций требуется для предотвращения конфликта. Переименуйте класс в SomeTest, и вы сможете использовать аннотацию @Test с импортом.

+0

Спасибо! Это сработало. –

Смежные вопросы