package test_classes; import org.testng.annotations.AfterMethod; import org.testng.annotations.Test; import org.testng.annotations.BeforeMethod; import java.io.File; import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.TimeUnit; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.apache.commons.io.FileUtils; import org.openqa.selenium.By; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.WebElement; import org.openqa.selenium.JavascriptExecutor; import tools.Settings; public class qsf_view_testing { private WebDriver driver; private Settings settings = new Settings(); public void makeScreenshot(String filepath) throws IOException{ File screenshot = ((TakesScreenshot) driver). getScreenshotAs(OutputType.FILE); String path = "c://tmp//"+ filepath; FileUtils.copyFile(screenshot, new File(path)); } @BeforeMethod public void SetUp(){ File file = new File(System.getProperty("user.dir")+"/drivers/chromedriver.exe"); System.setProperty("webdriver.chrome.driver", file.getAbsolutePath()); this.driver = new ChromeDriver(); //driver = new FirefoxDriver(); /*File file = new File("C:/install/selenium/chromedriver.exe"); System.setProperty("webdriver.chrome.driver", file.getAbsolutePath()); driver = new ChromeDriver();*/ /*File file = new File("C:/install/selenium/IEDriverServer.exe"); System.setProperty("webdriver.ie.driver", file.getAbsolutePath()); WebDriver driver = new InternetExplorerDriver();*/ //startUrl = "http://demo2:demo2@demo.adaptainc.com/release4-for-tests/www/admin/"; //startUrl = "http://demo.adaptainc.com/release4-for-tests/www/admin/"; driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); driver.get(settings.http + settings.siteUrl); } public void makeElementVisibleByJavascript(final WebElement element) { String script = "var element = arguments[0];" + "element.style.display='block';" ; ((JavascriptExecutor)driver).executeScript(script, element); } @Test public void testScreen(){ //driver.get("http://demo.adaptainc.com/release4-for-tests/www/admin/"); List hiddenMenus = driver.findElements(By.className("dropdown-menu")); for (WebElement hiddenMenu : hiddenMenus){ makeElementVisibleByJavascript(hiddenMenu); } List elements = driver.findElements(By.cssSelector("div.navbar ul.nav li a")); Map elements_map = new HashMap(); for (WebElement element : elements){ elements_map.put(element.getText(), element.getAttribute("href")); } for(Entry entry : elements_map.entrySet()) { driver.get(entry.getValue()); try { makeScreenshot("qsf//ff//" + entry.getKey() + ".png"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } @AfterMethod public void tearDown(){ driver.quit(); //driver.close(); } }