I need to automate a form where there is a checkbox for all days, and a checkbox for each day. The test cases are:
- At least one of the Days checkboxes must be checked.
- If All is checked, no other checkbox can be checked.
- If any individual day (Sunday, Monday, Tuesday etc.) is checked, All must be unchecked.
How do I get values from the check boxes, and how do I set them?
Here is my code, I wrote for testing has priority numbers are three. First default testng for open login page. After login go to category module then enter name for each field and then submit and here I want to test the check boxes .I wrote the next testng priority 3 for testing the check boxes and I run my code .Here not testing the priority no. 3 .till testing priority 1 and 2 and then finish.What should I do ?
public class subcategoryTest extends DriverManager {
subcategorysteps log;
int inputDataFlag = 0;
public subcategoryTest() throws IOException {
log = new subcategorysteps();
}
@BeforeSuite
public void initDriver() throws IOException {
HomePage page = new LoginSteps().Login(prop.getProperty("nam"), prop.getProperty("pas"));
}
@Test(dataProvider = "setData")
public void init(String nam, String nam_loc, String cat, String cli, String pre, String ts, String te, String tavg) {
log.Login(nam, nam_loc, cat, cli, pre, ts, te, tavg);
Assert.assertFalse(driver.getPageSource().contains("List Subcategory"));
}
@Test(priority = 1, dataProvider = "setData")
public void ini(String nam, String nam_loc, String cat, String cli, String pre, String ts, String te, String tavg) {
log.Login(nam, nam_loc, cat, cli, pre, ts, te, tavg);
Assert.assertTrue(driver.getPageSource().contains("List Subcategory"));
}
@DataProvider
Object[][] setData() {
Object[][] dataValues = getValues();
return dataValues;
}
@Test(priority = 2, dataProvider = "getData")
public void days() {
Assert.assertTrue(driver.getPageSource().contains("List Subcategory"));
}
@DataProvider
Object[][] getData() throws InterruptedException {
Object[][] dataValues = setValues();
return dataValues;
}
private Object[][] setValues() throws InterruptedException {
Thread.sleep(100000);
// if (!driver.findElement(By.id("days")).isSelected()) {
// driver.findElement(By.id("days")).click();
// }
// return new Object[0][];
// Find the checkbox or radio button element by its name.
List<WebElement> list = driver.findElements(By.name("days"));
// Get the number of checkboxes available.
int count = list.size();
System.out.println("no .of boxes :" +count);
// Now, iterate the loop from first checkbox to last checkbox.
for (int i = 0; i < count; i++) {
// Store the checkbox name to the string variable, using 'Value'
// attribute
String sValue = list.get(i).getAttribute("value");
// Select the checkbox if its value is the same that you want.
if (sValue.equalsIgnoreCase("Sunday")) {
list.get(i).click();
// This statement will get you out of the for loop.
break;
}
}
return new Object[0][];
}