Automation Using Selenium Webdriver

Thursday, 20 October 2016

Page Object Model(SingIn-Page)Exp

By Using Page Object Model SignInPage  Store Locaters and Test  Best Example for (Singin-Page)

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

/**
 * Class which models the view of Sign-In page
 */
public class SignInPage {
 
    @FindBy(id="username")
    private usernameInput;

    @FindBy(id="password")
    private passwordInput;

    @FindBy(id="signin")
    private signInButton;

    private WebDriver driver;

    public SignInPage(WebDriver driver) {
        this.driver = driver;
    }
 
    /**
     * Method to perform login
     */
    public HomePage performLogin(String username, String password) {
        usernameInput.sendKeys(username);
        passwordInput.sendKeys(password);
        signInButton.click();
        wait.ForPageToLoad();
        return PageFactory.initElements(driver, HomePage.class);
    }
}


import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
/**
 * Class which models the view of home page
 */
public class HomePage {
    @FindBy(id="logout")
    private logoutLink;

    private WebDriver driver;

    public HomePage(WebDriver driver) {
        this.driver = driver;
    }
 
    /**
     * Method to log out
     */
    public SignInPage logout() {
        logoutLink.click();
        wait.ForPageToLoad();
        return PageFactory.initElements(driver, SignInPage.class);
    }
}

/**
 * Login test class
 */
public class LoginTest {
    public void testLogin() {
        SignInPage signInPage = new SignInPage(driver);
        HomePage homePage = signInPage.login(username, password);
        signInPage = homePage.logout();
    }
}

Challenges faced while working on Selenium

Challenges faced while working on Selenium

There are many challenges we face while working on selenium. Some of the challenges are:

Challenges faced that are as follows:
·         Frequently changing UI. It always need to make changes in code most of the time.
·         Stuck somewhere while running automation scripts in chrome browser getting error that element is not visible, element not found.
·         New kind of element like ck-editor, bootstrap calendar and dynamic web tables. But get the solution always.
·         Reused of test scripts.
·         To be continued

1. configuration challenges on different machines
2. selenium's compatibility with browser versions like with FF20 is not supported with some web-driverversions.
3. handling IE/chrome etc.
4. popup handling
5. Ajax handling
6. security certificate handling
7. iframes
8. date pick from calender.
9. identifying locators
10. Upload and download file
11. Maintain the scripts to work properly irrespective of new build
12. Diff to identify script has failed may be unable to locate the element
or config issue(Browser updated) if your framework is not able to catch issue.
13. If you are using xpath as a locator. writing xpath without using dynamic changing data.
i.e., xpath generated dynamically.

Enter a text without using SendKeys method() in Selenium Webdriver

How to Send text without using sendkeys methods

public class type{

public static void setattribute(WebElement element,String attributename,String Value){

WrapsDriver wrappedElement=(WrapsDriver)element;
JavascriptExecuter driver =(JavaScriptExecutor)wrappedElement.getWrapedDriver;
driver.executeScript(arguments[0].setAttribute(arguments[1],arguments[2]",element,
                                    attributeName,value);
}

//or

JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript("document.getElementById('email').value = 'thotajagan@gmail.com';");


Onemore Example:

driver.get("http://facebook.com/");
WebElement cssValue= driver.findElement(By.xpath(".//*[@id='s']"));
JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript("document.getElementById('s').value='Virender Testing   
sending'");