2015-11-06 62 views
2

我确定,这个问题可以由经验丰富的Java开发人员快速回答。但是由于我对Java并不熟悉,我不知道如何从Java中获取Selenium的@Config部分。如果我可以有一个配置文件或类,我可以将数据(浏览器,网站等)和测试文件放在一起,那将是最佳选择。
下面是测试文件的例子:
Selenium Java - 如何外包@Config并从外部类调用测试?

package com.example_test.selenium; 

import io.ddavison.conductor.Browser; 
import io.ddavison.conductor.Config; 
import io.ddavison.conductor.Locomotive; 
import org.junit.Test; 

@Config(
     browser = Browser.CHROME, 
     url  = "http://example.com" 
) 

public class test_a_Home extends Locomotive { 
    @Test 
    public void testifExists() { 
     validatePresent(site_a_Home.EL_NEWCUSTOMERBANNER); 
    } 
} 

现在我想有一个名为tests.java在那里我可以称之为“test_a_Home” - 函数一个单独的文件。如果我尝试它只是

package com.example_test.selenium; 

public class tests { 
    test_a_Home test = new test_a_Home(); 

    test.testifExists(); 

} 

我收到的错误,即“testifExists()”不能得到解决。
我尝试将public void testifExists()更改为public int testifExists(),并试图在class tests中用int res = test.testifExists();调用它,但这也不起作用,因为我收到错误java.lang.Exception: Method testNewCustomersBannerExists() should be void
如果有人能帮助我,我会非常高兴。如果您需要更多信息,请随时提及。谢谢。

回答

1

如果你希望你的设计是这样,那么你就需要组织你的测试,例如:

public class BasePage { 
    public Locomotive test; 
    public BasePage(Locomotive baseTest) { 
     test = baseTest; 
    } 
} 

public class test_a_Home extends BasePage { 
    public test_a_Home(Locomotive baseTest) { 
     super(baseTest); 
    } 

    public void testifExists() { 
     test.validatePresent(site_a_Home.EL_NEWCUSTOMERBANNER); 
    } 
} 

那么你的测试类,我建议建立一个基类,以及:

@Config(
    browser = Browser.CHROME, 
    url  = "http://example.com" 
) 
public class BaseTest extends Locomotive {} 

然后你的测试类:

public class tests extends BaseTest { 
    test_a_Home test = new test_a_Home(this); 

    @Test 
    public void testHomePage() { 
     test.testIfExists(); 
    } 
} 

而且你的状态状态:

我不明白如何在Java中使用Selenium的@Config部分。

请确保你知道,使用Conductor从Selenium API中抽象出你..它只是包装它。 @Config不属于Selenium,属于Conductor。

+0

谢谢,它的工作。 –

+0

很高兴听到!继续并通过点击绿色选中标记将此答案标记为“已接受”,如果您觉得我配得上它,请继续并上传 – sircapsalot