有人可能会告诉我如何编写一个功能应用程序测试,它结合Selenium、Page、Object Pattern和ExtentsReports (http://extentreports.relevantcodes.com/)来从这些测试用例生成报告。如何设计测试类?因为我知道验证应该与页面对象分开。做到这一点的最佳方法是什么?
一段示例代码将非常有用。
发布于 2015-07-24 14:56:16
当然,将模型(页面对象)与测试分离是一种很好的方法。为此,您可以使用一个服务层,即帮助器类,它可以与业务对象和页面对象进行交互。
注意:我将回答您问题的第二部分,而不是关于报告的另一个库。
因此,您有一个业务对象:
public class Something {
boolean toHappen;
public Something(boolean toHappen) {
this.toHappen = toHappen;
}
public boolean isToHappen() {
return toHappen;
}
}你也有你的页面:
public class ApplicationPage {
// how driver object is put here is your own business.
private static WebDriver driver;
@FindBy(id = "id")
private Button triggerButton;
public ApplicationPage() {
PageFactory.initElements(driver, this);
}
public static ApplicationPage open(){
driver.get("http://page.net");
return new ApplicationPage();
}
public void trigger() {
triggerButton.click();
}
}因此,为了不在测试中混淆业务对象和页面,您需要创建一个服务:
public class InevitableService {
public static void makeHappen() {
// just a very stupid code here to show interaction
Something smth = new Something(true);
ApplicationPage page = ApplicationPage.open();
if(smth.toHappen()){
page.trigger();
}
}
}最后是你的测试
public class TestClass extends Assert {
@Test
public void test() {
InevitableService.makeHappen();
assertTrue(true);
}
}结果是:
优点:
缺点:
随着时间的推移,
考虑到你的报告工具-我相信它只是监听你的测试结果,并将它们发送到服务器。或者,它只是获取测试的xml/html结果,然后生成漂亮而无用的饼状图。再说一次,和流行音乐没有任何关系。
发布于 2016-01-13 20:08:08
步骤:
1. Declare variables under Test Suite class
public ExtentReports extent ;
public ExtentTest test;
2. Create object for Extent Managers User defined class
extent = ExtentManager.instance();
3. Pass extent parameter to the Page Object Class
inbound = new DemoPageObject(driver,extent);
4. Goto page object class method and Start with "Start log"
test = extent.startTest("View details", "Unable to view details");
5. For Success steps and we need end test
test.log(LogStatus.PASS, "The list of details are successfully displaying");
test.log(LogStatus.INFO, test.addScreenCapture(ExtentManager.CaptureScreen(driver, "./Send")));
log.info("The list of details are successfully displaying ");
extent.endTest(test);
6. For Failure and no need to end test
test.log(LogStatus.FAIL, "A Technical error is displaying under ");
7. Use @AfterMethod to handle error test cases
@AfterMethod
public void tearDown(ITestResult result) {
if (result.getStatus() == ITestResult.FAILURE) {
test.log(LogStatus.FAIL, "<pre>" + result.getThrowable().getMessage() + "</pre>");
extent.endTest(test);
}
}
8. Finally Adding results to the report
@AfterTest
public void when_I_Close_Browser() {
extent.flush();}
公共类ExtentManager {
public static ExtentReports instance() {
ExtentReports extent;
String Path = "./ExtentReport.html";
System.out.println(Path);
extent = new ExtentReports(Path, true);
//extent.config() .documentTitle("Automation Report").reportName("Regression");
extent
.addSystemInfo("Host Name", "Anshoo")
.addSystemInfo("Environment", "QA");
return extent;
}
public static String CaptureScreen(WebDriver driver, String ImagesPath) {
TakesScreenshot oScn = (TakesScreenshot) driver;
File oScnShot = oScn.getScreenshotAs(OutputType.FILE);
File oDest = new File(ImagesPath + ".jpg");
try {
FileUtils.copyFile(oScnShot, oDest);
} catch (IOException e) {
System.out.println(e.getMessage());
}
return ImagesPath + ".jpg";
}}
https://stackoverflow.com/questions/31539242
复制相似问题