是否可以要求结构具有特定字段作为特征的一部分?我正在使用 Rust 中的 Thirdfour_sync 箱进行一些网络自动化。我想为将实现它们的页面对象编写一些具有默认实现的特征。基本上,我知道每个要实现此特征的结构都会有一个名为“driver”的字段,该字段保存对 WebDriver 结构的引用。我想在该特征的默认实现中使用此驱动程序字段。
error[E0609]: no field `driver` on type `&Self`
--> src\base_order_details.rs:13:30
|
10 | / pub trait BaseOrderDetails {
11 | |
12 | | fn oid(&self) -> WebDriverResult<String> {
13 | | let oid_title = self.driver.find_element(By::XPath("//*[text()=\"Order ID:\"]"))?;
| | ^^^^^^
... |
Run Code Online (Sandbox Code Playgroud)
有没有办法让编译器知道任何实现此特征的东西都将具有 &WebDriver 类型的字段驱动程序?
我很难习惯WebDriver PageObject模式.请分享您使用PageObjects模式和loadableComponents的经验和方法.
由于PageObject通常代表一个组件或一部分功能,我起初想到我应该使用它来实际执行load()中的一些事情,看看它是否在isLoaded()中做了它应该做的事情.
然后我意识到它应该仅用于"加载"对象(可能是初始化),就像在网站中移动一样,每个对象都有自己的URL.并使用isLoaded()来测试对象是否为READY进行测试.
但是如果你有一个复杂的JavaScript命令提交者进行测试,那就是JS文件上传器的复合,JS表单基于2个独立的部分而且有三种Orders,你不会移动到任何地方(关于URL),只是元素状态正在发生变化.
考虑get()方法.您将使用交互式表单进入该页面.当表单存在于页面上时加载它.然后你有form1和form2对象......他们的load()和isLoaded()方法应该是什么样的,他们可以立即采取行动,因为他们不需要任何加载,只需测试他们的服务.
这是一个烂摊子,人们不知道isLoaded()方法是否用于检查是否加载了对象,或者是否加载了对象并且设置正确.但我想前一种方法是正确的,并且应该在测试中确保设置它的有效性.
场景:
Testing first part of html form - test that field client side validation works
Testing the second one that depends on the first one
Testing the following file uploader - upload, canceling, clearing, order, fileIDs
Testing the overall html form submission - ServerSide validation errors, results
Run Code Online (Sandbox Code Playgroud)
文件说:
公共方法表示页面提供的服务
验证,上传,上传多个,取消,清除
尽量不要暴露页面的内部
我唯一想到的就是将Driver实例隐藏到UnitTests并使用Only PageObjects来保存所有字段名,在PageObjects中的css类名+提供带有输入数据的PageObjects并断言服务/功能的布尔结果
方法返回其他PageObjects
这是最难以习惯的事情.对于一个交互式表单有4个页面对象有点不自然.他们推荐Form1,Form2(Form1),Upload(Form2),Submit(Upload),虽然我发现链接并将前一个对象的引用非常混乱.在测试方法中对所有这些调用get()似乎更好.但我想它背后的想法不是将驱动程序实例暴露给测试,而只使用内部使用驱动程序实例的PageObjects
对于同一个动作的不同结果被建模为不同的方法 我认为这意味着不应该在Page对象侧决定该动作的有效性,而是在Test侧
java design-patterns webdriver pageobjects selenium-webdriver
将PageObjects模式应用于页面组件时的标准方法是什么?
为了举例,我可以说我正在为亚马逊产品页面上的功能编写测试.
该页面包含大量单独的功能,产品信息,浏览此客户,其他客户建议等.
我在PageObjects中看到的当前示例实际上仅涵盖了如何处理功能有限的单个页面.我正在寻找的东西是一个PageObject,它代表Product页面,然后由代表每个组件的ComponentObject组成.
例如:
public class ProductPage
{
[FindsBy(How = How.Id, Using = "productInformation")]
public ProductInformationControl ProductionInformation{get;set}
[FindsBy(How = How.Id, Using = "customersViewed")]
public CustomersAlsoViewedControl CustomersAlsoViewed{get;set}
[FindsBy(How = How.Id, Using = "customersSuggested")]
public CustomersSuggestedControl CustomersSuggested{get;set}
}
public class ProductInformationControl
{
//Ideally the FindsBy here would find the element based on the Controls context
// So only resolving to an element that was within the context of this control.
[FindsBy(How = How.ClassName, Using = "title")]
private IWebElement _title;
public string …Run Code Online (Sandbox Code Playgroud) 想象一下,我有一个像这样的图像:
the_image = @browser.image(:id, 'image01')
Run Code Online (Sandbox Code Playgroud)
获得其类的价值的方法可以是:
image_status = the_image.attribute_value('class')
Run Code Online (Sandbox Code Playgroud)
好.我正在使用page_object gem并假设我将图像作为元素,如:
image(:the_image, :id => 'image01')
Run Code Online (Sandbox Code Playgroud)
要获取attribute_value,我可以使用:
image_status = the_image_element.attribute_value('class')
Run Code Online (Sandbox Code Playgroud)
......但是我得到了一份弃权警告:
*** DEPRECATION WARNING
*** You are calling a method named attribute_value at page.rb:68:in `get_status'.
*** This method does not exist in page-object so it is being passed to the driver.
*** This feature will be removed in the near future.
Run Code Online (Sandbox Code Playgroud)
如何class使用page_object元素获取值?当然答案很简单,但我没有找到它.你能告诉我路吗?
先感谢您!
我们目前正在努力在我们公司建立一个良好的测试框架。它适用于中型到大型网络应用程序,可能有几十个页面。我们目前主要编写基于 WebDriver Selenium UI 的测试。
我们正在尝试确定一些编码标准,我们正在讨论的一件事是是否使用始终返回PO(即使页面相同)的页面对象(PO),仅当您离开当前页面时才返回PO一件新的,甚至不退回 PO。我一直认为返回 PO 是 PO 设计模式的一个关键特性,但我对此可能是错误的。
基本上,我们尝试在以下模式之间做出决定:
class SomePage {
// constructor
public SomePage(Driver) { //... }
// always return a page object
public SomePage fillInTextField(String val){
// details
return new SomePage(driver);
// only return a PO if it's a different page
public void fillInTextField(String val){
// details
return;
}
Run Code Online (Sandbox Code Playgroud)
其中一个比另一个更可取吗?
我正在尝试在Java中使用Page Object模式,并且@ FindBy / XPath遇到了一些麻烦。
之前,我在Groovy中使用了以下构造:
driver.findElement(By.xpath("//td[contains(text(),'$SystemName')]")).click()
Here, SystemName is a parameter that can be different.
Run Code Online (Sandbox Code Playgroud)
现在,我想做同样的事情,但是要遵循Java中的Page Object范式:
public class ManagedSystems {
private WebDriver driver;
@FindBy(id="menu_NewSystem")
private WebElement menuNewSystem;
@FindBy (xpath = "//td[contains(text(),'$SystemName')]") // ??? How to use SystemName from deleteSystem method (below)?
private WebElement plantSystemName;
....
public SystemHomePage deleteSystem (String systemName) {
plantSystemName.click();
}
}
Run Code Online (Sandbox Code Playgroud)
在测试中,我调用deleteSystem:
SystemHomePage.deleteSystem("Firestone");
Run Code Online (Sandbox Code Playgroud)
问题:如何为PlantSystemName和为deleteSystem指定的SystemName链接@FindBy表示法?
谢谢浣熊
我的问题是:使用findby属性修饰的webelements是否在每次引用时调用findelement函数?如果不是,何时?
List <webelement>的程序是什么?当您引用列表时,或引用该列表中的元素时,它会触发吗?
我问,因为我有一些情况,我得到陈旧的元素异常,我想知道如何处理它们.
作为一个与开发人员几乎没有互动的e2e测试人员,我如何找出导致angularJS网站挂起的原因?如何调试网站并为他们提供有问题的解决方案?Chrome开发人员是否提供了这方面的答案?
我目前的解决方案是使用下面两个代码片段中的任何一个,但从我读过的内容来看,这并不理想.
browser.sleep();
browser.ignoreSynchronization = true;
Run Code Online (Sandbox Code Playgroud)
我在下面遇到类似的问题:
是的,最常见的原因是当应用程序连续轮询$ timeout或$ http时,Protractor将无限期地等待并超时.但这也可能发生在App占用时间超过11秒的情况下
您可能有更多运气暂时关闭同步:
有没有办法使用 PageFactory 注释等待 Selenium 中不存在的元素?
使用时:
@FindBy(css= '#loading-content')
WebElement pleaseWait;
Run Code Online (Sandbox Code Playgroud)
定位元素,然后:
wait.until(ExpectedConditions.invisibilityOfElementLocated(pleaseWait));
Run Code Online (Sandbox Code Playgroud)
我会得到:
org.opeqa.selenium.WebElement cannot be converted to org.openqa.selenium.By
Run Code Online (Sandbox Code Playgroud)
我可以使用以下方法完成我需要的操作:
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector('loading-content')));
Run Code Online (Sandbox Code Playgroud)
但是,我希望能够使用 PageFactory 注释以保持框架一致。有没有办法做到这一点?
我正在尝试为我的第一次登录测试实现 PageObject 模式。在运行它时,我收到以下错误:
>> py.test -v test_login.py
============================= test session starts ==============================
platform linux2 -- Python 2.7.3 -- pytest-2.3.4
plugins: xdist
collected 0 items / 1 errors
==================================== ERRORS ====================================
____________________ ERROR collecting test_login_logout.py _____________________
test_login_logout.py:10: in <module>
> from ui.pages import LoginPage
../pages/__init__.py:1: in <module>
> from loginPage import LoginPage
../pages/loginPage.py:3: in <module>
> from base import BasePage
E ImportError: No module named base
Run Code Online (Sandbox Code Playgroud)
这是python路径:
Python路径:PYTHONPATH="${PYTHONPATH}:/usr/lib/python2.7/"
导出 PythonPATH
就我的第一次测试而言,很多代码都是复制粘贴的,也许它有问题,但我无法理解。对这方面的任何建议都会非常满意。
下面是我所谓的 PageObject 实现的结构和内容:
pageobjects ×10
java ×4
selenium ×4
webdriver ×3
angularjs ×1
asynchronous ×1
c# ×1
cucumber ×1
javascript ×1
page-factory ×1
protractor ×1
pytest ×1
python ×1
python-2.7 ×1
ruby ×1
rust ×1
struct ×1
traits ×1
xpath ×1