NSelene
NSelene copied to clipboard
Add extra helpers for Widgets/ElementObject creation
The original idea was to add ability to create custom elements that behave like SElement and can be produced by SCollection
So, e.g.
You could write
public class Task : SElement
{
public void Delete()
{
this.Hover().S(".destroy").Click();
}
//...
}
and then
Task secondTask = new Task().By("#task-list li:nth-of-type(2)");
secondTask.Should(Have.Text("do something");
secondTask.Delete();
or
SCollection<Task> tasks = new SCollection<Task>("#task-list li:nth-of-type(2)");
tasks.Should(Have.Size(2));
tasks[1].Should(Have.Text("do something");
tasks[1].Delete();
The problem with such requirements are that in order to satisfy them, we should provide an overcomplicated implementation (in order to be robust), full of "magic" and "tricky parts", hard to support, improve and scale. The usage will be also less simple, and the "learning path" would be harder.
Actually, the same behaviour described above can be achieved via simple composition/aggregation/decoration with no any additional features:
public class Task
{
public SElement Element { get; private set; };
public Task(SElement element)
{
this.Element = element
}
public void Delete()
{
this.Element.Hover().S(".destroy").Click();
}
//...
}
so
Task secondTask = new Task(S("#task-list li:nth-of-type(2)"));
secondTask.Element.Should(Have.Text("do something");
secondTask.Delete();
or
SCollection tasks = SS("#task-list li:nth-of-type(2)");
tasks.Should(Have.Size(2));
tasks[1].Should(Have.Text("do something");
new Task(tasks[1]).Delete();
As you can see, the usage is just a bit less laconic, but is much more straightforward, and teaches object-oriented over magic-oriented programming...
More over, actually, here exists even simpler "modular" solution to achieve the same:
public static class Task
{
public static void Delete(SElement task)
{
task.Hover().S(".destroy").Click();
}
//...
}
so
SElement secondTask = S("#task-list li:nth-of-type(2)");
secondTask.Should(Have.Text("do something");
Task.Delete(secondTask);
or
SCollection tasks = SS("#task-list li:nth-of-type(2)");
tasks.Should(Have.Size(2));
tasks[1].Should(Have.Text("do something");
Task.Delete(tasks[1]);
So, remember about KISS, relax and be happy ;)
Nevertheless, one day we can add some additional "magic" support but it will be implemented in the form of "additional helpers" not influencing the core of NSelene. Most probably helpers will be implemented via reflection, maybe in a bit similar way to PageFactory from raw selenium.