开发者社区 问答 正文

TestNG 的 assert?报错

package testNG_Baidu;

import org.testng.Assert;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;
import org.testng.asserts.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.*;
import org.openqa.selenium.WebDriver;


public class BaiduHomePage {
	  @BeforeClass
	  public void beforeClass() 
	  {
		  
	  }
		
	  @Test
	  public void f() {
		  String searchCondition = "JAVA + SELENIUM";
			WebDriver browser = new FirefoxDriver();
			browser.get("https://www.baidu.com");
			
			WebElement findIdKw = browser.findElement(By.id("kw"));
			WebElement findIDSu = browser.findElement(By.id("su"));
			
			findIdKw.sendKeys(searchCondition);
			findIDSu.click();
			//navigation.back();
			
			try
			{
				Thread.sleep(5000);
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}
			
			
			WebElement findRS = browser.findElement(By.className("tt"));
			String s = (findRS.getText());
			
			try
			{
				Assert.assertEquals(s, "相关搜索", "Assertion Failed,");
			}
			catch(Exception e)
			{	
                            System.out.println("abc");	
				e.printStackTrace();
			}
			
			browser.quit();
	  }
	  
	
	
	  @AfterClass
	  public void afterClass() {
	  }

}
  1. 如果try中语法报错,为什么catch中的System.out.println没有输出



展开
收起
爱吃鱼的程序员 2020-06-09 11:21:41 470 分享 版权
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    你把System.out.println放到e.printStackTrace()后面试试

    2020-06-09 11:22:00
    赞同 展开评论
问答分类:
问答地址: