简体   繁体   English

多个@ Test,Selenium WebDriver之间的Get()和Set()

[英]Get() and Set() between multiple @Test, Selenium WebDriver

I'm using Selenium WebDriver and Arquillian drone for these test. 我正在使用Selenium WebDriver和Arquillian无人机进行这些测试。

how my tests are build : 我的测试是如何构建的:

@RunWith(Arquillian.class)
public class SimpleTest{

  private String idPo;

  public String getIdPo() {
    return idPo;
  }

  public void setIdPo(String id) {
    idPo = id;
  }

  @Test
  public void setTest() {
    setIdPo("5");
  }

  @Test
  public void getTest() {
    String temp = getIdPo(); // ----> returns null
    Assert.assertTrue(temp.equals("5"));
  }

}

When i set the value, everything seems to be ok, but when i switch to another test, IdPo is null. 当我设置该值时,一切似乎都正常,但是当我切换到另一个测试时, IdPo为空。 Is it possible that each @Test release and renew variables ? 每个@Test发行和更新变量都有可能吗?

I've found the error... 我发现了错误...

When i call the getter i was using : getId() instead of getIdPo() . 当我调用getter时,我使用的是: getId()而不是getIdPo()

But Eclipse never underline getId() .. don't really know why.. because it doesn't exist in my code.. 但是Eclipse从来不强调getId() ..真的不知道为什么..因为它在我的代码中不存在。

I belive BeforeTest should help you. 我相信BeforeTest应该可以为您提供帮助。

@BeforeTest: The annotated method will be run before any test method belonging to the classes inside the tag is run. @BeforeTest:带注释的方法将在运行属于该标记内的类的任何测试方法之前运行。

Just write a method and annotate it with @BeforeTest and set the values as desired. 只需编写一个方法并使用@BeforeTest对其进行注释,然后根据需要设置值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM