2016-08-23 4 views
1

私はlocalhostで私のmavenテストでエラーが発生しました。 1日前はすべてうまくいった。私は単語が含まれている場合私のホームページのタイトルをテストします。同じ単語が含まれている場合は、trueを返します。それ以外の場合はfalseですが、タイトルが良好であってもエラーが発生するたびに失敗します。私は何も変えなかったので変だ。セレンはタイトルを取得

package Testselenium; 

import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import org.testng.Assert; 
import org.testng.annotations.AfterTest; 
import org.testng.annotations.BeforeTest; 
import org.testng.annotations.Test; 

public class NewTest {  

    private WebDriver driver; 

    @Test    
    public void testEasy() {      
     driver.get("127.0.0.1/Demo"); 
     String title = driver.getTitle(); 
     Assert.assertTrue(title.contains("TimDevops")); 
    } 

    @BeforeTest 
    public void beforeTest() { 
     driver = new FirefoxDriver(); 
    } 

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

そしてテストに私のファイルの先頭:

<!DOCTYPE html> 
<html lang="en"> 
<head> 
<meta charset="utf-8"> 
<meta http-equiv="X-UA-Compatible" content="IE=edge"> 
<meta name="viewport" content="width=device-width, initial-scale=1"> 
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> 
<meta name="description" content=""> 
<meta name="author" content=""> 
<link rel="icon" href="../../favicon.ico"> 

<title>Bienvenue sur TimDevOps</title> 

<!-- Bootstrap core CSS --> 
<link href="style.css" rel="stylesheet"> 
私のpom.xml以下

<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>Devops</groupId> 
<artifactId>Devops</artifactId> 
<version>0.0.1-SNAPSHOT</version> 
<build> 
<plugins> 
    <plugin> 
     <artifactId>maven-surefire-plugin</artifactId> 
     <version>2.19.1</version> 
     <inherited>true</inherited> 
     <configuration> 
      <suiteXmlFiles> 
       <suiteXmlFile>testng.xml</suiteXmlFile> 
      </suiteXmlFiles> 
     </configuration> 
    </plugin> 
    </plugins> 
</build> 
<distributionManagement> 
    <!-- Publish snapshots here --> 
    <snapshotRepository> 
      <id>nexus</id> 
      <name>My snapshots</name> 
      <url>http://localhost:8081/repository/maven-public/</url> 
    </snapshotRepository> 
</distributionManagement>    
<dependencies> 
    <!-- http://mvnrepository.com/artifact/org.apache.maven.surefire/surefire-api --> 
    <dependency> 
     <groupId>org.apache.maven.surefire</groupId> 
     <artifactId>surefire-api</artifactId> 
     <version>2.19.1</version> 
    </dependency> 
    <!-- http://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin --> 
    <dependency> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-compiler-plugin</artifactId> 
     <version>3.5.1</version> 
    </dependency> 
    <!-- <dependency>    
     <groupId>junit</groupId>        
     <artifactId>junit</artifactId> 
     <version>3.8.1</version>        
     <scope>test</scope>         
    </dependency> -->    
    <dependency>    
     <groupId>org.seleniumhq.selenium</groupId>        
     <artifactId>selenium-java</artifactId>        
     <version>2.53.1</version>        
    </dependency>    
    <dependency>    
     <groupId>org.testng</groupId>        
     <artifactId>testng</artifactId>        
     <version>6.9.8</version>        
     <scope>test</scope>         
    </dependency> 
</dependencies> 
</project> 

ここでは私のビルドの結果である:

[TestNG] Running: 
C:\Users\TIMSPIRIT\workspace\Devops\testng.xml 


=============================================== 
Suite 
Total tests run: 1, Failures: 1, Skips: 0 
=============================================== 

誰かが私を助けることができますか?

+0

あなたのコードに_Assert.assertTrue(title.contains( "TimDevops")); _のタイトルが_ のときにBienvenue sur TimDevOps _が含まれています。文字列が等しくなければならないので、これをチェックしてください。 – JDelorean

+0

また、これはローカルWebページであると理解していますが、 'driver.open()'の後に何らかの 'waitFor()'メソッドを実装する必要があります。それ以外の場合は、Seleniumがブラウザを開いてページをロードする前に例外がスローされます。 – JDelorean

+0

@JDeloreanあなたの答えに感謝します。メソッドwaitFor()をどのように置くことができるのか分かりません。 – Djoh

答えて

0

タイトルを取得してから、testEasy()メソッドでサイトに移動しています。逆にする必要があります。

+0

あなたの答えをありがとう。ファイルを更新して投稿を編集しますが、それでも同じです – Djoh

+0

変数タイトルの内容を印刷して、webdriverがあなたのために得ているものを – Grasshopper

+0

お返事ありがとうございます。私はリターン(タイトル)を試みるが、私はこのコマンドをどこに置かなければならないのか分からない。私を明るくしてもらえますか? – Djoh

関連する問題