As these days I am working on designing Framework for my AUT in Selenium, I found information regarding the Page object Model Framework as being mostly used in Selenium. But I as I have gone through it, I saw a major drawback in it as being application dependent-We are defining classes based on application pages(or some specific functionality) which is not reusable across multiple projects.It has to be re -written for each application.Please all you guys, give your thoughts on it..!!
|
Somewhere in your automation framework there would be a layer which is application dependent. This is hard to avoid. I do find page object pattern useful as it does make tests meaningful and easier to write.
|
Administrator
|
In reply to this post by Vishal Aggarwal
Hi Vishal,
Page object is supposed to be application dependent as it encapsulates the features represented by a page. But you can always wrap Selenium 2 calls to more succinct methods so that you don't have to use driver.findElement....... kind of usage in all over your page objects. And you could simply use - type ("elelementLocator", "testdata"); This is the same syntax which is used in Selenium 1. Please refer this post for more on encapsulating Selenium 2 calls - http://www.seleniumtests.com/2012/01/selenium-2-methods-are-no-more-weird.html?utm_source=BP_recent Let me know if it answers your query.
~ seleniumtests.com
|
Tarun,
I completely agree with you. But my concern is as we are having multiple set of related applications(around 12) and all are plain web based. Earliar we were using an keyword driven framework(QTP-Vbscript) which was an common set of function libraries which we were reusing across all our projects. But now I see here we have to write it for every application and reusablity seems to be very low. My key question is: how POM is reusable across multiple projects? Thanks, Vishal |
Administrator
|
Vishal,
If you post an example of you how you were using keyword driven framework earlier with QTP, especially in terms of reusability. Then I might be able to get you same solution in Selenium as well
~ seleniumtests.com
|
Keyword Syntax:
perform|webButton;Submit|Click. This code will be written in excel to press an button called "Submit". There is a code behind this which is tied to the keyword "Perform|Click". This is something I can reuse in any web application for pressing buttons. |
Administrator
|
So Vishal,
As far as UI operations are concerned (click, type etc) you can still encapsulate them in one class and all of your page objects should extend it. Like - /** * Wraps selenium operations * * @author tarunb * */ public class ActionDriver { protected WebDriver driver; public ActionDriver(WebDriver driver) { this.driver = driver; } public void type(By by, String testdata) { driver.findElement(by).clear(); driver.findElement(by).sendKeys(testdata); } } You Page object goes here - public class GoogleHomePage extends ActionDriver { public GoogleHomePage(WebDriver driver) { super(driver); if (!isElementPresent((GoogleHomePageElements.getSearchBox()))) { throw new IllegalStateException( "This is not Google Search page. Page is: " + driver.getPageSource()); } } public GoogleSearchResultPage searchGoogle(String testdata) { type(GoogleHomePageElements.getSearchBox(), testdata); // Some more operations here return new GoogleSearchResultPage(driver); } } And your test class goes here - public class GoogleSearchTest extends SelTestCase { @Test public void testGoogleSearch() { GoogleHomePage googleHomePage = new GoogleHomePage(driver); googleHomePage.searchGoogle("Selenium HQ"); assert driver.getPageSource().contains("seleniumhq"):"Selenium headquarter search failed"; } } Do you see how similar it is to - perform|webButton;Submit|Click as operations like click, type are part of Action Driver class and all of your page objects classes extend from it. So these operations are available to all page object classes. Now any of the page object class in any project can use Action driver as Action driver class is independent of a project. Do let me know if I miss understood you.
~ seleniumtests.com
|
Thanks Tarun, for clarifying my doubts.
|
Administrator
|
I would also suggest you to see Page Factory pattern - http://code.google.com/p/selenium/wiki/PageFactory
You can think of it Selenium way of QTP repository mechanism
~ seleniumtests.com
|
In reply to this post by Vishal Aggarwal
Can't we hide this Vertical bar (which has Tweet,Submit,Digg,FShare etc - This is really annoying to write anything on this site)
I I created one sort of framework: 1. This is not POM - I feel, though it has functions with page/specific action (e.g.Login) 2 . This is just like Switch + Case based. So, just by changing the test data in the XLS file, we can control the entire script flow - No need to change the code, ever. 3. I created a Enum data type class, in which all my keywords are declared as data types. 4. I have different functions to do different tasks. These functions have the flexibility to be called from any other function. THESE are not at all related to a single page/screen. Using the ValueOf function for the Enum class object, I compare values. 3. Public Class m{ public void (or String....) UserDetails() { MyEnumClass mec = new MyEnumClass.ValueOf(stringvariable) Switch case name: --In a single function I verify existence and verify enabled/disabled - Enter Data (and write the result into XLS that entered dta successfully.) case Street: --In a single function I verify existence and verify enabled/disabled - Enter Data (and write the result into XLS that entered dta successfully.) ------------------------------------------------- end of Switch The above name,Street are Enum data taypes. These are present in the test case like: name - Rao Street - XSTreet ThThis data will be put into a single array (feteched from the XLS), and I iterate until the loop ends. Sorry, could not explain in a clear way. This requires a lot of time. } } |
Administrator
|
@Illusion0Reality, Appreciate your participation in group.
Does this bar overlaps when writing a response? I checked it with two systems and looked ok. I kept this bar so that group could be shared more. Could you send me one snap shot at - tkumarb at gmail.com and I could try to fix width again.
~ seleniumtests.com
|
In reply to this post by Vishal Aggarwal
Now, it is okay. Seems it has been shortened in height.
If it can be placed on the extreme right side, maybe, more better. Because at the right we have more margin/empty space. Initiallty it obscured this whole text area, so I could not see what I was writing.vbar.JPG |
Administrator
|
@Vishal,
You wish is my command :) I moved it to right. Is it any better now?
~ seleniumtests.com
|
Thanks Tarun, not only it looks nice now, but also I am comfortable to write anything.
|
I agree with Tarun.
By designing and implementing the framework below, I have the exact replica of QTP keyword framework in Selenium as well. Like QTP keyword driven approach, we can write sepcific functions to do specific tasks. To enter data - we write specific function, which enters data by taking 2 parameters - id,test data. This function will obviously application independent. Only the case statements (in SElenium), can be arranged with app. specific keywords. Switch (abc.ValueOf(myvar)) //as u see, like in QTP, here also, based on the keyword's value, a specific case statement will be executed. { Case username; -- call the function which verifies the existence and enabled etc... -- call the function to enter data/click object etc. - Here, 2 parameters are test data and id/locator--- //the above 2 functions are application independent, hence can be used with any application ------- Case pw; Case address; Case phone; case navigation; } |
In reply to this post by softwaretestingforum
Hi,
I have a small query redg. application independent framework design. Say i have two different AUT, one is for flight reservation and other a social networking site. If I am able to understand it correctly, 1. Do we need to create page object class for each AUT, which may extends from Action Driver class ? 2. If yes, would not be a keyword driven framework be suitable in such scenario? Thanks, Abhishek |
Administrator
|
Given the approach I described earlier answer is Yes
Could you elaborate more on how keyword driven would be suitable?
~ seleniumtests.com
|
In reply to this post by Abhishek
Abhishek,
What Do you mean by keywords here? Are you talking about lower level action keywords like "clickbutton" or higher level application keywords like "CreateOrder" or "MakePayment"? In case if you are talking about higher level application keywords and the applications are not related( as in your scenario) then those keywords can't be re-used as well.Let my know if you differ on it. -Vishal Aggarwal |
In reply to this post by Illusion0Reality
Hi,
I kind of agree with Vishal, how is it reusable still. What to do with options which are common across all pages. What I was doing currently in POM was, extend each page class with Base class which has functions common to all pages - logout link, Menu navigation,etc. In that case, where do we put in Action class. |
Free forum by Nabble | Edit this page |