2017-03-20 7 views
1
**CaptureScreenShot.java** 

public class CaptureScreenshot { 
    WebDriver driver; 

      public static void takescreenshot(WebDriver driver,String Screenshotname) throws IOException 
      { 
        TakesScreenshot takescreenshot=(TakesScreenshot)driver; 
        File source=takescreenshot.getScreenshotAs(OutputType.FILE); 
        FileUtils.copyFile(source, new File("./Screenshots/"+Screenshotname+".png")); 
        System.out.println("Screenshot Taken Successfully!!!!"); 

      } 

**Main.java** 
public class ToadsLogin extends SuperTestNG { 



@BeforeClass 
    public void precondition() 
    { 
     System.setProperty("webdriver.chrome.driver", "D:/personal/chromedriver_win32/chromedriver.exe"); 
     driver=new ChromeDriver(); 
     driver.get("http://10.1.19.234:8002/"); 
     driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); 

    } 
    @Test() 
    public void login1() 
    { 

     Login login=new Login(driver); 
     login.toadsLogin(); 
     //login.clkUsers(); 
     Assert.assertEquals("Index - TOADSw", "Index - TOADS"); 
    } 

    @AfterMethod 
    public void failedCondi(ITestResult result) throws Exception 
    { 
     System.out.println("Testcase status is"+ result.getStatus()); 
     System.out.println("result status is"+ ITestResult.FAILURE); 
     if(ITestResult.FAILURE==result.getStatus()) 
     { 
      CaptureScreenshot.takescreenshot(driver, "titlefail"); 
     } 

    } 

} 

와 함께 잘 작동합니다.스크린 샷은 크롬 브라우저에서 작동하지 않고 같은 코드이 코드는 파이어 폭스 브라우저하지만 같은 코드가 크롬 브라우저에 다음과 같은 오류를주고있다와 잘 작동 파이어 폭스

Error: FAILED CONFIGURATION: @AfterMethod failedCondi([TestResult name=login1 status=FAILURE method=ToadsLogin.login1()[pri:0, instance:[email protected]] output={null}]) 
org.openqa.selenium.WebDriverException: unknown error: cannot get automation extension 
from unknown error: page could not be found: chrome-extension://aapnijgdinlhnhlmodcfapnahmbfebeb/_generated_background_page.html 
    (Session info: chrome=57.0.2987.110) 
    (Driver info: chromedriver=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform=Windows NT 10.0.14393 x86_64) (WARNING: The server did not provide any stacktrace information) 
+0

이 최신 chromedriver 버전으로 업데이트하는 시도? – Mikhail

+0

크롬 드라이버를 업데이트하고 현재 작동 중입니다 ...하지만 반 페이지짜리 스크린 샷 만 찍습니다. 실패한 테스트 케이스 만 가져 오는 방법이 있습니까? –

+0

webdriver의 창 크기를 올바르게 설정했는지 확인하십시오 – Mikhail

답변