forked from TalhaBinAshraf1/SeleniumTestingInternetHerokuApp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddRemoveElements.java
More file actions
47 lines (36 loc) · 1.45 KB
/
Copy pathAddRemoveElements.java
File metadata and controls
47 lines (36 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package allTests;
import org.testng.Assert;
import org.testng.annotations.Test;
import utility.BaseTest;
import utility.FrameworkConstants;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class AddRemoveElements extends BaseTest{
@Test
public void test() throws InterruptedException {
System.setProperty(FrameworkConstants.CHROME_DRIVER_KEY,FrameworkConstants.CHROME_DRIVER_PATH);
WebDriver driver = new ChromeDriver();
WebElement pageLink = driver.findElement(By.xpath("//a[contains(text(),'Add/Remove Elements')]"));
pageLink.click();
validateAddElements(5, driver);
validateRemoveElements(5, driver);
}
public void validateRemoveElements(int noOfClicks, WebDriver driver) throws InterruptedException {
List<WebElement> removeElementBtns = driver.findElements(By.cssSelector("button.added-manually"));
for(int i=0;i<removeElementBtns.size();i++) {
removeElementBtns.get(i).click();
Thread.sleep(2000);
}
}
public void validateAddElements(int noOfClicks, WebDriver driver) {
WebElement addElementBtn = driver.findElement(By.xpath("//button[contains(text(),'Add Element')]"));
for(int i=0;i<noOfClicks;i++) {
addElementBtn.click();
}
List<WebElement> elements = driver.findElements(By.xpath("//div[@id='elements']/button"));
Assert.assertEquals(noOfClicks, elements.size());
}
}