Creating a WebDriver

Simon Stewart: Selenium is just a browser automation API.

It's not a batteries-included framework, so how do we get hold of the driver executable? We need we do that by making use of a third-party library. In this example, we're going to use WebDriver manager to help manage this complexity for us. But rest assured, there are similar tools available for every major programming language. As you can see, we have a very basic gradle project, there's not much that's interesting in here. It's a simple test file, it's kinda empty and the Selenium Tick checkmark, which we will use later.

We only have two inputs. The first is Selenium itself, and the second is this WebDriver manager, which we're gonna use, which you will notice that this is beta one of Selenium 4. We have finally got that. I'm very pleased to hear that. Now, why do I have WebDriver manager in here? It's a very good question. What we want to do is in our test. We want to demonstrate how to do things and the very first thing that we want to do is before all of our stuff. What we want to do is we want to create a new, we want to make sure that Chrome and stuff, the public static void prepareDriverManager.

Oh we're just going to use WebDriverManager to make sure that we have a version of the Chrome driver present on our system, and that should match the latest version of Chrome and our systems are kept up to date. So everything's good. And before each of our tests, we want to create a new WebDriver instance. And to organdy is we're going to make use of a new feature of Selenium 4 or a feature that was present in Selenium 3 but not widely used. And we've enhanced it significantly in Selenium four. So we're going to go to the remoteWebDriver going to go builder and we want one of Chrome.

Or we could have the Firefox option, Firefox options or EDGE or any supported browsers but we're just going to do this. And I'm going to build it and what we're going to do, we will assign that to a field that is driver, great. So this is a new way of getting hold of the Selenium instance. What we could have done if you were using the remote WebDriver, so you could have done, you know, HTTP://my-grid-here.com or whatever it is. Right.

 So you could and there are a lot of settings on here, and this is a nice way of creating a WebDriver instance. And the next thing we're going to do, we're going to create a wait type of WebDriver and WebDriver waits and it's going to take the driver and you will see that all of the signatures other than the ones that take direction have been deprecated.

So we'll have a duration of 10 seconds. What we'll do is we will now make that field lovely so now we go and then after each of our tests, quitDriver. Great, and we're ready now for our first test.

Comments are closed.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}