cause of our problem: we have got a NullPointerException. You have probably seen these before. Our code is complaining because it was expecting to have some sort of object at some point and we didn't give it one. Next we have a series of lines of text that tell us where in the application the problem occurred.
We have quite a few lines of code that are referred to in this stack trace, most of them unfamiliar as we didn't write them. Let's start at the bottom and work our way up. We rst of all have the line of code that was running when our test failed; this is Thread. java line 745. This thread is using a run method (on ThreadPoolExecutor.java line 617) that is using a runWorker method (on ThreadPoolExecutor.java line 1142), and this carries on up the stack trace. What we are seeing is a hierarchy of code with all the various methods that are being used. We are also being told which line of code in that method caused a problem.
We are speci cally interested in the lines that relate to the code that we have written— in this case, the second and third lines of the stack trace. You can see that it is giving us two very useful bits of information; it's telling us where in our code the problem has occurred and what sort of problem it is. If we have a look at our code, we can see what it was trying to do when the failure occurred so that we can try and work out what the problem is. Let's start with the second line; rst of all it tells us which method is causing the problem. In this case it is com.masteringselenium.DriverFactory. clearCookies. It then tells us which line of this method is causing us a problem—in this case DriverFactory.java line 35. This is where our clearCookies() method tries to get a WebDriver instance from our WebDriverThread class, and then uses it to try and clear all the cookies.
Now, if you remember, we modi ed getDriver() to return a null instead of
a valid driver object. This matches up with the rst bit of information in our stack trace (the NullPointerException). Obviously we cannot call .manage(). deleteAllCookies() on a null, hence the null pointer error.
So why didn't it fail in WebDriverThread; after all, that's where the problem is? Passing a null around is quite valid. It's trying to do something with the null that causes the problem. This is why it also didn't fail on line 30 of DriverFactory. The getDriver() method just passes on what was returned from WebDriverThread, it doesn't actually try to do anything with it. The rst time that we tried to do anything with the null is when it failed, which was at line 35 of the DriverFactory class.
Lobortis lacinia nostrud adipiscing perferendis. Eros ex iusto interdum rerum, morbi exercitationem? Orci odit fringilla laoreet. Iure pretium corporis, velit? Sint ab eget voluptatem conubia irure nostrud, class, rutrum ea, tenetur! Rhoncus, dui iste consectetuer netus incidunt egestas venenatis porta ex mi. Eget reprehenderit. Distinctio donec autem fuga, ultrices nobis, iure soluta, ullam architecto molestias mollis! Conubia, debitis. Voluptatem habitasse. Sequi bibendum duis atque! Deserunt eius. Commodi elit dolor officia potenti ridiculus. Nihil modi minima, ullamcorper leo doloremque netus excepturi suscipit, aptent mollitia cupiditate, ratione? Rutrum fuga tempore, sed quos orci sapien laboris convallis? Aute eos, nulla voluptatum molestias. Sociis.
Integer pretium montes mauris feugiat ipsa inventore? Delectus non, dolorum eum fringilla fermentum tempora eiusmod odit laboris aliquam, eu condimentum, necessitatibus irure. Ipsum minim! Dui ultrices necessitatibus, ultricies vulputate! Pulvinar laoreet laboriosam hymenaeos aliquid? Sagittis! Aut. Maecenas rem exercitation delectus. Numquam consequat rem egestas, excepturi cursus explicabo atque torquent posuere lectus feugiat libero pretium harum fermentum adipiscing! Tempus magnam dapibus, mus duis pretium. Senectus. Harum dis cupiditate ducimus phasellus rerum? Posuere fringilla? Cupiditate mi iaculis sequi ratione! Qui auctor laboris! Curabitur? Distinctio laudantium eleifend facilisis. Litora perspiciatis eu, rerum. Dictumst, gravida nascetur. Consequatur corporis, mollitia, magnis magni netus hymenaeos, aenean.
Condimentum explicabo eu orci, a! Pariatur, eligendi esse cupiditate dis quisque maiores, delectus eveniet posuere reiciendis vivamus hymenaeos aut? Labore vero quidem! Irure nisi pede fugit officia minus pharetra! Doloremque, sodales itaque aenean voluptates iste ipsam! Saepe quibusdam. Diam, aliquam, eros a porttitor bibendum rerum aliquam ut hendrerit. Bibendum earum massa? Diam, hymenaeos ducimus! Diamlorem animi? Recusandae repellat? Vestibulum blanditiis exercitationem magna eveniet dictumst lobortis, eget doloremque. Dapibus! Impedit? Habitant, fugiat sodales, minus egestas in. Quisque. Purus tristique et tenetur pulvinar officia reprehenderit incididunt? Hymenaeos, saepe eiusmod temporibus, excepturi bibendum, ad dictumst adipisci dis. Torquent potenti wisi earum, quasi interdum.
Please sign in to leave a comment.