Javascript Selenium IDE/Builder能否在多个页面上运行相同的测试用例?

Javascript Selenium IDE/Builder能否在多个页面上运行相同的测试用例?,javascript,selenium,jenkins,automated-tests,selenium-ide,Javascript,Selenium,Jenkins,Automated Tests,Selenium Ide,有没有一种方法可以在多个页面上运行相同的Selenium测试用例,而无需专门定义页面列表 例如,我有一个UIMap页面集,定义如下: var map = new UIMap(); map.addPageset({ name: 'pages', description: 'all pages', pathRegexp: '^thisistheroot/$' }); 在页面集中,我为要在页面集中的每个页面上测试的测试脚本定义了所有元素。 所有这些都添加到我的核心扩展中 我能

有没有一种方法可以在多个页面上运行相同的Selenium测试用例,而无需专门定义页面列表

例如,我有一个UIMap页面集,定义如下:

var map = new UIMap();
map.addPageset({
    name: 'pages',
    description: 'all pages',
    pathRegexp: '^thisistheroot/$'
});
在页面集中,我为要在页面集中的每个页面上测试的测试脚本定义了所有元素。 所有这些都添加到我的核心扩展中

我能在整个页面集上运行测试用例吗?我该怎么做

我对这个问题做了更多的调查。詹金斯有没有办法做到这一点

编辑:

我试图避免使用SeleniumWebDriver,但如果可以像在UIMap中一样获得链接,那么这可能也会为我指明正确的方向。我将尝试使用单个测试用例迭代链接,这可以用java轻松完成。顺便说一下,我正在使用java作为webdriver

谢谢。

简单的答案是“否”,但是
Selenium WebDriver
是确保找到页面链接并进行迭代的最佳选择之一。UIMapping有一个非常类似的概念,称为将所有页面元素映射到单独的类中,以保持职责分离,这使得调试和重构更加容易。我使用了PageFactory的概念

现在回到您的问题,您可以很容易地找到页面中存在的链接列表。在这种情况下,只需稍微小心地编写选择器。然后,您可以轻松地在链接上进行迭代,并来回访问等等

谷歌概念验证

package google;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.util.NoSuchElementException;

/**
 * Defines the generic methods/functions for PageObjects.
 */
public class BaseClass {

    protected WebDriver driver;

    /**
     * @param _driver
     * @param byKnownElement
     */
    public BaseClass(WebDriver _driver, By byKnownElement) {

        //assigning driver instance globally.
        driver = _driver;
        this.correctPageLoadedCheck(byKnownElement);

        /* Instantiating all elements since this is super class
        and inherited by each and every page object */
        PageFactory.initElements(driver, this);
    }

    /**
     * Verifies correct page was returned.
     *
     * @param by
     */
    private void correctPageLoadedCheck(By by) {

        try {

            driver.findElement(by).isDisplayed();

        } catch (NoSuchElementException ex) {

            throw ex;
        }
    }
}
package google;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;

import java.util.List;

/**
 * Created by Saifur on 5/30/2015.
 */
public class GoogleLandingPage extends BaseClass {


    private static final By byKnownElement = By.xpath("//a[text()='Sign in']");

    /**
     * @param _driver
     */

    public GoogleLandingPage(WebDriver _driver) {
        super(_driver, byKnownElement);
    }

    //This should find all the links of the page
    //You need to write the selector such a way
    // so that it will grab all intended links.
    @FindBy(how = How.CSS,using = ".gb_e.gb_0c.gb_r.gb_Zc.gb_3c.gb_oa>div:first-child a")
    public List<WebElement> ListOfLinks;
}
基本页面

package google;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.util.NoSuchElementException;

/**
 * Defines the generic methods/functions for PageObjects.
 */
public class BaseClass {

    protected WebDriver driver;

    /**
     * @param _driver
     * @param byKnownElement
     */
    public BaseClass(WebDriver _driver, By byKnownElement) {

        //assigning driver instance globally.
        driver = _driver;
        this.correctPageLoadedCheck(byKnownElement);

        /* Instantiating all elements since this is super class
        and inherited by each and every page object */
        PageFactory.initElements(driver, this);
    }

    /**
     * Verifies correct page was returned.
     *
     * @param by
     */
    private void correctPageLoadedCheck(By by) {

        try {

            driver.findElement(by).isDisplayed();

        } catch (NoSuchElementException ex) {

            throw ex;
        }
    }
}
package google;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;

import java.util.List;

/**
 * Created by Saifur on 5/30/2015.
 */
public class GoogleLandingPage extends BaseClass {


    private static final By byKnownElement = By.xpath("//a[text()='Sign in']");

    /**
     * @param _driver
     */

    public GoogleLandingPage(WebDriver _driver) {
        super(_driver, byKnownElement);
    }

    //This should find all the links of the page
    //You need to write the selector such a way
    // so that it will grab all intended links.
    @FindBy(how = How.CSS,using = ".gb_e.gb_0c.gb_r.gb_Zc.gb_3c.gb_oa>div:first-child a")
    public List<WebElement> ListOfLinks;
}
PageObject继承的BasePage

package google;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.util.NoSuchElementException;

/**
 * Defines the generic methods/functions for PageObjects.
 */
public class BaseClass {

    protected WebDriver driver;

    /**
     * @param _driver
     * @param byKnownElement
     */
    public BaseClass(WebDriver _driver, By byKnownElement) {

        //assigning driver instance globally.
        driver = _driver;
        this.correctPageLoadedCheck(byKnownElement);

        /* Instantiating all elements since this is super class
        and inherited by each and every page object */
        PageFactory.initElements(driver, this);
    }

    /**
     * Verifies correct page was returned.
     *
     * @param by
     */
    private void correctPageLoadedCheck(By by) {

        try {

            driver.findElement(by).isDisplayed();

        } catch (NoSuchElementException ex) {

            throw ex;
        }
    }
}
package google;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;

import java.util.List;

/**
 * Created by Saifur on 5/30/2015.
 */
public class GoogleLandingPage extends BaseClass {


    private static final By byKnownElement = By.xpath("//a[text()='Sign in']");

    /**
     * @param _driver
     */

    public GoogleLandingPage(WebDriver _driver) {
        super(_driver, byKnownElement);
    }

    //This should find all the links of the page
    //You need to write the selector such a way
    // so that it will grab all intended links.
    @FindBy(how = How.CSS,using = ".gb_e.gb_0c.gb_r.gb_Zc.gb_3c.gb_oa>div:first-child a")
    public List<WebElement> ListOfLinks;
}
链接迭代器测试继承BaseTest

package tests;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;

public class BaseTest {


    public WebDriver driver;
    String url = "https://www.google.com/";


    @BeforeClass
    public void SetUpTests() {

        driver = new FirefoxDriver();
        //Navigate to url
        driver.navigate().to(url);
        //Maximize the browser window
        driver.manage().window().maximize();
    }

    @AfterClass
    public void CleanUpDriver() throws Exception {
        try {

            driver.quit();

        }catch (Exception ex){

            throw ex;
        }
    }
} 
package tests;

import google.GoogleLandingPage;
import org.openqa.selenium.WebElement;
import org.testng.annotations.Test;

import java.util.List;

/**
 * Created by Saifur on 5/30/2015.
 */
public class LinksIteratorTests extends BaseTest {

    @Test
    public void IterateOverLinks(){
        GoogleLandingPage google = new GoogleLandingPage(driver);

        List<WebElement> elementList = google.ListOfLinks;

        for (int i=0;i<elementList.size(); i++){
            elementList.get(i).click();
            //possibly do something else to go back to the previous page
            driver.navigate().back();
        }
    }
}
包测试;
导入google.GoogleLandingPage;
导入org.openqa.selenium.WebElement;
导入org.testng.annotations.Test;
导入java.util.List;
/**
*由Saifur于2015年5月30日创建。
*/
公共类LinksIteratorTests扩展了BaseTest{
@试验
public void IterateOverLinks(){
GoogleLandingPage google=新的GoogleLandingPage(驱动程序);
List elementList=google.ListOfLinks;

对于(inti=0;i实际上,针对1个特定页面(实际上是基本url)运行IDE测试很简单:
java-jar selenium-server.jar-htmlSuite“*firefox”http://baseURL.com“mytestsuite.html”“results.html”

因此,您需要做的是使用jenkins(或任何bash/batch脚本)在基本url设置为“”的情况下多次运行该命令

这只会让您获得要测试的静态页面列表。如果您想要动态列表,您还必须“爬网”页面,您可以在类似的批处理/bash脚本中这样做,以获得要测试的页面列表


在这种情况下,您最好投资于selenium IDE之外的产品,并切换到webdriver,这样您就有了更强大的循环和流量控制能力。

我对您所做的编辑有点困惑。您是否在
webdriver
上寻求帮助?我可以同时使用这两种产品,但最好使用selenium IDE解决方案。如果需要
webdriver
ed,我有能力使用它。最近我被允许使用
WebDriver
,这就是我进行编辑的原因。所以,我的想法是加载每个页面并迭代页面上的链接?是的,想法是在多个页面上运行一个测试。所有页面都应该有相同的定位器,并且应该能够通过我所做的测试设计好的。好的,非常感谢!我会处理这个问题。将悬赏保留到最后,这样问题仍然会引起注意,但我会将它奖励给其他人。谢谢!我还提供了一个github链接,其中清晰地实现了PageFactory的完整概念。如果您想要更改页面模式,可以查看一下。很好的示例:-)@djangofan对此表示感谢!简单的答案是肯定的,但这并不容易。是的!这太棒了!这也允许我将IDE与WebDriver测试混合在一起,对吗?我的答案是“正确”一个,但我没有得到赏金?哈哈。我不知道你说的混合测试是什么意思?我想你也可以,如果你从命令行启动它们的话。我试图平等地传播声誉。就像我说的,我希望我能给你们两个,但赛弗有一个非常详细的答案,这对我帮助很大。我说的混合测试是指abl我想在同一Jenkins构建中同时运行这两个工具。我最初的想法也是同时执行这两个工具的命令行,这就是为什么我问这个问题。我在IDE中做了一些测试,在WebDriver中做了一些测试。我想让其他人更容易使用。页面对象模型也做到了这一点,这样我就能够在一个包含公共元素的页面列表上进行迭代。(一个有子类要迭代的超类)这是分割信誉的主要原因。