본문 바로가기

테스트툴/Selenium

Selenium Webdriver 툴 팁

Selenium의 도구 설명은 웹 페이지의 개체 위에 마우스를 놓을 때 나타나는 텍스트입니다

개체는 링크, 이미지, 단추, 텍스트 영역이 될 수 있습니다

도구 설명 텍스트는 마우스 커서 위에 놓인 개체에 대한 자세한 정보를 제공합니다

툴 팁은 전통적으로 'title' 속성으로 구현되었습니다

 

'title' 속성을 사용한 툴 팁

실습은 

 

YouTube

 

www.youtube.com

위 페이지를 활용하였습니다

YouTube 홈에서

홈 버튼의 툴팁을 확인할 것입니다

 

먼저 요소를 찾고 'title' 속성을 가져와서 예상되는 도구 설명 텍스트로 확인합니다

툴 팁이 'title' 속성에 있다고 가정하기 때문에 마우스 오버 효과를 자동화하지 않고 단순히

getAttribute() 메소드를 사용하여 속성 값을 검색합니다

package newpackage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.*;

public class MyClass {
	public static void main(String[] args) {
		System.setProperty("webdriver.chrome.driver", "c:/selenium/chromedriver.exe");
		WebDriver driver = new ChromeDriver();
		
		String getURL = "https://www.youtube.com/";
		driver.get(getURL);
		
		String expectedTooltip = "홈";
		
		WebElement naver =driver.findElement(By.xpath("//*[@id=\"endpoint\"]"));
		
		String actualTooltip = naver.getAttribute("title");
		
		System.out.println("Actual Class of Tool Tip "+actualTooltip);
		if(actualTooltip.equals(expectedTooltip)){
			System.out.println("Test Case Passed");
		}
		driver.close();
	}
}

위 코드의 결과로

Console 결과

Console 창에 위와 같은 결과를 출력됩니다


jQuery 플러그인을 사용한 툴 팁

실습은

 

Tooltip Demo

Using any HTML inside the tooltip Tooltip content can be any HTML, not just plain text. Move your mouse over the Download button and you'll see a tooltip that contains an image, table and a link element. You can also see the slide effect in action. Downloa

demo.guru99.com

위 페이지를 활용했습니다

Download now 버튼에 마우스 오버하여 나오는

What's new in 3.2 링크를 확인해 볼 것입니다

 

우선 Download now 버튼 WebElement를 찾습니다

그리고 Interactions  API를 사용하여 요소로 이동합니다

(Actions 클래스의 moveToElement로 마우스오버 효과 사용)

도구 설명 내에서 링크에 해당하는 WebElement를 찾고 예상 텍스트와 비교하도록 합니다

package newpackage;

import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.*;

public class MyClass {
	public static void main(String[] args) {
		System.setProperty("webdriver.chrome.driver", "c:/selenium/chromedriver.exe");
		WebDriver driver = new ChromeDriver();
		
		String getURL = "http://demo.guru99.com/test/tooltip.html";
		driver.get(getURL);
		
		String expectedTooltip = "What's new in 3.2";
		
		WebElement down_bnt =driver.findElement(By.xpath("//*[@id=\"download_now\"]"));
		Actions builder = new Actions(driver);
		builder.moveToElement(down_bnt).build().perform();
		
		WebElement tooltipElement = driver.findElement(By.xpath("//*[@id=\"demo_content\"]/div/div/div/a"));
		String actualTooltip = tooltipElement.getText();
		System.out.println("Tool Tip Text " + actualTooltip);
		
		if(actualTooltip.equals(expectedTooltip)){
			System.out.println("Test Case Passed");
		}
		driver.close();
	}
}

Console 결과

위와 같은 결과를 출력합니다