Can Selenium IDE / Builder run the same test case on many pages?

Is there a way to run the same Selenium test case on many pages without specifying a list of pages specifically?

Let's say, for example, I have a UIMap page defined like this:

var map = new UIMap();
map.addPageset({
    name: 'pages',
    description: 'all pages',
    pathRegexp: '^thisistheroot/$'
});

      

In a set of pages, I have all the elements defined for a test script that I want to test on every page in the set of pages. These are all added to my main extensions.

Is it possible to run a test file on an entire set of pages? How can i do this?

I went over this issue a little more. Is this possible with Jenkins? https://jenkins-ci.org/

Edit:

I tried to avoid using selenium webdriver, but if links can be obtained like in UIMap it will probably point me in the right direction too. I would try to iterate over the links with a single test case, which can be done easily in java. By the way, I am using java for webdriver.

Thank.

+3


source to share


2 answers


Actually, just run an IDE test with 1 specific page (base url actually): java -jar selenium-server.jar -htmlSuite "*firefox" "http://baseURL.com" "mytestsuite.html" "results.html"

So, you need to use jenkins (or any bash / batch script) to run this command multiple times with base url set as " http://baseURL.com/page1 ", " http://baseURL.com/page2 " and etc.



This will only result in a static list of pages for testing. If you want a dynamic list you will have to "crawl" the pages as well, and you can do that in the same batch / bash script to get the list of pages to test.

In this case, you are better off investing outside of the selenium IDE and switch to webdriver where you have more control over the loop and flow.

+2


source


The simple answer is no, but Selenium WebDriver

one of the best options is to find the links to the page and repeat them. There is a very similar concept to your UIMapping called PageFactory , where you map all elements of a page in separate classes to keep responsibility separate, which makes debugging and refactoring much easier. I used the PageFactory concept here .

Now back to your question, you can easily find the list of links present on the page. In this case, you just need to write a selector a bit. Then you can easily iterate over the links and go back and forth, etc.

Google proof of concept

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;
        }
    }
}

      

PageObject inherited BasePage



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;
        }
    }
} 

      

Link Iterator that inherits BaseTest

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();
        }
    }
}

      

Note. I am using TestNG for running tests and please note that for lazy loading page you may need to add an explicit wait if needed

+3


source







All Articles