简体   繁体   English

在页面对象模型框架中存储数据的最佳方法是什么

[英]What is the best way to store data in a Page Object Model Framework

Im building an automation framework in selenium using the Page Object Design Pattern. 我使用页面对象设计模式在硒中构建了一个自动化框架。 Following are some of the data that Im using and where i have stored them 以下是我使用的一些数据以及我将其存储在何处

  1. PageObjects (xpath, id etc) - In the Page Classes itself PageObjects(xpath,id等)-在页面类本身中 在此处输入图片说明
  2. Configuration Data (wait-times, browser type , the URL etc) - In a properties file. 配置数据(等待时间,浏览器类型,URL等)-在属性文件中。 在此处输入图片说明
  3. Other data - In a class as static variables. 其他数据-在类中为静态变量。
    在此处输入图片说明

Once the framework starts growing it would be hard to store all the data it would be hard to organize the data. 一旦框架开始增长,将很难存储所有数据,也将很难组织数据。 I did a some research on how others have implemented the way they store data in their framework. 我对其他人如何实现他们在框架中存储数据的方式进行了一些研究。 Here is what I found out, 这是我发现的,

  1. Storing data (mostly page objects) in classes itself 在类本身中存储数据(主要是页面对象)
  2. Storing data in JSON 用JSON存储数据 在此处输入图片说明
  3. And some even suggested storing data in a database so that it would reduce reading times 甚至有人建议将数据存储在数据库中,这样可以减少读取时间

Since there are lot of options out there, I thought of getting some feedback on what is the best way to store data and how everyone else has stored there data. 由于那里有很多选择,我想就什么是最好的数据存储方式以及其他人如何存储数据的方式获得一些反馈。

JSON或任何临时数据存储是最佳选择,因为它是一个框架,其目的是为不同项目重用。

I advice using Interfaces for each device type to store multiple type selectors, example: 我建议对每种设备类型使用接口来存储多个类型选择器,例如:

import static org.openqa.selenium.By.cssSelector;
import static org.openqa.selenium.By.linkText;
import static org.openqa.selenium.By.xpath;

public interface DesktopMainPageSelector {
    By FIRST_ELEMENT = cssSelector("selector_here");
    By SECOND_ELEMENT = xpath("selector_here");
    By THIRD_ELEMENT = id("selector_here");
}

than, just implement these selectors from whatever you need them. 只需从您需要的任何地方实现这些选择器即可。

You can also use enums with for a more complex structure. 您还可以将枚举与更复杂的结构一起使用。

I found this as best solution, because its easy to manage large numbers of selectors 我发现这是最好的解决方案,因为它易于管理大量选择器

I don't see any problem with the way you have stored your data. 我认为您存储数据的方式没有任何问题。

  1. Locators (by POM definition) should be stored in the page objects themselves. 定位符(通过POM定义)应存储在页面对象本身中。
  2. Config data can be stored in some sort of config file... whatever you find convenient. 可以将配置数据存储在某种配置文件中……无论您发现什么方便。 You can use plain text, JSON, XML, etc. We use XML but that really comes down to personal preference. 您可以使用纯文本,JSON,XML等。我们使用XML,但这确实取决于个人喜好。
  3. I think this is fine also. 我认为这也很好。

The framework doesn't really grow, the automation suite does. 框架并没有真正增长,自动化套件却在增长。 As long as you keep the data stored in the 3 places above consistently, I think you should be fine. 只要您将数据存储在上面3个位置上,就可以了,我认为应该没问题。 The only issue I've run into with this approach is that sometimes certain pages have a LOT of functionality on them so the page objects grow quite large. 我使用这种方法遇到的唯一问题是,有时某些页面上具有很多功能,因此页面对象会变得很大。 In those cases, we found a way to divide the page into smaller chunks, eg one page had 22 tabs, each consisting of a different panel. 在那种情况下,我们找到了一种将页面分成较小的块的方法,例如,一个页面有22个选项卡,每个选项卡由一个不同的面板组成。 In that case, we broke the page object into 22 different class files to keep the size more manageable and then hooked them all back into the main page as properties, eg mainPage.Panel1.someMethodOnPanel1(); 在那种情况下,我们将页面对象分成22个不同的类文件,以使大小更易于管理,然后将它们作为属性重新挂回到主页面,例如mainPage.Panel1.someMethodOnPanel1();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将 Page Object Model 与 Page Fatcory 一起使用的最佳方法是什么 - What is the best way to use Page Object Model with Page Fatcory 使用页面对象模型(java)处理导航的最佳方法是什么 - What is the best way to handle navigation using page object model (java) 在android中存储JSON数据对象的最佳方法是什么? - What is the best way to store a JSON data object in android? 将操作存储为java中的数据的最佳方法是什么? - What is the best way to store actions as data in java? 从自动化框架的 Excel 表中存储数据的最佳方法 - Best way to store data from excel sheet for automation framework 使用struts框架创建等待页面的最佳方法是什么 - What's the best way to create a waiting page using the struts framework 在Java中支持嵌套对象模型的最佳方法是什么? - What is the best way to support nested object model in java? 什么是从数据库存储和检索数据的最佳方法 - What is the best way to store and retrieve data from database 只要Tomcat工作,什么是存储数据的最佳方法? - What is the best way to store Data as long as Tomcat works 从 Excel 读取数据后存储数据的最佳方式是什么? - What is the best way to store data after reading from Excel?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM