Complete Page Object Model (POM) using Page Factory in Selenium
ฝัง
- เผยแพร่เมื่อ 12 พ.ย. 2024
- This video will focus on how to design page object model using Page Factory.
In Selenium Webdriver POM is very widely used design pattern.
For more info check out my blog
learn-automatio...
~-~~-~~~-~~-~
Please watch: "How To Create Maven build For Selenium Framework"
• How To Create Maven bu...
~-~~-~~~-~~-~
If I could put more than 1 "like", I would do it!
Chill got u covered after 5 years
I am unemployed manual tester and they are not trainings here that give you the knowledge and prepare you for the career in automation, just learning from videos on TH-cam like yours. Actually most that I like are yours and I think I am advancing.
Thank you
Thats Great Eva.. Never stop learning.. Keep in touch and let me know if any help required from my side.
Thanks Mukesh for your detailed video. I have taken couple paid selenium courses but none was as clear as you explained. I really appreciate and value your time in making these free videos. Keep Rocking Champ :)
+sathissh s Hi Sathissh, your comment made my day :)
Thank you keep visiting.
Hi Mukesh
Thank you so much for this video.
This is very helpful and you explained it very easy and clear way.
Now I want to watch all your videos.
Also, your english is very fluent and clear.
+Borna Hossain Thanks Borna.. Let me know if any help required..
This is covering scalability as well. Good video.
Thanks Nandhis I am glad it helped you.
Hi Mukesh from Turkey !!!
Than you for all videos !!!
+karacan kayar Thank you Karacan :)
Hi Mukesh,
I've been watching all your videos for quite a while. All of them are very informative and i've learned a lot from your videos. Kindly keep posting the videos like this. Thanks a lot for your help:-)
+Saikiran Palugula Thanks SaiKiran yes sure I have so many topics in Pipeline will upload soon.
Happy weekend
You are a great teacher, I really appreciate how you take time and explains every steps in details !! Thank you
Great video Mukesh. I am self learning Selenium WebDriver Automation.
This was helpful.
Thanks.
Hey Jon Gald to know you liked. Keep visiting.
Very well consolidated..Thanks a lot Mukesh for sharing...!!
Keep visiting Kuldeep.
Hi Mukesh,
All the videos are awesome and very very helpful.
Thanks for sharing these :)
+saurabh Pandey Thanks Saurabh panday keep visiting :)
HI mukesh ,
Thanks a lot for this video i got so much knowledge through your videos.Thanks for the video on Page Factory really help full.
+Purushothama MB Hi Purushothama Thank you. I am glad that it helped you.
Thank you, Mukesh, you've saved my life!
Great man :) Cheers
the best tutorial in youtube... thanks a lot for the help Mukesh. :)
Thank you Jincy
it was an excellent video about page object model, thanq so much... actually I have a doubt in page factory implementations it clarified me..
Hi Naresh I am glad to hear it clarified your doubts.Cheers
Excellent video tutorial !!! Everything is explained in details!! Keep it up man.
Thanks Shahin I am glad it helped.
Hi mukesh great day to you and again great lesson! very helpful!
well just wanted to ask if you have a lesson for the auto suggest text box?
Hi Marven after 16 may I will be having so much new content.
i am ready mukesh! bring it on!
Thank you so much for this video....It helped me immensely....All my confusions resolved...
Thank you Maya. Glad it helped.
Great tutorial video. You made what looked like super complex concepts very easy to understand.
Clearcut explanation.Thank you Mukesh
Thanks Ninu :)
good ..I think we should set the system properties for crome and IE?
+Prince Nawsher yes we have to set the property for chrome and IE.
Thanks Mukesh, Got learn new concept Page Factory...
Welcome Kiran. happy weekend.
Hi Mukesh Ji,Thanks a lot for sharing this video with us.It was very informative(Please sharing the code created from this video,if possible,from Google Drive...or others).Please continue to share your experience.All the Best and MAY GOD BLESS YOU!!!.
+Madiraju K Chaitanya Hi Chaitanya ji, I will update the code in blog tomorrow.
mate! u r a great teacher! keep on doing this! greetings from Argentina
😀 Ur comments made my day..
Hi mukesh ,
Its a very good session .will help us lot in improving to learn automation.Thanks for good session .
Hi Vamshi, I am glad to know you liked it. Thanks you
Thank you very much Mukesh
Wonderful presentation !
Thanks
Sai
+baruri saikiran thanks Sai keep sharing and keep visiting
Thanks Mukesh for the good video!!
I have a doubt on Page factory, how can we select a drop down value using @FindBy ?
+madipelly naresh identify dropdown and use Select class as we do for normal scripts.
Hi Mukesh, Thanks for the video.
I need to ask a question that how i can run 2 test cases in series e.g I want to run Loginpage first and then postpage.
I am not able to run the second test case because the user should be already logged in for 2nd case to run.
Please help !!!!!!!!!
Hi Gaurav, You can use TestNG priorities (i..e in your case, for Loginpage set (priority=1), and for the post page set (priority =2) or you can use dependsOnMethods to prioritise your test cases.
Fantastic video, 5Star. Helped me a lot to work on real time project and crack interviews
Great Mate :) Cheers
Hi Mukesh, why do we need a construtor in this example? (11.38). We are not using it anywhere in the class file. I tried without a constructor and it worked fine. Can you help please?
Hi Riju, If you want to use driver is pages then you need constructor to work with driver.
Many many thanks Mukesh ! The doubt that I had is that dont you have to do System.set property(" ",""); in case of chrome driver?
Hi Nidhi I used the same step to make it work in MAC
learn-automation.com/firefox-browser-on-mac-using-selenium-webdriver/
learn-automation.com/chrome-browser-on-mac-using-selenium/
We can also do the same thing in windows too using Env variables.
Hi Mukesh, My Bad .....I was referring to the Concept in the video at 15:30, where you check the browser type and then you assign the driver accordingly. So in case if the browser happens to be chrome , apart from assigning the WebDriver object driver as ChromeDriver, would we also need to do System.setpProperty (ChromeDriver," Path of the chromeDriver");.
It 's very useful mukesh. Keep posting videos like this.
Thanks Manoj :)
Great videos again ! Have you any videos for data driven testing (reading from Excel) using Page factory?
No as such you can use the same logic for Page Factory as well
This video helped me to clarify my thoughts on page factory. I wanted to know in the @test class could i create object as simply as LoginClassName objA ? and import the class and call my methods from LoginClassName by objA. ? That's what I was doing until now and things didn't go well but with creating object with pagefactory in @test showed from you a new way to approach it and it worked for me. Thank you.
Hey Hossain, I am glad to know it worked for you. I always use PageFactory approach which worked for me always.
Hi Bro I have did the assignment which you gave and it run successfully
Good Shashank bhai Keep it up.
Thank you Bhai Please help me with more information about selenium can you please contact me through my email i can call you
Good explanation and easy to understand ...Thanks Mukeh...
Always welcome Venky.
Amazing and Crystal Clear Example
Thanks Mukesh..Nice explanation..short and sweet..
I Would like to request you, Kindly make video to explain any one testing project with complete framework details at one time,
Hi Gajanan, You can play this playlist th-cam.com/video/vFXL4nMWvXI/w-d-xo.html
Great! Thnks. But how to be with an Ajax on the page if it's elements are initialized at the start? Is there a way to refresh the elements?
Hi Julian for Ajax control you can still use @FindBy or normal By class as well.
Briliant description !
Thanks Shwetank :)
So nice !! Thanks a lot for your contributions and time !!!
thanks :)
very helpful to better understanding of POM
I am glad to hear that Sudheer
@@Mukeshotwani I made classes for login and post, can you guide me to run these 2 class combine at a time e.g first login then post.
Very helpful videos! Thank you Mukesh!
Thanks Eva
hi mukesh...i added enter title and content and publish button elements in seperate addnew page..while entering title text it is giving null pointer exception what might be the problem?i added constructor as well
+gr reddy Hi Please share the code as well.
Thanque for your reply mukesh.It worked.But please clarify one more, suppose if we have some constant elements in multiple pages(Ex :Home ,SignIn links),in which page do we write them(write only once right !!)?
Hi Mukesh
Very helpful to better understanding of page factory,please let me know how to find when List instead of WebElement.
Hey Leela, as per latest post by simon (creator of Selenium) on twitter that @findBy will be deprecated soon.
Use By class in pageObjects.
@@Mukeshotwani Thanks mukesh for the update.pls let me know how to find List by using By class
Hi Mukesh, is there any video which includes entire framework like POM page factory , Data driven using excel ,TestNG reports, Maven with jenkins. Need to see an end to end flow ? It would be helpful .
Hi Shirish uploading soon.
Mukesh otwani Thank you..we are waiting for it
Hi Mukesh,
I am little bit confused between '@FindBy(id="") and @FindBy(how=How.ID,using="")'. Which one is better to use. Can you please help me with the difference between these two?
Good and Easy to understand. Passing parameters and return is little bit complex. so if could you create another video that could be more useful for Beginners
Hi Sushanth, yes will create soon.
Thank you for the amazing video..I have a query.. for example I want to implement fluent wait..and want to give a condition to wait for an element with a locator may be xpath. How would I do it? normally I do
WebElement element = (new WebDriverWait(driver, 50))
.until(ExpectedConditions.elementToBeClickable(By.xpath(YC_compName)));
here instead of By.xpath(YC_compName), what can be used?
Hi Mukesh,
I tried whatever you gave the assignment. I created the new page for Posts and I created the new testcase also. But how to continue this new testcase after login page testcase? Why because we already given the BrowserFactory with browser and URL and how will we continue with this in new testcase? I added all the class files in xml file and executing as a testNG suite.
+Shiva D Hi Shiva,
After login you have to initialize the post page then you can continue with the remaining steps
Hi Mukesh,
We have already a separate class file for Login. By continuing the post page in the login file, I have created another class file for post page and I'm trying to execute in a testNG xml file.
In every new test case we should call the BrowserFactory class file , it will open separate browser then how will it find the element?
+Shiva D Hi Shiva it will be seperate session so it wont create any issue.
Hi Mukesh ,I learn lots of things from your videos .
Question . How and where to use visibilityOf Element method in Page Factory?
Hi Mukesh,
This video is very useful for me to get start with POM. Could you please help me to understand what is the main differences bet ween normal approach and POM, in normal approach we will keep all the elements info in property file and we will call and use. What could be the main difference.
Thanks.
Both are perfect but in OR every object in same file so searching element would be difficult. In Page object model we would be storing based on functionality so it makes our test robust.
Hi Mukesh ,
I implemented the page object model using page factory , but when i run i am getting the java.lang.NullPointerException.
Can you please help me in overcoming this exception.
Thank You
+phani indra Hey Phani send code to mukeshotwani@learn-automation.com
Hi Mukesh, Thank you so much for explaining Page Factory. I did your assignment but one problem. It does not identify the text body element where you write your post, giving 'nosuchelementfoundexecption', all other elements are working fine. Can you help me on this?
+Nirmala Nirmi Please send me ur code to mukeshotwani@learn-automation.com
I need help on switching windows,frames, uploading and downloading files, reading and writing into an excel sheet using page factory. Could you please help on this
HI Mate, I have videos for all the new topics on my channel. Please do check and let me know if you face any issue.
@@Mukeshotwani thank you for your reply Mukesh. Could you please message the youtube handle for the concept of pagefactory that I asked in the above comment. Thank you so much
While using how class you have used the variable “using” ,what is the use of it and also we haven’t defined it anywhere in the code .Can you explain the need of using variable .
Hi Sumathi, using is predefined keyword in pom.
@mukeshotwani very good explanation , can you please tell me, is it important to have every page class contain it's own constructor to initialize ?
Hi Mukesh,
Why did you declare startBrowser as static? Can we declare it as ordinary method instead?
So that I can call using Classname
Nice tutorial appreciate your efforts
thank you!!
Hey Mukesh, thanks for amazing video. Can we limit webdriver scope when we use pagefactory in automation framework?
Hi Mukesh
Thanks for your video. I have a question which lib I have to use for email notifications. And do you have any video for that ? Please give me link .
Thanks and regards
Md Chowdhury
I have videos on this common email is the API name
Please can You give me the link ?
Thank you Mukesh for giving these videos...how to find sequence of selenium videos
Hi Rajesh you can find the order here learn-automation.com/selenium-webdriver-tutorial-for-beginners/
Hi Mukesh.
Could you pls explain in two words, what is the advatage of this factory pattern/model comparing to simple page object model?
In current example it seems like this is just more complicated and does not increase readability and maintenability, comparing to POM...
Hi, Can we initialise PageFactory in LoginPage class constructor only?
LoginPage(WebDriver driver)
{
PageFactory. initelements(driver, this);
}
In Test Case How we have to write assertion?
+Manjunath B.N Hi Manjunath, yes we can intiliaze in this way as well. For assert you can directly write assertEquals method.
Check below post for more detail.
learn-automation.com/capture-error-message-in-selenium/
This is very helpful ... Thank you
Your most welcome Sunday Jeremiah
Hi Mukesh.. Thanks for the efforts that put in for the videos. Its very really awesome.Trying to learn automation watching your videos only :)
I have a quick question about the property file and PageFactory when i was thinking to co-relate in between the two. can it be done and will it give any advantage if we are already having @cache annonation in pagefactory model?
Hii sir, I m getting Null pointer exception even I followed as you said.can you explain what might be the reason?
Hi Mukesh,
I am following all your vedios from the past few months.They are really well explained . I am looking forward for a live project to work on .Do u provide such live project training.if yes then please provide me the details.
+Moni Mathur Hi Moni glad to know that :).
.. Kindly mail me @ mukeshotwani@learn-automation.com
Hi Mukesh, What is the best way among page factory and normal approach considering huge framework.
Hi Mukesh,
Thanks for the video.I have one doubt can you pls tell me what is the purpose of changing the return type from void to Webdriver in the helper (Browsername class).
Mukesh, While using the POM concept, how do you integrate variables from a properties list?
thanks for this technical video
+fran ferris welcome Fran I am glad you liked it
Hi Mukesh.
Very good explanation for beginners. I am from California and looking for automation training. Is there any way to learn it from you other than the you tube videos you post.
Thanks
+Dimple Bajaj Hi Dimple Bajaj thanks a ton for nice feedback. Yes I have details which I want to share. Please send test email to my id I will share the details mukeshotwani@learn-automation.com
Hi mukesh but this why browser factory necessary it's lot of confusion and u create a return type in that so confusion
Hello Mukesh bro you teach awesome.
I have a small doubt, in page object model how to get TestData from excel file and use it in web application.
I tried but i cannot figure it out kindly help me please.
Hi Sandeep,
below guide will guide you
learn-automation.com/read-and-write-excel-files-in-selenium/
Hi Mukesh,
How can handle Object Repository for Webtables in POM.
Scenario like i need to read the users data from the data table and i need to create object for the datatable attribute in Object Repository. so how to handle in the Object Repository?
Thanks in advance.
Regards,
Venkatesh
Hi mukesh....how to find web element's' using @findby
Hi Vinith can u try using By ?
Please follow this updated playlist th-cam.com/play/PL6flErFppaj0WwNOMFeXPVlNCDuJyPYFi.html
In verifyvalidlogin class we need to pass url right then i was tried but am unable to get that startBrowser() method after BrowserFactory.
Hii Mukesh ur superb the concept of POM now fully cleared but some extra things like how to use Loadable Component in POM can u pls elaborate it by creating a video...........pls help me out.
Sir finally I got output I recognized my mistake I made the code correctly then your assignment is little bit tough but still I didn't try I have no time to do your assignment but in future I shall do Sir thank you
No hurry take your time for assignment
Hi Mukesh, thanks for the video. Your videos have been helpful! I have tried this scenario. Like others I am also getting nullpointer exception on the second page that I've created. I have created the constructer on each page. I am unable to resolve this issue. Please help! Thanks.
+Neetu Hi Neetu can u please share ur code mukeshotwani@learn-automation.com I will fix the issue.
+Mukesh otwani Looks like I lost the access to this demo site. Cannot learn on this application any more ):
Hi Neetu I have another site for demo or practice demo.avactis.com/4.7.9/
Hi . can you please tell where you write the link for the demo site. I am not able to find. Thanks
Hi Kanika, you can use any web application for automation.
Here is the credentials for demo site
Admin Page: s1.demo.opensourcecms.com/wordpress/wp-login.php
Username: opensourcecms
Password: opensourcecms
Hello, I am getting exception while running program as 'Timed out receiving message from renderer'.
Whereas same program runs fine without Page factory
Hi Pallavi this issue comes with new page loads. You can suppress this warning using ChromeOption.
HI Mukesh,
Which is the widely used framework in the industry now a days Page object design pattern or Data driven?
Can we combine both Data driven And POM together and can write a script.
if we learn POM is enough?
Am new to selenium Please suggest me.
Thank you.
+Purushothama MB Hi you can implement POM with any framework because it is just design pattern.
I generally use POM with hybrid framework.
@Mukesh I am trying to implement POM. My application has registration link and clicking on the registration link opens a popup.
So when you start the process, the popup will navigate to 3-4 screens as popup.
Suggestion please do I need to create Pages for each of the popup . OR shall I define all the locators for the popup screens on the Registration page itself.
+Satnam Singh Hi Satnam I would suggest keep it in Registration page only.
Hello Mukesh, just a quick question instead of making startBrowser () and WebDriver driver as static (in BrowserFactory class) cant we take it as a nonstatic for both method and variable, or is there any specific purpose we have made both as static.
Usually Factory Designs use static methods.
Here in this case I believe, this method is static, because it only work on arguments provided to it. It does not change the state of Object.
Hi Mukesh, i wanted to know one thing. Where would you put the quit method in this framework?
I used in AfterSuite
Mukesh otwani thanks a lot. Your videos really helped me clear one of the interview
Hi Mukesh
I went through your course package at learn-automation.
I know the basic stuffs of framework and know how to pass the value using hard coding, like you have explained in page factory.
But now i want to explore more by using excel sheets to send data like start date and end date in two different calendars. Would your paid course help me on this ?
Please let me know.
Regards
Yes it will help in case you have additional requirement then let me know :)
The Best explanation. Thank you
Thanks Mukesh.. What is the difference between HOW and @FindBY. Like when to use HOW.
Both are used for finding element but how class adds more readability in script.
hi mukesh , i am not able launch browser everything is correct.. is setproperty requiired in code???
Hi Mukesh.
Please give an example on how to use assertion for verifying login details for the above program.
Thanks
Hi Mukesh
I have one question?
For object repository which one is the best page factory or By locators?
TIA
Hello Mukesh,
My project is having lot of reusable functions. Currently i'm NOT using Page factory and I have created separated classes for Page Objects, Re-usable functions and Test Cases. Here, If I follow Page Object Model using Page Factory, then should I write all reusable methods on the page objects class itself or is there any way to separate page objects and re-usable functions.
Very neatly explained. Thanks
Thanks buddy.
Great video!!! Kool stuff
tHANKS Sudarsan keep visiting.
hello Mukesh, please can you help me out? I want to write a java method/function that clicks on one button call: "ExpandAll" to display or show hidden fields or names hidden under lettered buttons in a column. The ExpandAll button has an attribute value=true. where true displays hidden fields and false hides the fields.
+Rosalyn Abankwah Hi Rosa,
Any sample application for reference?
+Mukesh otwani I have to show you through teamviewer
+Mukesh otwani I have to show you through teamviewer
+Mukesh otwani I have to show you through teamviewer
+Mukesh otwani I have to show you through teamviewer
good video..informative..
+Shreyansh jain Thanks
Thanks Mukesh.
Welcome bro. Keep visiting and let me know if any help.
Hi Mukesh, will cacheLookUp solve staleElementException?
Hi Raman, in most of the cases yes because it does not look in web everytime plus it also reduce script execution time.
I have read sonewhere that using page factory, we can avoid stale elements exception,, how come?