如何处理java.util.concurrentmodificationexception

swvgeqrz  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(271)

我刚刚开始学习java和selenium。在我下面的代码中,我只是打开paytm主页并点击一个链接。在输出中,我得到以下异常:

[TestNG] Time taken by org.testng.reporters.XMLReporter@59a6e353: 6 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@7f63425a: 36 ms
[Utils] Attempting to create C:\Kapil\Kapil B\Auto\Selenium\Workspace\WebDriverCmds_Kapil\test-output\testng-failed.xml
[Utils]   Directory C:\Kapil\Kapil B\Auto\Selenium\Workspace\WebDriverCmds_Kapil\test-output exists: true
[Utils] Attempting to create C:\Kapil\Kapil B\Auto\Selenium\Workspace\WebDriverCmds_Kapil\test-output\Default suite\testng-failed.xml
[Utils]   Directory C:\Kapil\Kapil B\Auto\Selenium\Workspace\WebDriverCmds_Kapil\test-output\Default suite exists: true
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 13 ms
[TestNG] Reporter org.testng.reporters.JUnitReportReporter@2acf57e3 failed
java.util.ConcurrentModificationException
    at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:909)
    at java.util.ArrayList$Itr.next(ArrayList.java:859)
    at org.testng.reporters.JUnitReportReporter.getNextConfiguration(JUnitReportReporter.java:220)
    at org.testng.reporters.JUnitReportReporter.generateReport(JUnitReportReporter.java:105)
    at org.testng.TestNG.generateReports(TestNG.java:1175)
    at org.testng.TestNG.run(TestNG.java:1102)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)
[Utils] Attempting to create C:\Kapil\Kapil B\Auto\Selenium\Workspace\WebDriverCmds_Kapil\test-output\old\Default suite\toc.html
[Utils]   Directory C:\Kapil\Kapil B\Auto\Selenium\Workspace\WebDriverCmds_Kapil\test-output\old\Default suite exists: true
[Utils] Attempting to create C:\Kapil\Kapil B\Auto\Selenium\Workspace\WebDriverCmds_Kapil\test-output\old\Default suite\Default test.properties
[Utils]   Directory C:\Kapil\Kapil B\Auto\Selenium\Workspace\WebDriverCmds_Kapil\test-output\old\Default suite exists: true
[Utils] Attempting to create C:\Kapil\Kapil B\Auto\Selenium\Workspace\WebDriverCmds_Kapil\test-output\old\Default suite\index.html
[Utils]   Directory C:\Kapil\Kapil B\Auto\Selenium\Workspace\WebDriverCmds_Kapil\test-output\old\Default suite exists: true
[Utils] Attempting to create C:\Kapil\Kapil B\Auto\Selenium\Workspace\WebDriverCmds_Kapil\test-output\old\Default suite\main.html
[Utils]   Directory C:\Kapil\Kapil B\Auto\Selenium\Workspace\WebDriverCmds_Kapil\test-output\old\Default suite exists: true
[Utils] Attempting to create C:\Kapil\Kapil B\Auto\Selenium\Workspace\WebDriverCmds_Kapil\test-output\old\Default suite\groups.html
[Utils]   Directory C:\Kapil\Kapil B\Auto\Selenium\Workspace\WebDriverCmds_Kapil\test-output\old\Default suite exists: true
[Utils] Attempting to create C:\Kapil\Kapil B\Auto\Selenium\Workspace\WebDriverCmds_Kapil\test-output\old\Default suite\classes.html
[Utils]   Directory C:\Kapil\Kapil B\Auto\Selenium\Workspace\WebDriverCmds_Kapil\test-output\old\Default suite exists: true
[Utils] Attempting to create C:\Kapil\Kapil B\Auto\Selenium\Workspace\WebDriverCmds_Kapil\test-output\old\Default suite\reporter-output.html
[Utils]   Directory C:\Kapil\Kapil B\Auto\Selenium\Workspace\WebDriverCmds_Kapil\test-output\old\Default suite exists: true
[Utils] Attempting to create C:\Kapil\Kapil B\Auto\Selenium\Workspace\WebDriverCmds_Kapil\test-output\old\Default suite\methods-not-run.html
[Utils]   Directory C:\Kapil\Kapil B\Auto\Selenium\Workspace\WebDriverCmds_Kapil\test-output\old\Default suite exists: true
[Utils] Attempting to create C:\Kapil\Kapil B\Auto\Selenium\Workspace\WebDriverCmds_Kapil\test-output\old\Default suite\testng.xml.html
[Utils]   Directory C:\Kapil\Kapil B\Auto\Selenium\Workspace\WebDriverCmds_Kapil\test-output\old\Default suite exists: true
[Utils] Attempting to create C:\Kapil\Kapil B\Auto\Selenium\Workspace\WebDriverCmds_Kapil\test-output\old\index.html
[Utils]   Directory C:\Kapil\Kapil B\Auto\Selenium\Workspace\WebDriverCmds_Kapil\test-output\old exists: true
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@b684286: 51 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@17f6480: 4 ms

下面是我的代码:

public class PaytmFrames extends TestBase {
    @Test
    public void testPaytm() throws InterruptedException {
        initBrowser("Chrome");
        driver.get("https://paytm.com/");
        Thread.sleep(10000);
        driver.findElement(By.xpath("//div[@class='_3fM-']")).click();
    }
}

以及上面代码中调用的initbrowser函数:

@BeforeMethod
public ExtentTest setupTest() {
    System.out.println("@BeforeMethod");
    extent = initExtRep();
    extTest = extent.createTest("Kapil Test");
    return extTest;
}

@AfterMethod
public void finalizeExtentRep() throws InterruptedException {
    System.out.println("@AfterMethod");
    extent.flush();
    Thread.sleep(10000);
    driver.quit();
}

// Initialize and setup the browser
public WebDriver initBrowser(String browser) {
    // Disable notifications, ignore ssl, start mazimized, no logs
    if (browser.equals("Chrome")) {
        ChromeOptions optionsCh = new ChromeOptions();
        optionsCh.addArguments("--disable-notifications");
        optionsCh.addArguments("ignore-certificate-errors");
        optionsCh.addArguments("--start-maximized");
        System.setProperty(ChromeDriverService.CHROME_DRIVER_SILENT_OUTPUT_PROPERTY, "true");
        optionsCh.setPageLoadStrategy(PageLoadStrategy.EAGER);
        driver = new ChromeDriver(optionsCh);

    } 
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    return driver;
}

我也尝试过修改testng版本,但是没有用。目前我使用的是7.0.0。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题