List of usage examples for org.openqa.selenium WebDriver quit
void quit();
From source file:org.apache.tomcat.maven.webapp.test.SimpleTest.java
License:Apache License
@Test public void testHelloWorld() throws InterruptedException { String serverUrl = System.getProperty("serverUrl"); assertNotNull(serverUrl, "serverUrl was not found"); WebDriver driver = new ChromeDriver(); driver.get(serverUrl);//from w w w. j av a2s.c om // driver.get("http://localhost:8080/"); WebDriverWait wait = new WebDriverWait(driver, 5); wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id("who")))); driver.findElement(By.id("who")).sendKeys("Hello World!"); driver.findElement(By.id("send-btn")).click(); wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id("response")))); assertEquals("Unexpected response", "Hello Hello World!", driver.findElement(By.id("response")).getText()); driver.quit(); }
From source file:org.ballerinalang.composer.uitests.BallerinaEditorUITest.java
License:Open Source License
@Test(dataProvider = "getData") public void openBallerinaFile(String fileName) throws IOException, InterruptedException, ParserConfigurationException, SAXException, TransformerException, URISyntaxException { //creating relevant browser webdriver //TODO make this generic for multiple browsers WebDriver driver = new FirefoxDriver(); //opening base page - welcome page this case driver.get(TestConstants.SERVER_URL); //once the open button available click it waitAndGetElementByXpath(driver, TestConstants.WELCOME_PAGE_OPEN_BUTTON_XPATH).click(); //fill the location of the ballerina file to be opened URL ballerinaResourceLocation = BallerinaEditorUITest.class .getResource(TestConstants.BALLERINA_RESOURCE_FOLDER + File.separator + fileName + ".bal"); waitAndGetElementByXpath(driver, TestConstants.FILE_OPEN_POPUP_LOCATION_INPUT_XPATH) .sendKeys(ballerinaResourceLocation.getPath()); //wait for the open button in the pop-up window waitAndGetElementByXpath(driver, TestConstants.FILE_OPEN_POPUP_LOCATION_OPEN_XPATH).click(); //wait for the SVG element where the diagram is rendered WebElement domElement = waitAndGetElementByXpath(driver, TestConstants.SVG_XPATH); //Getting inner HTML of the SVG node String dom = TestUtils.preprocessDOMContent(domElement.getAttribute("innerHTML")); //TODO Add mechanism to generate DOM files //org.ballerinalang.composer.uitests.TestUtils.fileWriter(dom, fileName + "DOM.xml"); URL domResourceLocation = BallerinaEditorUITest.class .getResource(TestConstants.DOM_RESOURCE_FOLDER + File.separator + fileName + "DOM.xml"); //destroying browser instance driver.quit(); //checking inner content of the DOM element assertEquals("Rendered diagram of " + fileName + "is not equal to the expected diagram", TestUtils.fileReader(domResourceLocation.getPath()), dom); }
From source file:org.bigtester.ate.model.caserunner.CaseRunner.java
License:Apache License
/** * Tear down./*w w w . j a va 2 s .c om*/ */ @AfterMethod(alwaysRun = true) public void tearDown() { try { if (null != mainDriver) { mainDriver.quit(); } if (null != context) { Map<String, IMyWebDriver> myWebDrivers = context.getBeansOfType(IMyWebDriver.class); for (IMyWebDriver myWebDriver2 : myWebDrivers.values()) { WebDriver weD = myWebDriver2.getWebDriver(); if (null != weD) weD.quit(); } } } catch (UnreachableBrowserException | NoSuchWindowException e) { // NOPMD // browser has been closed, no action needs to be done here. } if (null != context) { ((ConfigurableApplicationContext) context).close(); } }
From source file:org.bigtester.ate.model.casestep.CaseTypeService.java
License:Apache License
/** * {@inheritDoc}// ww w . j av a 2s.co m */ @Override public void doStep() throws StepExecutionException2, PageValidationException2, RuntimeDataException { String testCaseFileName = getTestCaseFileName(); WebDriver mainDriver; ApplicationContext context; context = new FileSystemXmlApplicationContext(testCaseFileName); IMyWebDriver myWebD = (IMyWebDriver) GlobalUtils.findMyWebDriver(context); mainDriver = myWebD.getWebDriverInstance(); try { super.setCurrentWebDriver(myWebD); setStepThinkTime(getParentTestCase().getStepThinkTime()); /* remove all the asserters */ TestCase newTestcase = (TestCase) GlobalUtils.findTestCaseBean(context); newTestcase.cleanUpAsserters(); newTestcase.goSteps(); /* transfer all the dataholders value to parent test case */ for (int j = 0; j < getDataHolders().size(); j++) { IDataParser parentDataHolder = getDataHolders().get(j); if (parentDataHolder instanceof ICaseServiceParsedDataParser) { ICaseServiceParsedDataParser parentDataHolderTemp = (ICaseServiceParsedDataParser) parentDataHolder; parentDataHolderTemp.setStrDataValue( ((IStepInputData) context.getBean(parentDataHolderTemp.getSubCaseMappedDataHolderID())) .getStrDataValue()); } } } catch (Throwable t) { // NOPMD mainDriver.quit(); throw t; } }
From source file:org.bigtester.ate.systemlogger.problemhandler.ProblemBrowserHandler.java
License:Apache License
/** * {@inheritDoc}//from ww w . j a va 2 s . c o m */ @Override public void handleProblem(@Nullable Problem aProblem) { WebDriver webD = myWebDriver.getWebDriver(); if (null != webD) webD.quit(); }
From source file:org.craftercms.cstudio.share.selenium.basic.CStudioSeleniumUtil.java
License:Open Source License
public static void exit(WebDriver driver) { driver.close(); driver.quit(); }
From source file:org.ednovo.gooru.web.util.WebDriverUtil.java
License:Open Source License
/** * Generates screen shot for the given// ww w . j a v a2s .c o m * * @param url * of dimension * @param width * x * @param height * * */ public byte[] generateScreenshot(String sourceUrl, int width, int height) throws Exception { /* Load driver and take screenshot */ errorMsg = "Error to take screen shot"; String targetFileName = ""; WebDriver driver = new FirefoxDriver(); driver.get(sourceUrl); Thread.sleep(2000); String fileName = sourceUrl.substring(sourceUrl.lastIndexOf("/") + 1); Dimension dimesions = driver.findElement(By.tagName("html")).getSize(); imageWidth = dimesions.width; try { String scrFileName = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE).toString(); targetFileName = fileName + ".png"; new ImageScaler().scaleImage(scrFileName, width, height, targetFileName, imageWidth); } catch (Exception e) { return FileUtils.readFileToByteArray(new File(errorMsg)); } driver.quit(); imageWidth = 0; return FileUtils.readFileToByteArray(new File(targetFileName)); }
From source file:org.eweb4j.spiderman.plugin.util.WebDriverDownloader.java
License:Apache License
public void close() throws Exception { for (String h : this.client.getWindowHandles()) { WebDriver d = this.client.switchTo().window(h); try {//w w w . j a v a 2 s . c o m d.quit(); } catch (Throwable e) { } try { d.quit(); } catch (Throwable e) { } } try { this.client.close(); } catch (Throwable e) { } try { this.client.quit(); } catch (Throwable e) { } }
From source file:org.glassfish.tyrus.tests.qa.SeleniumToolkit.java
License:Open Source License
public static void quit() { for (WebDriver driver : webDriverInstances) { driver.quit(); } }
From source file:org.hepaces.surveyfeedbacktestscript.KrogerFeedbackManager.java
public static void main(String[] args) { //test inputs DateTime date = new DateTime(); WebDriver browser = new FirefoxDriver(); String entryId = "014-695-15-858-88-0a"; browser.get("https://www.krogerfeedback.com/"); fillInDateAndTime(date, browser);/* w w w . j a va2 s. com*/ fillInEntryId(entryId, browser); clickSubmit(browser); System.out.println(getErrorMessage(browser)); browser.close(); browser.quit(); }