如何解决如果通过Bitbucket管道运行,则无法通过Selenium定位元素
我目前正在Selenium中进行集成测试。我有一些测试集,用于测试网络元素的存在及其行为。如果我在本地计算机上运行这些测试,则一切运行正常。作为WebDriver,我使用ChromeDriver。
但是,如果我在bitbucket的管道中运行它们,则其中一些测试将失败。它之所以失败是因为它无法定位元素,最糟糕的是,在管道中,它的行为有点不确定性-有时它定位该元素,有时却不定位(在找到该元素和在哪个元素之间运行时,没有代码更改)元素未找到,两次运行之间测试的网站均未更改。)
预期条件失败:正在等待...定位元素(以500毫秒的间隔尝试了300秒)
在不是非常快的本地计算机上,30秒的超时时间对我来说已经足够了。而且测试始终会在我的本地计算机上通过。是bitbucket上的管道运行非常缓慢还是我错过了什么?
ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="MoveThumb.xaml"/>
<ResourceDictionary Source="ResizeDecorator.xaml"/>
<ResourceDictionary Source="RotateDecorator.xaml"/>
</ResourceDictionary.MergedDictionaries>
<!-- ContentControl style to move,resize and rotate items -->
<Style x:Key="DesignerItemStyle" TargetType="ContentControl">
<Setter Property="MinHeight" Value="50"/>
<Setter Property="MinWidth" Value="50"/>
<Setter Property="RenderTransformOrigin" Value="0.5,0.5"/>
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ContentControl">
<Grid DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}">
<Control Name="RotateDecorator"
Template="{StaticResource RotateDecoratorTemplate}"
Visibility="Collapsed"/>
<s:MoveThumb Template="{StaticResource MoveThumbTemplate}"
Cursor="SizeAll"/>
<Control x:Name="ResizeDecorator"
Template="{StaticResource ResizeDecoratorTemplate}"
Visibility="Collapsed"/>
<ContentPresenter Content="{TemplateBinding ContentControl.Content}"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="Selector.IsSelected" Value="True">
<Setter TargetName="ResizeDecorator" Property="Visibility" Value="Visible"/>
<Setter TargetName="RotateDecorator" Property="Visibility" Value="Visible"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我在所有测试中都使用这种模式。
解决方法
尝试这样做:
webDriver.get(getTerminalUrl());
WebDriverWait wait = new WebDriverWait(webDriver,60);
boolean elementPresent = driver.findElements(By.xpath("//*[text()='Sign In']")).size() > 0;
if(elementPresent){
Thread.sleep(3000);
WebElement login = webDriver.findElement(By.xpath("//*[text()='Sign In']"));
Thread.sleep(3000);
login.click();
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。