seleniumbase / SeleniumBase

📊 Python's all-in-one framework for web crawling, scraping, testing, and reporting. Supports pytest. UC Mode provides stealth. Includes many tools.
https://seleniumbase.io
MIT License
5.34k stars 980 forks source link

关于元素封装 #392

Closed meilisong1 closed 5 years ago

meilisong1 commented 5 years ago

看了下页面元素都是写在脚本当中,需要自己再封装一下,把所有的元素都放到单独的yaml文件中,这样管理起来也方便,统一修改

mdmintz commented 5 years ago

Hello @meilisong1 , You can place page elements (selectors) in a page_objects file so that you can encapsulate them for better code reusability. See the example here: https://github.com/seleniumbase/SeleniumBase/blob/master/examples/boilerplates/page_objects.py

meilisong1 commented 5 years ago

Hello @meilisong1 , You can place page elements (selectors) in a page_objects file so that you can encapsulate them for better code reusability. See the example here: https://github.com/seleniumbase/SeleniumBase/blob/master/examples/boilerplates/page_objects.py Thank you very much, this framework is very good, I am trying in the project, refueling

allandsouza commented 4 years ago

Indeed an excellent framework.

The challenge I am currently having is in trying to consolidate page actions in a test, as a method of the page object itself. E.g. the below two lines of code in /boilerplates/page_objects.py could be thought of as a behavior of the shoppingPage i.e. ShoppingPage.add_buyable_item_to_cart() self.click(ShoppingPage.buyable_item) self.click(ShoppingPage.add_to_cart)

The problem though is that the click and other driver methods are not available in the page objects. I understand its because the page objects do not inherit BaseTestCase. Any recommendations on a good way to implement this?

mdmintz commented 4 years ago

@allandsouza Have your BaseTestCase import and use the page_objects you created. The page_objects just store the selectors. Here’s the outline BaseTestCase: https://github.com/seleniumbase/SeleniumBase/blob/master/examples/boilerplates/base_test_case.py

allandsouza commented 4 years ago

Thanks for you response @mdmintz. I had already looked at the outline when evaluating selenium base. My point precisely is about "The page_objects just store the selectors". While that's true in seleniumbase; in general, from a concept/design standpoint, a page object will have elements & behaviors. E.g. https://www.pluralsight.com/guides/getting-started-with-page-object-pattern-for-your-selenium-tests. I have found the ability to define behavior's in page objects to be super valuable.

I understand this could mean a significant redesign+effort and may not be on your roadmap. But wanted to share my thoughts just incase you have a good way to support it.

Regardless, I love seleniumbase and "THANKS" to all the work you are doing to maintain and support it.