我应该在Selenium Page Object Model模式中的何处定义模式特定代码

编程入门 行业动态 更新时间:2024-10-27 22:29:23
本文介绍了我应该在Selenium Page Object Model模式中的何处定义模式特定代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在Selenium页面对象模型模式的网页中,Web页面被表示为类,页面上的各种元素被定义为该类中的变量,并且用户交互被实现为该类中的方法.

In Selenium Page Object model pattern web pages are represented as classes, various elements on the page are defined as variables in the class, and user interactions are implemented as methods in the class.

即为每个页面创建一个单独的类.

That is for each page separate class is created.

有一个带有页面的电子商务应用程序-登录,主页,搜索,产品,购物车,结帐和订单确认.

There's an ecommerce application with pages- login, home, search, product, cart, checkout, and order confirmation.

也有多种模式,例如购物车预览,添加客户等. 有些模式会在多页上可见,而某些模式只会在特定页面上可见.

There are variuos modals also, like cart preview, add customer, etc. Some modals will be visible on multiple pages and some modals will be visible on particular page only.

例如购物车预览模式将显示购物车中的当前产品,数量,价格,总计等信息,可以从首页,搜索,产品和购物车页面进行访问.

E.g. Cart preview modal will show information like current products in cart, quantity, price, total, etc and it can be accessed from home, search, product, and cart pages.

添加客户"模式将具有用于添加新客户的字段-名称,联系信息,地址等,并且该模式仅在结帐页面上可见.

Whereas add customer modal will have fields to add new customer- Name, Conact information, Address, etc. and this modal will be visible only on checkout page.

如果我使用页面对象模型模式,我应该在哪里定义这些模式,我应该为模式创建一个单独的类,还是应该在相应的封闭页面中定义它们?

If I am using page object model pattern, where should I define these modals I mean shall I create a separate class for modals or shall I define them in the respective enclosing page?

我应该为在多个页面上可见的模式创建一个单独的类,并在相应的封闭类中定义页面特定模式吗?

Shall I create a separate class for modal that is visible on multiple pages and define the page specific modal in the respective enclosing class?

推荐答案

根据 页面对象设计模式 :

  • 页面对象是一个面向对象的类,用作与待测应用程序的页面的接口.每当您的@Tests需要与该页面的 User Interface 进行交互时,便使用此 Page Object 类的方法.这样做的好处是,如果页面的UI更改了,则您无需更改@Tests本身.仅需要更改页面对象中的代码.

  • A Page Object is an object-oriented class that serves as an interface to a page of the Application Under Test. Your @Tests uses the methods of this Page Object class whenever they need to interact with the User Interface of that page. The benefit is that if the UI changes for the page your @Tests themselves don’t needs to be changed. Only the code within the Page Object needs to be changed.

优势:

  • 清除测试代码与页面特定代码(例如定位符,方法和布局)之间的分隔.
  • 该页面提供的操作的单个存储库,而不是将这些服务分散在整个测试中.

基于这些功能和优点, 模式框 是 Bootstrap Modal插件 ,并且基本上是同一页面的 HTML DOM 的一部分.因此,还应分别为每个 Page Object 定义这些 Locators 和关联的 Methods ,以便与 WebElement 相关联这些 模式框 也会在页面对象已初始化.

Based on these features and the advantages the Modal Box which you are observing in your UAT are a result of Bootstrap Modal Plugin and essentially part of the HTML DOM of the same page. So these Locators and the associated Methods should also be defined for each Page Object individually so that the WebElement associated with these Modal Box also gets initialized when the Page Object is initialized.

更多推荐

我应该在Selenium Page Object Model模式中的何处定义模式特定代码

本文发布于:2023-10-27 18:23:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1534168.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模式   定义   代码   Page   Selenium

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!