英文:
In Page Object Model, should an overlay modal window be treated as a separate Page Class or within the "Parent" Page Class?
问题
以下是您要翻译的内容:
我在学习Selenium的过程中,采用了页面对象模型作为我的设计方式。 我的练习站点是https://www.beeradvocate.com(我喜欢啤酒,它提供了一些我正在寻找的测试挑战)。
其中一个实例是页面覆盖或模态窗口。
我知道在POM中,每个页面都有自己的类,页面对象就位于其中,并且有相应的方法/操作需要执行在这些对象上。此外,如果我点击一个链接导航到另一个页面,函数中会返回一个新的页面对象,例如:
return new HomePage();
当点击登录链接时,会弹出一个覆盖的模态窗口。似乎框架并不像它们自己的页面类那样处理。需要使用switchToFrame()操作。对于这个覆盖窗口,是否也适用相同的方法呢?也许只需要使用getWindowHandles()操作来导航到它?
英文:
As I train myself on Selenium, I'm using Page Object Model as my design. My practice site is https://www.beeradvocate.com (I like beer and it's presenting some testing challenges I was looking for).
Once such instance is a page overlay or modal window.
I know in POM each page has it's own Class where the page objects are located and the corresponding methods/actions to be taken upon them. Furthermore, if I click a link that navigates to another page, that would return a new page object in the function such as:
return new HomePage();
When the Login link is clicked it generates an overlay modal window. It seems that Frames aren't treated as their own Page Class. It takes a switchToFrame() action. Would the same apply for this overlay? Perhaps just a getWindowHandles() action to navigate to it?
答案1
得分: 0
我也在做这个,主要问题是你需要找到登录网站的方式。如果你没有登录,你只能实际收到前25条评论。
英文:
I'm working on this too, and the main problem is that you need to find a way to login to the website. If you are not logged in, you can get only actually receive the first 25 reviews..
答案2
得分: 0
我建议创建一个单独的类来表示您的模态框,特别是如果它被其他页面共享或将来可能从该页面移出。
但是,如果模态框非常简单,只包含在一个页面上,并且与该页面真正相关,那么它可以由该页面内的一组函数表示。但是,您需要将这些方法识别为“区域”或子组,可以使用类似为方法添加命名空间或使用装饰器的方式,这在面向对象的术语中常常意味着需要分离出一个子对象!
在Java中,分割和组合的成本相当低,所以没有太多的开销。但是,如果页面对象很大,包含了大量的“子组件”,可能会变得混乱。这可能取决于站点本身的子结构如何,这将指导您的决策。例如,如果模态框的选择器相对干净,与主页面本身分离,它就不太“归属”于该页面。
这个类似的答案指出,“POM”更像是一个模块表示,而不是一个完整的“页面”(无论这在现在是什么意思!)。
https://stackoverflow.com/a/47141290/209288
这个答案也提出了同样的问题。
https://stackoverflow.com/a/49002231/209288
我寻找类似的答案,在阅读这些讨论时刚刚下定决心分解我的模态框。(所以我的答案是基于15分钟的思考,而不是经验!)
英文:
I would suggest creating a separate class to represent your modal, especially if it's shared by other pages or may be moved out of that page one day.
But if the modal is super-simple and only included on one page and really specific to that page, then it could be represented by a group of functions within that POM. However you'd need to recognise those methods as a "region" or a sub-group in some way, like namespacing the methods, or using decorators, which I always think in OO terms smells like there's a sub-object here which needs dividing out!
Dividing and composing is pretty cheap in Java so there's not much penalty. But having a big page object with tons of "sub components" can get messy. It probably depends on how well sub-structured the site itself is which will guide your decision. Like if the selector for the modal is relatively clean and separate from the host page itself, it's less "owned" by the page.
This similar answer points out that a "POM" is more of a module reprentation than an entire "page" (whatever that means these days!).
https://stackoverflow.com/a/47141290/209288
This answer also asks the same question.
https://stackoverflow.com/a/49002231/209288
I came looking for a similar answer, and have just made my mind up to decompose my modals, while reading these discussions. (So my answer is based on 15 minutes of thought, not experience!)
专注分享java语言的经验与见解,让所有开发者获益!
评论