4. TASKS
Create test cases for all the links of the page
Find all stories for Trump
Copy all text for reviewing
Test all the links in header
29/05/2018 4
7. 29/05/2018 7
1) Inspect a page and see how it built. You might see that all the links are in anch
or tags (’a’)
2) Create a variable called images the represents all the links:
let anchors = $$(‘a’)
3) Write a For Loop to go through each anchor and use console.log to print the
‘href’ value for each anchor. Looks like this:
for (let i = 0;i<
anchors.length; i++){
console.log(anchors[i].href)
}
RESULT: All the Links of the page are displayed.
Find All Links on a Page
8. 29/05/2018 8
Find all Stories for Trump
Use Patterns or Regular Expressions to filter data on a page. Regular Expressions
(RegEx or sometimes called ‘the testers best friend’) are super useful for checking for
proper format or string pattern
$$('h2.story-heading').map(element => element.innerText).filter(text =>
text.indexOf('Trump') > -1).join('nn')
RESULT: All the text with word Trump are displayed
9. Find Text
29/05/2018 9
1) Inspect to learn a section of the web page. With the section
highlighted/inspected, change the Console section of the Developer Tools.
2) Type $0
3) Press Enter
4) An object that represented the selected section displays.
5) Type $0.innerText and press Enter.
RESULT: All the text in the selected sections displays is returned. You can
read or copy the text to do testing things
10. Test Links
29/05/2018 10
let anchors=$x("//header/nav/ul/li/a")
console.log("Links that will be tested: "+anchors.length)
for (let i = 0;i< anchors.length; i++)
{
console.log(anchors[i].href);
fetch(anchors[i].href)
.then(function(response) {
console.log(response.url);
console.log(response.status);
})
.catch(function (error) {
console.log('Request failed', error);
});
}
RESULT: HTTP requests returned status 200. This means that requests were
fulfilled. Links work properly
1) Inspect the header navigation bar
2) Collect all the corresponding Links
3) Make HTTP requests, extract values from the responses
11. Wrap up
Reflect on how you can use these techniques in your daily work and
how the techniques integrate with your idea of exploratory testing.
Simple approaches can be very useful and easy to add to your skill
collection.
A little JavaScript can go a long way and give you a lot of
productivity.
Useful Resources:
Twelve Fancy Chrome DevTools Tips by David Gilbertson :
http://bit.ly/fancychromedevtoolstips
Command Line API Reference by Andi Smith& Meggin Kearney :
http://bit.ly/commandlinereference
29/05/2018 11