我有一个测试用例,用于检查用户单击按钮的时间,标题应向上滚动到页面顶部。但是默认情况下有一个标头。因此标题应该低于该名称。我们如何检查。请帮助
答案 0 :(得分:1)
以下是非常“长手”的方法,但过去对我来说非常成功。
您可以通过Selenium命令提取两个对象的位置和大小。然后,您可以计算标题所在的屏幕区域,并将其与标题出现的屏幕区域进行比较。
如果这些区域重叠,则可以说标题被标题隐藏了。
以下是作为RSpec匹配器的示例;
RSpec::Matchers.define :be_within do |reference_object|
@reference_object_location = reference_object.location
@reference_object_size = reference_object.size
match do |relative_object|
@relative_object_location = relative_object.location
@relative_object_size = relative_object.size
relative_x_max = @relative_object_location.x + @relative_object_size.width
relative_x_min = @relative_object_location.x
relative_y_max = @relative_object_location.y + @relative_object_size.height
relative_y_min = @relative_object_location.y
reference_x_max = @reference_object_location.x + @reference_object_size.width
reference_x_min = @reference_object_location.x
reference_y_max = @reference_object_location.y + @reference_object_size.height
reference_y_min = @reference_object_location.y
relative_x_max <= reference_x_max && relative_y_max <= reference_y_max &&
relative_x_min >= reference_x_min && relative_y_min >= reference_y_min
end
就像我说的那样,不漂亮!