简体   繁体   English

将Grid集成到Page对象模型

[英]Integrating Grid into Page object model

I currently run my tests from my local machine, I now want to run my tests from with Jenkins using selenium grid. 我目前在本地计算机上运行测试,现在我想使用硒网格在Jenkins上运行测试。

Currently my set up project set up is as follows: 目前,我的设置项目设置如下:

public BasePage(WebDriver driver){

    this.driver = driver;
    jsExecutor = ((JavascriptExecutor) driver);
    wait = new WebDriverWait(driver, 200);
}

public void loadPage(){

    driver.get(getPageUrl());
    driver.manage().window().maximize();
}

These methods are inherited by 这些方法是由

 CretePage.java

public CreateClass(WebDriver driver) {
        super(driver);
        this.PAGE_URL = "http://xxxxxx.12121/home";
    }


public void createClass(String name){
    openPage();
    findDynamicElement(By.id("id"), 12);
    clickElement(button_Save);
}

Then my test runs for the class RunTest.java 然后我的测试针对类RunTest.java运行

public WebDriver driver;
    public WebDriverWait wait;
    CreateLocation CreateLocation;


    @BeforeClass(alwaysRun = true)
    public void setup(){
        this.driver = new FirefoxDriver();
        wait = new WebDriverWait(driver, 10);

        CreatePage = PageFactory.initElements(driver, CreatePage.class );

@Test(priority=1)
public void createClass(){
    CreateClass.createClass("Selenium Webdriver Class");

}

Any code changes I have made so far has resulted in build failures or empty browsers been launched. 到目前为止,我所做的任何代码更改都导致构建失败或启动了空的浏览器。 Can anyone explain what I should try do or an article to read to help me with this matter. 任何人都可以解释我应该尝试做的事情或阅读一篇文章以帮助我解决此问题。

Assuming that you have your hub and one or more nodes set up and running, you'll need to use the RemoteWebDriver and DesiredCapabilities class. 假设您已经设置了集线器和一个或多个节点并正在运行,则需要使用RemoteWebDriver和DesiredCapabilities类。 This should all be done in the setUp(). 所有这些都应在setUp()中完成。 Something like this: 像这样:

@BeforeClass
public void setUp() {
    String baseUrl = "http://www.google.com"; // Wherever you start your test
    String nodeUrl = "http://localhost:4444/wd/hub"; // Whatever the URL is to your hub
    DesiredCapabilities capabilities = DesiredCapabilities.firefox();
    capabilities.setBrowserName("firefox");
    driver = new RemoteWebDriver(new URL(nodeUrl), capabilities);
    driver.get(baseUrl);
}

I found most of this info on Selenium's GitHub page . 我在Selenium的GitHub页面上找到了大部分信息。

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

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