Я не вижу никакой проблемы как таковой в ваших испытаниях кода.
AjaxElementLocatorFactory
- это концепция отложенной загрузки в шаблоне Page Factory для идентификации WebElements только тогда, когда они используются в какой-либо операции то есть timeOut для WebElement может быть назначен классу страницы Object с помощью AjaxElementLocatorFactory
.
Синтаксис:
PageFactory.initElements(new AjaxElementLocatorFactory(driver, TimeoutValue), this);
Пример:
PageFactory.initElements(new AjaxElementLocatorFactory(driver,5), this);
Приведенный выше код будет ожидать максимум 5 секунд, пока не будут загружены элементы, указанные в аннотациях. Если элемент не найден в заданный промежуток времени, он выбросит NoSuchElementException
.
Как и в вашем кодовом блоке, если элемент не найден после 5 seconds
, должно быть выброшено NoSuchElementException .
AjaxElementLocatorFactory создает AjaxElementLocator , используя SlowLoadableComponent , который может не закончить загрузку, когда [116 ] возвращается. После вызова load()
метод isLoaded()
должен продолжать отказывать, пока компонент полностью не загрузится.
I just figured this out so allow me to answer my own question.
I read Laurent's Bugnion enlighting article on this and it turns out I just had to tweak the above code so that I could see the Data from my ViewModel displayed in the Expression Blend GUI and was able to edit the DataTemplate in Blend, save it, and then continued editing in Visual Studio.
Basically the changes are: (1) take out the DataContext statement from code behind, (2) add the "local" namespace in XAML, (3) define a local data provider in XAML ("TheDataProvider"), (4) bind to it directly from the ListBox.
Here is the code that works in Expression Blend and Visual Studio in full:
XAML:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:TestStringFormat234"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" x:Name="window" x:Class="TestStringFormat234.Window1"
Title="Window1" Height="300" Width="300" mc:Ignorable="d">
<Window.Resources>
<local:CustomerViewModel x:Key="TheDataProvider"/>
<DataTemplate x:Key="DataTemplateCustomers">
<Border CornerRadius="5" Padding="5" Margin="3">
<Border.Background>
<LinearGradientBrush EndPoint="1.007,0.463" StartPoint="-0.011,0.519">
<GradientStop Color="#FFF4EEEE" Offset="0"/>
<GradientStop Color="#FFA1B0E2" Offset="1"/>
</LinearGradientBrush>
</Border.Background>
<StackPanel Orientation="Horizontal">
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} {1} (hired on {2:MMM dd, yyyy})">
<Binding Path="FirstName"/>
<Binding Path="LastName"/>
<Binding Path="HireDate"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</StackPanel>
</Border>
</DataTemplate>
</Window.Resources>
<Grid >
<ListBox
ItemsSource="{Binding Path=GetAllCustomers, Source={StaticResource TheDataProvider}}"
ItemTemplate="{StaticResource DataTemplateCustomers}" />
</Grid>
</Window>
Code Behind:
using System.Windows;
using System.Collections.ObjectModel;
using System;
namespace TestStringFormat234
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
}
//view model
public class CustomerViewModel
{
public ObservableCollection<Customer> GetAllCustomers {
get {
ObservableCollection<Customer> customers = new ObservableCollection<Customer>();
customers.Add(new Customer { FirstName = "Jim", LastName = "Smith", HireDate = DateTime.Parse("2007-12-31") });
customers.Add(new Customer { FirstName = "Jack", LastName = "Jones", HireDate = DateTime.Parse("2005-12-31") });
return customers;
}
}
}
//model
public class Customer
{
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime HireDate { get; set; }
}
}
У меня есть сообщение в блоге по этой проблеме: http://www.robfe.com/2009/08/design-time-data-in-expression-blend- 3 /
Мой пост посвящен отображению данных в смеси без необходимости отображать эти данные или даже создавать их во время выполнения.