django - Selenium -显示有关浏览器中发生的事情的注释

标签 django selenium testing

我正在进行硒测试,该测试模拟了我网站上的每个用户操作。从注册到修改表格等

有数百种动作,所以我想看看目前正在发生什么。有没有一种方法可以在Selenium中添加一些注释,以便我可以在浏览器中实时看到它们?例如一些透明的文字覆盖?

我认为可以使用AJAX创建解决方法,但也许内置了一些东西。

最佳答案

使用可以使用ExtentReports,如下例所示。
如果使用Maven,首先应添加依赖项

<dependency>
    <groupId>com.aventstack</groupId>
    <artifactId>extentreports</artifactId>
    <version>3.1.5</version>
</dependency>


和代码示例

**import org.testng.annotations.Test;

import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.MediaEntityBuilder;
import com.aventstack.extentreports.Status;
import com.aventstack.extentreports.reporter.ExtentHtmlReporter;

public class ExtentReportDemo 
{

    @Test
    public void loginTest() throws IOException
    {    
            // Create Object of ExtentHtmlReporter and provide the path where you want to generate the report 
            // I used (.) in path where represent the current working directory
        ExtentHtmlReporter reporter=new ExtentHtmlReporter("./Reports/learn_automation1.html");

            // Create object of ExtentReports class- This is main class which will create report
        ExtentReports extent = new ExtentReports();

            // attach the reporter which we created in Step 1
        extent.attachReporter(reporter);

            // call createTest method and pass the name of TestCase- Based on your requirement
        ExtentTest logger=extent.createTest("LoginTest");

            // log method will add logs in report and provide the log steps which will come in report
        logger.log(Status.INFO, "Login to amazon");

        logger.log(Status.PASS, "Title verified");

            // Flush method will write the test in report- This is mandatory step  
        extent.flush();

            // You can call createTest method multiple times depends on your requirement
            // In our case we are calling twice which will add 2 testcases in our report
        ExtentTest logger2=extent.createTest("Logoff Test");

        logger2.log(Status.FAIL, "Title verified");

        logger2.fail("Failed because of some issues", MediaEntityBuilder.createScreenCaptureFromPath("/Users/mukeshotwani/Desktop/logo.jpg").build());

        logger2.pass("Failed because of some issues", MediaEntityBuilder.createScreenCaptureFromPath("/Users/mukeshotwani/Desktop/logo.jpg").build());

            // This will add another test in report
        extent.flush();

    }

}**


我要么建议尝试TestProject免费自动化平台。还有一个不错的SDK,并提供了创建美观而翔实的报告的多种可能性。
简而言之,您可以像在一个测试中的示例一样,在那里管理报告:

int total = 0;
        total += Integer.parseInt(Adults);
        total += Integer.parseInt(Seniors);
        total += Integer.parseInt(Childs);
        total += Integer.parseInt(Infants);
        by = By.xpath("//div[@class='passengers etField flight-pax beforeLast js__pax_display-container']");
        amount = Integer.parseInt(driver.testproject().getText(by));
        result = total == amount;
        reporter.step("Passengers validation is > " + result, total == amount, TakeScreenshotConditionType.Failure);


之后,您将看到something like this

关于django - Selenium -显示有关浏览器中发生的事情的注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57559724/

相关文章:

python - 我如何在 Django 中编写此查询? (约会时间)

python - 如何使用 postgres 在 django 中设置 DateTimeField

mysql - 如何使用 MySql 后端为 Django 中的 TextField 指定索引?

javascript - 有没有办法从 JavaScript 检测到我在 Selenium Webdriver 页面中

Laravel 5.6 测试Notification::assertSentTo() 未找到

python - clean_data 在 django 1.8.6 中不起作用

selenium - 使用 Selenium IDE 和 WebDriver 编写的测试执行时间比较

android - 如何找到用于手动测试的android应用程序的代码覆盖率?

php - Selenium、php、phpUnit、404 错误调用 testComplete() 而不是继续,我该如何停止?

java - Selenium 动态生长表