rem_16_0312 2021-11-29 18:32 采纳率: 33.3%
浏览 33

关于java继承关系的疑问

背景:在写测试用例套件,下面的Base和Login就是测试集里的两个类
代码如下,Login继承Base,执行测试集后,这个Base和Login都会被执行,这样的话相当于执行了两遍beforeTest(),想请教一下如何不执行Base中的方法?


public class Base {
    public static WebDriver driver;
    public static  File file;
    
      @BeforeTest
      public void beforeTest() {
          file=new File("src\\main\\resources\\chromedriver.exe");
          System.setProperty("webdriver.chrome.driver",file.getAbsolutePath());
          System.out.println(file.getAbsolutePath());
          driver = new ChromeDriver(); //初始化driver
          driver.manage().window().maximize();
      }
}

public class Login extends Base {

      @BeforeTest
      public void f() throws InterruptedException, IOException {
          driver.get("http://******:****/cloud-manager/index/");
//          登录
          driver.findElement(By.xpath("//*[@id='LAY-user-login-username']")).sendKeys("hhh");;
          driver.findElement(By.xpath("//*[@id='LAY-user-login-password']")).sendKeys("111111");
          driver.findElement(By.xpath("//*[@id='LAY-user-login-vercode']")).sendKeys("123");
          driver.findElement(By.xpath("//*[@id='subBtn']")).click();
    }
    
}
  • 写回答

1条回答 默认 最新

  • 未聞花名丶 2021-11-29 20:21
    关注
    评论

报告相同问题?

问题事件

  • 修改了问题 11月30日
  • 创建了问题 11月29日

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100