개발 공부

Selenium 과 Selenide

king yun bell 2023. 6. 8. 15:23

Selenium의 코드를 Selenide로 더욱 간단하고 가독성 좋게 만들 수 있다.

 

<dependencies>
    <dependency>
        <groupId>com.codeborne</groupId>
        <artifactId>selenide</artifactId>
        <version>6.15.0</version>
    </dependency>
</dependencies>

maven 기준 의존성 추가 코드

 

//selenium 과 selenide의 코드 차이

//selenium에서의 element 찾기
WebElement customer = driver.findElement(By.id("customerContainer"));
//selenide에서의 element 찾기
WebElement customer = $("#customerContainer"); 
WebElement customer = $(By.id("customerContainer"));

//selenium에서의 input
WebDriver driver = new ChromeDriver();
driver.findElement(By.id("")).sendKeys("");
or
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].value = ''", WebElement);

//selenide에서의 input
$("").setValue("");
or
executeJavaScript("arguments[0].value = " + "'" + userId + "'", $("#id_user_id"));

//selenium에서의 wait
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("")));

//selenide에서의 wait
$(By.xpath("")).should(exist, Duration.ofSeconds(10));
or
$("").shouldBe(visible).shouldNotBe(visible);

//selenium에서의 frame이동
driver.switchTo().frame("inputFrame");

//selenide에서의 frame이동
switchTo().frame("inputFrame");