【问题标题】:Selenium TestNG the same test for different dimensionsSelenium TestNG 不同维度的相同测试
【发布时间】:2018-12-14 13:01:52
【问题描述】:

我可以使用 Selenium/TestNG/Java 对不同尺寸的浏览器窗口运行相同的测试吗?我想我有一个解决方案,但我不想像这样写两次相同的代码:

@Test(priority = 0)
public void pc {
 driver.manage().window().maximize();
 "TheSameTestcode"
}

@Test(priority = 1)
public void smartphone {
 Dimension d = new Dimension(420,600);
 driver.manage().window().setSize(d);
 "TheSameTestcode"
}

我在 C# / Nunit 中看到了适合我的东西,它看起来像这样(宽度为 1000px,800px):

[TestFixture(1000)] 
[TestFixture(800)]     
[Test]
public void allDevices {
 "TheSameTestcode"
}

【问题讨论】:

    标签: java maven selenium testing testng


    【解决方案1】:
    class ReusableMethods{
    
    public void setWindowSize(WebDriver driver,int x, int y){
      Dimension d = new Dimension(x,y);
      driver.manage().window().setSize(d);
    }
    public void sameCodeMethod(){
      "samecode here"
    }
    public boolean windowSizeAssertion(WebDriver driver, int x,int y){
      int height = dirver.manage().window().getHight();
      int width = dirver.manage().window().getWidth();
      if((height==x)&&(width==y)){
         return true;
      }
      else{
         return false;
      }
    
    }
    }
    
    class TestNGTest extends ReusableMethods{
    @Test(priority = 0)
    public void pc {
      driver.manage().window().maximize();
      samecodeMethod();
    }
    
        @Test(priority = 1)
        public void smartphone {
          setWindowSize(driver,100,200);
          samecodeMethod();
          Asset.assertTrue(windowSizeAssertion(driver,100,200));
        }
    
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-11
      • 2020-05-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-25
      相关资源
      最近更新 更多