-1
My Test ProjectがBDDアプローチで構築されています。 私は静的変数を通じてメソッドを呼び出そうとしていました。しかし、私の行動には何かが間違っています。一般的なケースではタイプを変換可能にする必要があります
マイコード:
public class BasePage
{
public T As<T>() where T : BasePage
{
return (T)this;
}
}
public class PropertiesCollection
{
private static BasePage _currentPage;
public static BasePage currentPage
{
get { return _currentPage; }
set
{
ScenarioContext.Current["class"] = value;
_currentPage = ScenarioContext.Current.Get<BasePage>("class");
}
}
}
public sealed class LoginSteps
{
[Given(@"I have navigated to my app")]
public void GivenIHaveNavigatedToMyApp()
{ Browser.Current.Navigate().GoToUrl(ConfigurationManager.AppSettings["seleniumBaseUrl"]);
PropertiesCollection.currentPage = new LoginPage();
}
[Given(@"I typed the (.*) and (.*)")]
public void GivenITypedTheAnd(string username, string password)
{
var m = PropertiesCollection.currentPage.As<LoginPage>().Login(username, password);
}
だから、最後のコード行で、私は、このような一般的な方法では、パラメータとしてそれを使用するためには.Pages.BasePage」「タイプはに変換可能でなければならない」などのメッセージエラーがあります「.Pages.BasePage.As()」 は、私は修正のためにそれをどのように変更すべきか?
'LoginPage'の定義は何ですか? 'BasePage'を拡張していますか? – Lee
投稿のログインページもあります。なぜプライベート静的BasePage _currentPageが必要ですか? – unickq
'public Tのポイントは何ですか?()T:BasePage'?使用法は 'myBasePage.As ()'になりますが、 'myObject as DerivedPage'は既にC#で利用可能です。さらに、あなたのバージョンは例外をスローするハードキャストですが、既存の' as'実装は単純に戻りますヌル。 –
Flater