I'm developing .NET core app that using selenium, so I've designed the logic using fluent interface that make the code more readable and maintained.
I have a problem which is how to make a conditional logic in pipeline I followed this link of conditional builder.
the error here
here the source code
BasePage.cs
public class BasePage
{
public IWebDriver WebDriver { get; set; }
public WebDriverWait DefaultWait { get; }
public BasePage(IWebDriver webDriver)
{
WebDriver = webDriver;
DefaultWait = new WebDriverWait(WebDriver, TimeSpan.FromSeconds(1));
}
}
HomePage.cs
public class HomePage: BasePage
{
private Select2 Driver => new Select2(WebDriver, WebDriver.FindElementIfExists(By.XPath("xpath")));
private TextBox FirstName => new TextBox(WebDriver, WebDriver.FindElementIfExists(By.XPath("xpath")));
private TextBox LastName => new TextBox(WebDriver, WebDriver.FindElementIfExists(By.XPath("xpath")));
public HomePage(IWebDriver webDriver) : base(webDriver)
{
}
public HomePage FillPostingInformationForm(Company company)
{
FirstName.SetText(company.ContactPerson.FirstName);
LastName.SetText(company.ContactPerson.LastName);
return new HomePage(WebDriver)
}
public HomePage IsDriverFound(Company company)
{
Driver.IsItemSelected(company.Drivers.First().FirstName + " " + company.Drivers.First().LastName);
return new HomePage(WebDriver)
}
}
Select2.cs
public class BaseElement
{
public IWebDriver WebDriver { get; set; }
public BaseElement(IWebDriver webDriver)
{
WebDriver = webDriver;
}
}
public class Select2 : BaseElement
{
public IWebElement _element;
public Select2(IWebDriver webDriver, IWebElement element) : base(webDriver)
{
_element = element;
}
public bool IsItemSelected(string keyWord)
{
try
{
_element.Click();
_element.SendKeys(keyWord);
var option = WebDriver.FindElement(By.XPath(string.Format("//*[@{0} = '{1}']",
"role", "option")));
option.Click();
_element.BodyClick();
return true;
}
catch (NoSuchElementException ex)
{
Console.WriteLine(ex.Message);
return false;
}
}
}
BuilderExtensions.cs
public static class BuilderExtensions
{
public static T If<T>(this T t,bool cond, Func<T, T> builder)
where T : HomePage
{
if (cond)
return builder(t);
return t;
}
}
and the call as following
public void Build()
{
HomePage HomePage => new HomePage(InitializeBrowser());
var x = HomePage
.If(IsDriverFound(company), b => b.FillPostingInformationForm(company))
.If(!IsDriverFound(company), b => b.GoToDriversPage());
}
IsDriverFound(company) shown error, so what I did wrong here? and how to call this method inside if extension in the pipeline

HomePageinherits fromHomePage. Please make sure that you give us full instructions on how to run this code ourselves. We need a minimal reproducible example.return thisis a bad sign in a fluent interface. It should be something likereturn new HomePage(/* this plus the stuff passed to the call*/);.companyinBuild, there is no such parameter in the method and I don't see a property/field with this name.