개발 공부
Selenium Test코드 예제
king yun bell
2023. 6. 5. 13:18
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.Test;
import static org.junit.Assert.assertEquals;
@Test
public class TestCode {
public void testDoubleClick() throws Exception{
WebDriver driver = new ChromeDriver();
driver.get("http://cookbook.seleniumacademy.com/DoubleClickDemo.html");
WebElement message = driver.findElement(By.id("message"));
assertEquals("rbg(0, 0, 255)", message.getCssValue("background-color").toString());
Actions builder = new Actions(driver);
builder.doubleClick(message).build().perform();
assertEquals("rgb(225, 225, 0)", message.getCssValue("background-color").toString());
driver.close();
}
}
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.Test;
import static org.junit.Assert.assertEquals;
@Test
public class TestCode {
public void testDragDrop() {
WebDriver driver = new ChromeDriver();
driver.get("http://cookbook.seleniumacademy.com/DragDropDemo.html");
WebElement source = driver.findElement(By.id("draggable"));
WebElement target = driver.findElement(By.id("droppable"));
Actions builder = new Actions(driver);
builder.dragAndDrop(source, target).perform();
try {
assertEquals("Dropped!", target.getText());
} catch (Error e) {
e.printStackTrace();
}
}
}