Selenium获得冠军

时间:2016-08-23 08:35:02

标签: maven selenium testng

我在localhost中的maven测试出错了。一天前一切都很好。如果它包含一个单词,我会在我的主页上测试标题。如果包含相同的单词则返回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
===============================================

有人可以帮我吗?

1 个答案:

答案 0 :(得分:0)

您首先获取标题,然后使用方法testEasy()导航到您的网站。应该是相反的。