2017-09-08 11 views
0

나는 웹 어플리케이션을 테스트하는 셀렌과 Phantomjs을 사용하고 있습니다. 다음과 같이 캡쳐를 임 : 입력 요소의셀렌 및 Firefox 기록 결함이 스크린 샷

byte[] bytes = ((TakesScreenshot)webDriver).getScreenshotAs(OutputType.BYTES); 
ByteArrayInputStream bis = new ByteArrayInputStream(bytes); 
returnImage = ImageIO.read(bis); 

이 있지만, 스크린은 다음과 같다 : faulty screenshot

실제로는 다음과 같다 (크롬을 사용할 때/파이어) how it's supposed to look

재미있는 것은 내가 제대로 스크린 샷을한다 (Configuration.Browser = "phantomjs")를 phantomjs를 사용하는 셀렌을 설정할 때입니다. 그 종류의 요소에서만 발생합니다. 버튼 등이 잘 녹음되고 있습니다. 어떤 아이디어?

추신 :이 게시물에 첨부 된 스크린 샷은 잘립니다. 여기 코드는 전체 페이지의 스크린 샷입니다. 필자는 코드에서 원하는 요소로만 스크린 샷을 자르지 만 전체 화면을 표시하는 스크린 샷에서도 요소가 올바르게 기록되지 않습니다.

답변

0

당신은 코드 아래 사용하여 요소를 스크린 샷이 걸릴 수 있습니다 : -

WebElement ele = driver.findElement(By.id("hplogo")); 

// Get entire page screenshot 
File screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); 
BufferedImage fullImg = ImageIO.read(screenshot); 

// Get the location of element on the page 
Point point = ele.getLocation(); 

// Get width and height of the element 
int eleWidth = ele.getSize().getWidth(); 
int eleHeight = ele.getSize().getHeight(); 

// Crop the entire page screenshot to get only element screenshot 
BufferedImage eleScreenshot= fullImg.getSubimage(point.getX(), point.getY(), 
    eleWidth, eleHeight); 
ImageIO.write(eleScreenshot, "png", screenshot); 

// Copy the element screenshot to disk 
File screenshotLocation = new File("C:\\images\\GoogleLogo_screenshot.png"); 
FileUtils.copyFile(screenshot, screenshotLocation); 

이제 위의 코드에서 당신이 점점 getWidth()와 getHeight된다

(). 값을 더하거나 빼서 조정할 수 있습니다.

호프가 도움이 되길 바랍니다. :)

+0

내 질문에 대한 답변이 아닌 것 같습니다. 스크린 샷을 찍는 데 문제가 없습니다. 제대로 표시되지 않는 요소입니다. – user3479176

+0

오, 그래서 당신의 운전자가 호출 될 때 자기 자신이 적절한 요소를 보이지 않습니까? –

+1

스크린 샷에는 요소가 제대로 표시되지 않습니다. 일부 재조정을 위해 이제는 작동하지만, 나는 이유가 없습니다. 어쨌든 고마워 ! – user3479176