Total Pageviews

Monday, December 19, 2011

Different ways to verify pop-up/Window using selenium


SelectWindow:

If the window name/title is null, then we can focus the window/pop-up as below mentioned manner:


For this we can use, selectWindow | windowName command and to go back to main window from other window, we can use  selectWindow | null


Arguments:
  • by windowid - the java Script window id of the window to select. - Selects pop-up window id using window locator; Once a window selected, all the commands will execute on the pop-up window until main window selected.  To select the main window, use null as a target.
We can select the window by providing different objects:
  • by title, by internal java script "name" or by java script "variable".
    • title= MyWindow: This text appears in the title bar. some times two windows can have the same title, in that scenario, this locator will just pick one. 
      •  name=myWindow: Finds the window using its internal JavaScript "name" property. This is the second parameter "windowName" passed to the JavaScript method window.open(url, windowName, windowFeatures, replaceFlag) (which Selenium intercepts). 

      • var=variableName: Some pop-up windows are unnamed (anonymous), but are associated with a JavaScript variable name in the current application window, e.g. "window.foo = window.open(url);". In those cases, you can open the window using "var=foo".


selectPopup:

If it is a popup then do selectPopUp | windowId and then to go back to the main window do selectWindow | null

selectPopUp(windowID) Arguments:

    * windowID - an identifier for the popup window, which can take on a number of different meanings

Simplifies the process of selecting a popup window (and does not offer functionality beyond what selectWindow() already provides).

    * If windowID is either not specified, or specified as "null", the first non-top window is selected. The top window is the one that would be selected by selectWindow() without providing a windowID . This should not be used when more than one popup window is in play.

    * Otherwise, the window will be looked up considering windowID as the following in order: 1) the "name" of the window, as specified to window.open(); 2) a javascript variable which is a reference to a window; and 3) the title of the window. This is the same ordered lookup performed by selectWindow . 

Sunday, December 18, 2011

Verify the color of an object using selenium


The HTML code is
//<input name="input" class="form-text required error" id="edit-input" type="text" size="20" maxLength="255"/>

//<input name="op" class="form-submit" id="edit-submit-1" type="submit" value="Submit"/>

The Code example to check the above behavior is
@Test
  public void iscolorchanged() {
        org.openqa.selenium.ie.InternetExplorerDriver driver = new org.openqa.selenium.ie.InternetExplorerDriver();
        driver.get("the url to test");
        WebElement submitbutton = (new WebDriverWait(driver, 10)).until(new ExpectedCondition<WebElement>(){
            @Override
            public WebElement apply(WebDriver d) {
                  return d.findElement(By.xpath("//*[@id='edit-submit-1' and @name='op']"));
            }}); 
        submitbutton.submit();
        WebElement inputbox = (new WebDriverWait(driver, 10)).until(new ExpectedCondition<WebElement>(){
            @Override
            public WebElement apply(WebDriver d) {
                  return d.findElement(By.xpath("//*[@id='edit-input'and @class='form-text required error']"));
            }}); 
        Boolean colorchanged;
        String color= inputbox.getCssValue("border-color");
        if(color.equals("#ff0000"))
                    {
                          colorchanged=true;
                    }
                    else
                    {
                          colorchanged=false;
                    }
                   
        System.out.println( colorchanged);
       
        }

Gathered from Net

Monday, December 12, 2011

Selenium Locaters - Hand Book

Hi all,

Here I added a new hand book which I got it from Net. This is very useful for selenium testers to construct Objects.

You can download this from here

Selenium Locaters - HandBook