Expermient

TL DR[expand = „Click here to see short summary”]

Experiment! It is good for you.

[/expand]

Why Experiment Matter

My father like to ask this question:
„Do you know the difference between Technician and Engineer?”
The technician knows how to use it and how to troubleshoot it, but when his book on known issues ends his useless.
The Engineer understand principals how technology work, he may not know how to resolve common problems fast but will be able to understand more complex problems.

And my experience with other Testers is that too many of us are either Technician, not Engineers. They use tools for automation, but we don’t understand them and their limitations.

There are many ways to amend it, and I think one of the fastest is experimenting. You can learn new things about your tools (And its limitation).

Ok, how to do it?

Selenium I web element has two properties Text and Displayed. Understanding them is vital for flower 3 (coming soon)
So let’s check it
of course, there is documentation for both functions and its interaction:  Text, Visible Text, Displayed
But let’s assume you don’t have access to it:

I like to do experiments base on simplified scientific method:
1.Make Theory.
2. Make Experiment
If failure: Revise assumption.
If success: Check if the result is repeatable.

Make experiment has to contain not only attempts to confirm but also to prove theory false.

My theory is: You can get the text of any element – if that element has children it will also contain a text of that child. The display doesn’t affect it. (Again this is our theory at this point of time it doesn’t mean that it is true). And if there is no text it return string empty

For preparation, we need to start page
I am going to use book page at kobo.com ebook store – cause I am employed there, and it is my home turf.

So we have to do few test to check it:
– check not displayed element with text
– check element without text
– check element with children that have the text:

test code bellow

[csharp]
[TestMethod]
public void element_not_displayed_with_text()
{
var driver = new ChromeDriver();

driver.Navigate().GoToUrl("https://www.kobo.com/ie/en/ebook/into-the-water-3");
var cssSelector = By.Id("write-form-title");
var findElement = driver.FindElement(cssSelector);
PrintValue(findElement);
driver.Quit();
}

[TestMethod]
public void element_has_childern_with_text()
{
var driver = new ChromeDriver();

driver.Navigate().GoToUrl("https://www.kobo.com/ie/en/ebook/into-the-water-3");
var cssSelector = By.ClassName("synopsis-description");
var findElement = driver.FindElement(cssSelector);
PrintValue(findElement);
driver.Quit();
}

[TestMethod]
public void element_has_no_text()
{
var driver = new ChromeDriver();

driver.Navigate().GoToUrl("https://www.kobo.com/ie/en/ebook/into-the-water-3");
var cssSelector = By.CssSelector("body");
var findElement = driver.FindElement(cssSelector);
PrintValue(findElement);
driver.Quit();
}

private static void PrintValue(IWebElement findElement)
{
if (findElement.Text == null)
Console.WriteLine("Text is null");
else if(string.Empty == findElement.Text)
Console.WriteLine("Text is empty");
Console.WriteLine(
$" \n element text {findElement.Text[0]} \n is displayed {findElement.Displayed} is enebled {findElement.Enabled}");
}
[/csharp]

test result:

element_not_displayed_with_text:
Text is empty
Element text;
Is displayed False
-------- 

element_has_no_text

Text is empty
element text 
is displayed True
--------

element_has_childern_with_text

element text 'Wondering if Into the Water could be as good as The (....)'
is displayed True 
is enabled True

So writing a simple block of code we have the better understanding of how Display property works. Note this is a throwaway code it doesn’t have to be pretty you run it one twice and that all

Our theory was that we could get a text of not displayed element – which was wrong.

Warning!

Some Theories aren’t so easy to verify.

So what with an element that is not displayed but has displayed children?
Well, my theory is that you can’t have the situation like that. Cause if an element is visible it means it whole tree has to be visible.

I tried to check that, but I haven’t managed to find the situation like that. S does it mean I am right? I would be careful with when you test something you do positive and negative testing. – If a negative test doesn’t find anything, you are not saying that software is bug-free. Only that you didn;t found anything. Similarly is with this theory – so if you want.

To sum it up.

Sometimes to better understanding something, learn the new tool is useful to experiment.
Create theory.
Do experiment. Don’t forget not only options where it should work but also when it shouldn’t

 

If you want to read more test inspirations check here.

Or here for more articles about science here.

Dodaj komentarz