Check-boxes and radio buttons

A free video tutorial from Dmitry Shyshkin
I'll teach you automate tests.
Rating: 4.6 out of 5Instructor rating
7 courses
40,903 students
Check-boxes and radio buttons

Learn more from the full course

Advanced Selenium WebDriver with Java and TestNG

Real-world example of Advanced Selenium WebDriver test automation framework with Java and TestNG | Selenium tutorial

04:49:00 of on-demand video • Updated June 2022

Develop Full-Stack Test Automation Framework from scratch
Implement Data Driven Test Framework
Use Page Object Model in Selenium
Automate almost any test case with Selenium
Use advanced Selenium WebDriver techniques (Taking screenshots, capturing JS console errors, etc)
English [Auto]
Hi, guys, today we are starting part four of our course in this part, we will learn different advance selenium interaction and in the first video, we will be checking, checkboxes and selecting a radio buttons. Let's take a look at our test case here on the welcome page. Let's click on Link Checkboxes. This opens new checkboxes page, so we will need to add new page object to our project. Now we need to make sure that we can select to check boxes at the same time. Here in the clips, I created new test glass check boxes, tests that extends tests, utilities. And for this class, I created a new package, check boxes, page tests. And as I said, the first part, this project at the end will look like real life project. So we are creating it like one with all the classes and packages also. I already started a new test selection to check boxes test and it starts with opening welcome page. When I develop new tests, I like to comment all steps of test case first, so we have a plan when I didn't court and this court is already has some comments. So next step is to click on checkboxes link. So let's add click checkboxes link method to welcome page object and create checkboxes page object. Here is the new checkboxes page object. So far it doesn't have any methods, just one checkbox locator. We have to check boxes on the page, but one locator will be enough for this test. Here in Welcome Page Object I have pneumatically click checkboxes link and you locate the checkboxes link locator. So basically click on checkboxes link locator will return you checkboxes page. And here in the test we have this new line of code. Click the link and open new page. Next step in our test is to select all checkboxes. So that's why inside of checkboxes page I added new select all checkboxes. So first step in this method is to get all check boxes using our check box locator, and that's why I created the find all method inside of speech object. So right after our Web, Bellemont find the method, we have this project, at least for Bellemont to find all. So basically our finite element will return. Only one element was given locator. And if there are more than one elements on the page was this locator, this method will return just first one and are find all method will return a list of Web elements using the same locator. So here in the check box boxes page object, we are getting a list of web elements with this locator. So our locator. Here is peut at type equals Checkbook's will return to Web elements to check boxes that we have on the page, and now we we're just going to iterate over all elements inside of this list. So for first check box in the check at list, if Checkbook's is not selected and we using this driver method which will return Boolean, true or false. So this method we can use on checkboxes and radio buttons. And this exclamation point here means not so we check in if Checkbook's selected and then not so if Checkbook's is not selected, then we using just simple click command on the checkbox to select it. And as you remember, we have a separate cleek method like this in our base page object. But this method uses by object as the locator and our check box is the web element. So on the web element we can click using this code so we don't need to use our click method from the basically object. We can just use click method from the Solanum. So if checkbox is not selected, click. If it's already selected then just skip and do nothing. So this method will select all checkbox. So first it will find all elements that are checkboxes and then for each element that is not checked, we will click on it to check that element. And then we are doing the verification that all check boxes are checked, and for that we have also a new method inside our checkboxes page. So, Sam, we get in least of all checkboxes and here we're also going to iterate through all Web elements inside of this list. And if it's if at least one is not selected, so we're using the same method is selected. So if it's not selected after we executed all this select all checkbox esmat of. This method will return false. So basically, since our methods are named, are all check boxes checked, if at least one is not checked, this method will return false and our verification will fail because we are trying to make sure that all check boxes are checked. So if not, our test will print. Not all check boxes are checked message. So now let's create this suite and run this test. So here is the new test suite to run this test. I also created a new folder, separate test suites. And in this folder we will keep all separate test suite. And separately, I created a full UI, this suite and smog tests with snow in the smog test suite, we will have only the most important test. So I put just positive log-in test here in the smog test suite. In the full UI test suite. We will have all the tests that we have. So so far we have positive log-in test to negative test and one checkboxes test. So let's run checkboxes test suite. Right click run this test and let's expand console. And let's bring new created browser window to this monitor. Total Best-run one, filer's zero, and as I like to say, never trust the past, that never failed. So let's break this test manually while running in the debug mode and see if test will actually catch the error. So let's go to our checkboxes test. And before let's put a break point here on the verification and now let's run this test in the bottom also, right? Click the bag. That's the sweet. So test is starting again, here's our browser window. Let me. My kids back in winter won't. OK, so confirm perspective. Yes, I remember my decision and switch, so our ah eclipse will switch to the back perspective. And now as you see, we are stopped here at a third through method. Now, let's open our browser back and uncheck let's uncheck second checkbox. So now first checkbox is check, but second is not. Let's go back to our. Called and continue running. Our test, so resume. We open our test and she results, we see not all check boxes are checked. So test is working, it passes one Everson's good, and it fails when not all check boxes are checked. So that's expected. So in this test we worked only with checkboxes, but our lecture 22 title is called Checkboxes and Rajo Bartons. There is no example, a test case with Sahadeo Bartons in our app under test. But selenium commands are the same for checkboxes and the radio buttons click to select and we also can use is selected method to verify if it's selected. So there is no need for me to create separate test to show it to you. But if you want, you can go to this page. Here's the URL and on this page there are a lot of different Bartons links, fields, whatever you want, and here are some variety of options and checkboxes so you can try and automate selecting this male or female or other radio boppin the same way as we did with checkboxes. So basically, the only difference is that you can select few checkboxes of the time, but with radio buttons, if one is selected, the other must be unselected so you can create a new test case to make sure if you select female, then male is unselected or something like that just to practice.