我正在尝试将来自不同类的多个测试用例合并到一个范围报告中。所有测试用例都已成功运行,但未将这些测试用例添加到我的范围报告中。我的范围报告的版本是2.41.2。它仅显示上一个范围报告,没有生成所有测试用例的新报告。我成功生成了单个类报告,但无法生成多个类范围报告。这是我的代码:
// First I have created a base class for Extent Report:
public static ExtentHtmlReporter htmlReporter;
public static ExtentReports extent;
public static ExtentTest test;
@BeforeSuite
public void setUp()
{
htmlReporter = new ExtentHtmlReporter(System.getProperty("user.dir") +"/test-output/MyOwnReport.html");
extent = new ExtentReports();
extent.attachReporter(htmlReporter);
extent.setSystemInfo("OS", "Mac Sierra");
extent.setSystemInfo("Host Name", "Krishna");
extent.setSystemInfo("Environment", "QA");
extent.setSystemInfo("User Name", "Krishna Sakinala");
htmlReporter.config().setChartVisibilityOnOpen(true);
htmlReporter.config().setDocumentTitle("AutomationTesting.in Demo Report");
htmlReporter.config().setReportName("My Own Report");
htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
htmlReporter.config().setTheme(Theme.DARK);
}
@AfterSuite
public void tearDown()
{
extent.flush();
}
}
// Now Logintestcase Extending Base Extent report class:
public class LoginTestCase extends ExtentReportBaseClass {
static WebDriver driver;
Homepage login = new Homepage();
UtilityMethods util = new UtilityMethods();
String locUsernameElem;
String locPasswordelem;
String Sign_in;
String insertEmail;
String insertFirstName;
String createAccountButton;
// @Parameters("browser")
@BeforeClass
public void launchBrowser() {
driver = UtilityMethods.openBrowser(ConstantsValues.BROWSER_NAME);
UtilityMethods.launchWebsite(Utility.ConstantsValues.URL);
driver.manage().window().maximize();
}
@Test
public void registration() throws InterruptedException {
test = extent.createTest("registration", "This will check status for registration of the user.");
Sign_in = Utility.ConstantsValues.SIGN_IN;
insertEmail = Utility.ConstantsValues.EMAIL_ADDRESS;
createAccountButton = Utility.ConstantsValues.CREATE_ACOUNT;
// insertFirstName=ConstantsValues.USER_FIRSTNAME;
util.clickElement(Sign_in);
Thread.sleep(2000);
// driver.findElement(By.xpath("//input[@id='email_create']")).sendKeys("vivekkumar9652gmail.com");
util.sendData(insertEmail);
util.clickElement(ConstantsValues.CREATE_ACCOUNT);
util.clickElement(ConstantsValues.USER_TITLE);
util.sendDataById("customer_firstname", ConstantsValues.FIRST_NAME);
util.sendDataById("customer_lastname", ConstantsValues.LAST_NAME);
// util.sendData(ConstantsValues.LAST_NAME);
util.sendData(ConstantsValues.USER_PASSWORD);
util.clickElement(ConstantsValues.USER_NEWSLETTER);
Select day = new Select(driver.findElement(By.id("days")));
day.selectByValue("1");
Select month = new Select(driver.findElement(By.id("months")));
month.selectByValue("2");
Select year = new Select(driver.findElement(By.id("years")));
year.selectByValue("2014");
util.sendData(ConstantsValues.USER_COMPANY);
util.sendData(ConstantsValues.USER_STATE);
util.sendData(ConstantsValues.USER_ADDRESS1);
util.sendData(ConstantsValues.USER_MOBILENUMBER);
util.sendData(ConstantsValues.USER_ZIPCODE);
util.sendData(ConstantsValues.USER_ALIAS);
util.sendData(ConstantsValues.USER_CITY);
util.clickElement(ConstantsValues.SUBMITACCOUNT);
util.clickElement(ConstantsValues.USER_SIGN_OUT);
test.log(Status.PASS, MarkupHelper.createLabel("PASS", ExtentColor.GREEN));
}
@Test
public void userLogin() {
test = extent.createTest("userLogin", "This will check status for login of the user");
// util.clickElement(ConstantsValues.SIGN_IN);
util.sendData(ConstantsValues.LOGIN_USERNAME);
util.sendData(ConstantsValues.LOGIN_PASSWORD);
util.clickElement(ConstantsValues.USER_SIGNIN_Account);
//Assert.assertNotEquals("Krishna", "Krishna");
test.log(Status.PASS, MarkupHelper.createLabel("PASS", ExtentColor.RED));
}
}
//Now another class Extending BaseExtentReport Class:
public class PurchaseItemTestCase extends ExtentReportBaseClass {
WebDriver driver;
UtilityMethods util = new UtilityMethods();
// @Parameters("browser")
@BeforeClass
public void launchBrowser() throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
driver = new ChromeDriver();
driver = UtilityMethods.openBrowser(ConstantsValues.BROWSER_NAME);
UtilityMethods.launchWebsite(Utility.ConstantsValues.URL);
driver.manage().window().maximize();
}
@Test
public void chkPurchaseItem() throws InterruptedException {
test = extent.createTest("chkPurchaseItem", "This will check status for purchasing an item.");
driver.findElement(By.xpath("//img[@title='Faded Short Sleeve T-shirts']")).click();
driver.switchTo().defaultContent();
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[contains(@id,'fancy')]")));
System.out.println("after frame");
Thread.sleep(4000);
driver.findElement(By.xpath("//button[@type='submit']//span[contains(.,'Add')]")).click();
Set handles = driver.getWindowHandles();
System.out.println(handles);
// Pass a window handle to the other window
for (String handle1 : driver.getWindowHandles()) {
System.out.println(handle1);
driver.switchTo().window(handle1);
Thread.sleep(3000);
driver.findElement(By.xpath("//a[@title='Proceed to checkout']//span[contains(.,'Proceed')]")).click();
Thread.sleep(3000);
driver.findElement(By.xpath(
"//a[@class='button btn btn-default standard-checkout button-medium']//span[contains(.,'Proceed')]//i[@class='icon-chevron-right right']"))
.click();
driver.findElement(By.id("email")).sendKeys("vivekkumar009@gmail.com");
driver.findElement(By.id("passwd")).sendKeys("vivek123");
Thread.sleep(3000);
// UtilityMethods.getdriver().findElement(By.id("SubmitLogin"));
driver.findElement(By.id("SubmitLogin")).click();
driver.findElement(By.name("processAddress")).click();
driver.findElement(By.id("cgv")).click();
driver.findElement(By.xpath("//button[@name=\"processCarrier\"]")).click();
driver.findElement(By.className("cheque")).click();
driver.findElement(By.xpath("//span[contains(text(),'I confirm my order')]")).click();
test.log(Status.PASS, MarkupHelper.createLabel("PASS", ExtentColor.GREEN));
}
}
}
答案 0 :(得分:0)
将范围测试作为线程局部变量。 例如:
Public ThreadLocal<ExtentTest> test;