Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium 如何在testng电子邮件报告中获取断言错误?_Selenium_Selenium Webdriver - Fatal编程技术网

Selenium 如何在testng电子邮件报告中获取断言错误?

Selenium 如何在testng电子邮件报告中获取断言错误?,selenium,selenium-webdriver,Selenium,Selenium Webdriver,下面是我的代码 public void test58() throws FileNotFoundException{ for(int i=16; i<65; i++){ News_details nd=PageFactory.initElements(driver, News_details.class); nd.Stock_Exchange_List();

下面是我的代码

public void test58() throws FileNotFoundException{

        for(int i=16; i<65; i++){
                    News_details nd=PageFactory.initElements(driver, News_details.class); 
                    nd.Stock_Exchange_List();
                    //click on edit stocklist
                    driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[2]/div[3]/table/tbody/tr/td/a/span")).click();

                    driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[2]/div[3]/form/div[2]/div[1]/table/tbody/tr[5]/td[4]/a/img")).click();
                    driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[2]/div[3]/form/div[2]/div[1]/table/tbody/tr[6]/td[4]/a/img")).click();
                    driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[2]/div[3]/form/div[2]/div[1]/table/tbody/tr[7]/td[4]/a/img")).click();
                    driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[2]/div[3]/form/div[2]/div[1]/table/tbody/tr[8]/td[4]/a/img")).click();
                    driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[2]/div[3]/form/div[2]/div[1]/table/tbody/tr[9]/td[4]/a/img")).click();
                    driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[2]/div[3]/form/div[2]/div[1]/table/tbody/tr[10]/td[4]/a/img")).click();
                    driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[2]/div[3]/form/div[2]/div[1]/table/tbody/tr[11]/td[4]/a/img")).click();
                    driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[2]/div[3]/form/div[2]/div[1]/table/tbody/tr[12]/td[4]/a/img")).click();
                    List<WebElement> els = driver.findElements(By.xpath("//input[@type='checkbox']"));
                        for( WebElement el : els ) {
                            if ( el.isSelected() ) {
                                el.click();
                            }
                        }
                    try{
                    //Select an stock exchange
                    driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[2]/div[3]/form/div[2]/div[1]/table/tbody/tr["+i+"]/td[2]/input")).click();

                    }
                    catch(org.openqa.selenium.NoSuchElementException error)
                    {
                            continue;
                    }
                    //save
                    driver.findElement(By.id("navpanel_fwd")).click();
                    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
                    String Stocklist=driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[2]/div[3]/div[2]/div[2]/strong")).getText();
                    driver.navigate().to(url);

                    BottomTable1=driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[2]/div[3]/form/div[2]/div[1]/div[3]/table/tbody/tr/td/table[2]/tbody/tr[12]/td[2]")).getText();
                    try{

                        Assert.assertTrue(BottomTable1.contains(Stocklist),Stocklist+ "Stock Exchange Not Found");

                    }
                    catch(AssertionError err){
                        err.printStackTrace();
                        System.out.println(err);
                        //System.setOut(new PrintStream(new FileOutputStream("d://output.txt")));
                        //Reporter.log("PASS/FAIL");
                        //throw err; 
                        continue;

                    }
            }
public void test58()引发FileNotFoundException{

对于(int i=16;i使用SoftAssert),它在@Test期间收集错误(不会引发异常)

不要使用Assert.assertTrue。它是一个硬断言。它将立即抛出AssertException,测试标记为失败,失败的消息将打印在堆栈跟踪中,而不是在报告中

SoftAssert s_assert = new SoftAssert();
s_assert.assertTrue(BottomTable1.contains(Stocklist),Stocklist+ "Stock Exchange Not Found");