使用xml在Testng中运行2个类时跳过第二个类中创建的方法

时间:2016-07-28 12:03:10

标签: selenium-webdriver testng

我在这两个类中创建了2个具有3个方法/测试的类。 2级方法/测试和第3级方法/测试是2级。但是当我使用xml运行这些时,第一类运行测试和测试都会传递到第二类跳过的方法/测试。

XML:

<?xml version="1.0" encoding="UTF-8"?>
<suite name= "Expedia Call Tracker">
    <test name="Expedia Home Smoke Testcases">
        <classes>
            <class name="ExpediaCallTracker.Expedia"/>
            <class name="ExpediaCallTracker.ExpediaCreateSale" />
        </classes>
    </test>
</suite>

First Class :

package ExpediaCallTracker;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.Test;

public class Expedia {

public String e;

WebDriver expedia = new FirefoxDriver();


@Test(priority=1)

public void ExpediaLogin()
{

    expedia.manage().window().maximize();
    expedia.get("http://fedev.teleperformanceusa.com/Expedia/ExpediaCallTracker/Account/Login");

    expedia.findElement(By.id("UserName")).sendKeys("kochhar.5");
    expedia.findElement(By.id("Password")).sendKeys("Password11");
    expedia.findElement(By.xpath(".//*[@id='loginForm']/form/fieldset/p/input")).click();

}


@Test(priority=2)
public void ExpediaDashSale()

{

    expedia.findElement(By.linkText("Sale - HWW/EAN")).click();
}

}

Second Class :

package ExpediaCallTracker;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;


public class ExpediaCreateSale {

private static final WebDriver d = null;

public ExpediaCreateSale()
{

}

WebDriver expedia = d;          

@Test
public void ExpediaCreate(WebDriver d)
{


    expedia.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    Select LineOfBusiness = new Select(expedia.findElement(By.id("lineOfBusiness")));
    LineOfBusiness.selectByIndex(1);
    expedia.findElement(By.id("sourceCode")).sendKeys("abcdefgh");

    WebElement Upsell = expedia.findElement(By.xpath("html/body/div[1]/section[2]/form/fieldset/div[6]/input[1]"));
    Upsell.click();

    WebElement SaleCall =expedia.findElement(By.xpath("html/body/div[1]/section[2]/form/fieldset/div[8]/input[1]"));
    SaleCall.click();

    expedia.findElement(By.id("checkInDate")).sendKeys("09/14/2016");

    Select numberOfNights = new Select(expedia.findElement(By.id("numberOfNights")));
    numberOfNights.selectByIndex(1);

    WebElement PaymentMethod = expedia.findElement(By.xpath("html/body/div[1]/section[2]/form/fieldset/div[9]/div[6]/input[1]"));
    PaymentMethod.click();

    Select currency = new Select(expedia.findElement(By.id("currency")));
    currency.selectByIndex(70);
    expedia.findElement(By.id("grossBooking")).sendKeys("123456");
    expedia.findElement(By.id("itineraryNumber")).sendKeys("123456789");
    expedia.findElement(By.id("remark")).sendKeys("Itinery       number         saved.");
    expedia.findElement(By.xpath(".//*[@id='body']/section[2]    /form/fieldset/p/input[1]")).click();
}

}

任何人都可以建议我应该尝试做什么?

1 个答案:

答案 0 :(得分:0)

采用参数WebDriver的测试方法ExpediaCreate导致此问题。要解决此问题,请遵循与Expedia类相同的方法,它应该可以正常工作。

此外,您尚未在ExpediaCreateSale类中初始化webdriver实例变量d。一旦初始化驱动程序实例,它就可以在您的测试方法中使用,因此您不必作为参数传递。

你也不必拥有这行代码。

private static final WebDriver d = null;

希望这有帮助。