【发布时间】:2020-04-27 09:50:18
【问题描述】:
我有以下 HTML:
<a class="js-open-modal suspend" data-track-event="interacted_with_account_manage_settings_web"
data-track-properties="{"location":"clients","button_clicked":"Suspend"}" data-track="always"
href="/client_suspension/new?client_id=86">Suspend</a>
我已经用这两个定位器声明了元素(按钮):
link(:suspend_button, :class => ["js-open-modal", "suspend"])
link(:suspend_button, :visible_text => 'Suspend')
我已尝试“破坏”第一个定位器:link(:suspend_button, :class => ["blah-blah-blah-blah", "suspend"]),并尝试使用第二个定位器:link(:suspend_button, :visible_text => 'Suspend')。
这提供了弹性测试。
但如果我“破坏”了第二个定位器 link(:suspend_button, :visible_text => 'Ssssssuspend'),则测试不适用于第一个定位器:link(:suspend_button, :class => ["js-open-modal", "suspend"])。
页面是:
class MyClientsPage < Base
include PageObject
link(:suspend_button, :class => ["js-open-modal", "suspend"])
link(:suspend_button, :visible_text => 'Suspend')
end
测试是:
require 'spec_helper'
require "rspec/expectations"
describe 'Partner/client switch' do
it 'Client account is suspended' do
on(MyClientsPage).suspend_button
end
end
使用 Watir 组合多个定位器时,幕后有什么魔力? 您能否分享更多示例。 非常感谢!
【问题讨论】:
-
你在使用页面对象模型吗?
-
你是说你同时在同一个页面对象中包含了这两个
link声明? -
@JustinKo,是的,我留下了两个链接声明并运行了测试。我已经编辑了问题 -> 添加了示例代码。