Git Product home page Git Product logo

dmk07 / selenium Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 1.92 MB

Selenium is one of the most widely used open source Web UI (User Interface) automation testing suite. It was originally developed by Jason Huggins in 2004 as an internal tool at Thought Works. Selenium supports automation across different browsers, platforms and programming languages. Selenium automates browsers. That's it!

Java 100.00%

selenium's Introduction

Documentation

Documentation

Selenium

Selenium is one of the most widely used open source Web UI (User Interface) automation testing suite.

It was originally developed by Jason Huggins in 2004 as an internal tool at Thought Works.

Selenium supports automation across different browsers, platforms and programming languages.

Selenium automates browsers. That's it!

What you do with that power is entirely up to you

Primarily it is for automating web applications for testing purposes, but is certainly not limited to just that

Boring web-based administration tasks can (and should) also be automated as well

Driver Initilization

WebDriver driver = new ChromeDriver();
WebDriver driver = new FirefoxDriver();
WebDriver driver = new InternetExplorerDriver();
WebDriver driver = new EdgeDriver();
WebDriver driver = new SafariDriver();
WebDriver driver = new HtmlUnitDriver();

Element Locators

driver.findElement(By.id("Id Value"));
driver.findElement(By.name("Name Value"));
driver.findElement(By.className("Class Name Value"));
driver.findElement(By.linkText("Link text Value"));
driver.findElement(By.partialLinkText("Partial Text Constant Value"));
driver.findElement(By.tagName("Tag Name Value"));
driver.findElement(By.cssSelector("CSS Value"));
driver.findElement(By.xpath("Xpath Value"));
driver.findElement(with(By.tagName("input")).above(passwordField));
driver.findElement(with(By.tagName("input")).below(emailAddressField));
driver.findElement(with(By.tagName("button")).toLeftOf(submitButton));
driver.findElement(with(By.tagName("button")).toRightOf(submitButton));
driver.findElement(with(By.tagName("input")).near(emailAddressLabel));
driver.findElement(new ByAll(By.className("ElementClassName"),By.id("Element Id"), By.name("Element Name")))

Elements Operations

WebElement element =driver.FindElement(By.ElementLocator("Value of Element Locator"));
element.click();
element.sendKeys("Input Text");
element.clear();
element.submit();
element.getAttribute(“type”);
String innerText = element.getText();
boolean enabledstatus = element.isEnabled();
boolean displayedstatus = element.isDisplayed();
boolean selectedstatus = element.isSelected();

Operation on drop down

Select select = new Select(element);

select.selectByIndex(Integer Index);
select.selectByVisibleText("Text");
select.SelectByValue("Value");
select.deselectAll();
select.deselectByIndex(Integer Index);
select.deselectByVisibleText("Text");
select.deselectByValue("Value");

WebElement selectedOptions = select.getOptions();

Browser Operations

String pageTitle = driver.getTitle();
String currentURL = getCurrentUrl();
String currentPageSource = driver.getPageSource();

Navigation history

driver.get("https://www.facebook.com/");
driver.manage().window().maximize();
driver.manage().window().fullscreen();

driver.navigate().to("https://www.google.com/");
driver.navigate().back();
driver.navigate().forward();
driver.navigate().refresh();
driver.close();
driver.quit();

Handle Alert

Alert alert = driver.switchTo().alert();
alert.accept();
alert.dismiss();
alert.getText();
alert.sendKeys(“Input Data");

Handle Cookies

Cookie cookie = new Cookie(“cookieName”, “cookieValue”);
driver.manage().addCookie(cookie);
driver.manage().getCookies();
driver.manage().getCookieNamed(arg0);
driver.manage().deleteAllCookies();
driver.manage().deleteCookieNamed(arg0);

Handle frames

driver.switchTo().frame(int Frame Index);

driver.switchTo().frame("frameName");
WebElement element =driver.FindElement(By.ElementLocator("Value of Element Locator"));
driver.switchTo().frame(element);
driver.SwitchTo().defaultContent();

Screenshots Capture

TakesScreenshot screenshot =((TakesScreenshot)driver);

File srcFile= screenshot.getScreenshotAs(OutputType.FILE);
FileHandler.copy(srcFile, destFile);

Actions Class/Mouse Event

Actions action = new Actions(driver);
action.keyDown(Keys.CONTROL);
action.keyUp(Keys.CONTROL);
action.clickAndHold(webElement).build().perform();
action.doubleClick(webElement).build().perform();
action.moveToElement(webElement).build().perform();
action.moveByOffset(xOffset,yOffset).build().perform();
action.dragAndDrop(sourceEle,targetEle).build().perform();
action.release().build().perform();

Manage Timeouts

driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
welement = wait.until(Syntax: WebDriverWait wait = new WebDriverWait(driver, timeout);
ExpectedConditions.elementToBeClickable(locator));

welement.click();
driver.manage().timeouts().pageLoadTimeout(30,TimeUnit.SECONDS);

Upload a File

WebElement element =driver.FindElement(By.ElementLocator("Value of ElementLocator"));
element.sendKeys(filePath);

Window Handle

String handle=driver.getWindowHandle();
Set handles = getWindowHandles();

driver.switchTo().window(handle);

##Capture Width and Height of an Element

Point point = element.getLocation();
int elementWidth = element.getSize().getWidth();
int elementHeight = element.getSize().getHeight();

Scroll Down or Up Web Page

JavascriptExecutor js = (JavascriptExecutor)driver;

js.executeScript("window.scrollBy(0,100)");
js.executeScript("window.scrollTo(0, document.body.scrollHeight)");
WebElement element =driver.FindEle
ment(By.ElementLocator("Value of Element Locator"));
js. executeScript("arguments[0].scrollIntoView()", element);

Authors

@Dipak Kadam

##Selenium

Table of Contents

You're sections headers will be used to reference location of destination.


Description

Selenium is the best automation tool for web testing. In this project you wil learn from scratch to advanced level of concect which had in selenium.

Technologies

  • Java
  • Selenium WebDriver
  • Eclipse(IDE)

Back To The Top


How To Use

Installation

API Reference

    <p>dummy code</p>

Back To The Top


References

Back To The Top


License

MIT License

Copyright (c) [2017] [James Q Quick]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Back To The Top


Author Info

Back To The Top

selenium's People

Contributors

dmk07 avatar

Watchers

Kostas Georgiou avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.