System.out.println(“attribute value”+driver.findElement(By.id(“someid”)).getAttribute(“value”)); JavascriptExecutor javascriptExecutor = (JavascriptExecutor) driver; System.out.println(“JavaScript”+javascriptExecutor.executeScript(“return arguments[0].value”, driver.findElement(By.id(“someid”))));
Find your win10 release Win + R. Open up the run command with the Win + R key combo. locate the release in the pop up navigate to Microsoft WebDriver official page find the matching version download the web driver corresponding to your build set WebDriver in your path System.setProperty(“webdriver.edge.driver”, “{PathToDriver}/MicrosoftWebDriver.exe”); done
Using Selenium to test administrator functionality for wordpress
Test One thing ATOMIC TESTING Each Test should be able to run Independently ( autonomous) Anyone should understand the code Group Similar Tests together Centralized Setups and Tear Downs Use Page Objects
TestVariables.driver.switchTo().frame(TestVariables.driver.findElement(By.xpath(“//html/body/div[3]/div[1]/div/div[2]/div[2]/div/div/div[3]/form/div[6]/div/div/iframe”))); TestVariables.driver.switchTo().defaultContent();
new Select(driver.findElement(By.id(“DropDownId”))).selectByVisibleText(“Germany”);
Grid allows you to : scale by distributing tests on several machines ( parallel execution ) manage multiple environments from a central point, making it easy to run the tests against a vast combination of browsers / OS. Selenium Grid allows us to run multiple instances of WebDriver or Selenium Remote Control in parallel. It […]
starting hub java -jar selenium-server-standalone-2.44.0.jar -role hub Starting node java -jar selenium-server-standalone-2.44.0.jar -role node -hub http://localhost:4444/grid/register If you want to set a specific port java -jar selenium-server-standalone-2.44.0.jar -role hub -port 4441
One of the usual problems in testing is getting access to the test environment. Usually a test server is setup where a users authentication is required in order to access the application under test. In most browsers (firefox,chrome, safari ect) this can be easily achieved by parsing the credentials in the url like so http://USERNAME:PASSWORD@www.testdomain.com […]
TestVariables.driver = new HtmlUnitDriver(true) { protected WebClient modifyWebClient(WebClient client) { // This class ships with HtmlUnit itself DefaultCredentialsProvider creds = new DefaultCredentialsProvider(); // Set some example credentials creds.addCredentials(“USERNAME”, “PASSWORD”); // And now add the provider to the webClient instance client.setCredentialsProvider(creds); return client; } };
DesiredCapabilities capabilities = DesiredCapabilities.firefox(); capabilities.setCapability(“version”, “3.6”); capabilities.setCapability(“platform”, Platform.LINUX); WebDriver = driver = new RemoteWebDriver( new URL(“http://***.***.*.**:****/wd/hub”), capabilities); TestVariables.driver.get(“http://www.google.com”);
Capabilities caps = ((RemoteWebDriver) driver).getCapabilities(); String browserName = caps.getBrowserName(); String browserVersion = caps.getVersion();
create a public abstract class TestSetUps and include your annotations @Rule @Before @After When you create a new test class extend it to the TestSetUps Class You can over ride either using the @Override annotation @Override @After public void tearDown() throws Exception { }
Use a locators file Name Junit test scripts with a common end name (e.x. EndUserTests.class) Use common @before and @after Class to run Tests Take Screenshot on fail
Still if you want to move the mouse pointer physically, you need to take different approach using Robot class Point coordinates = driver.findElement(By.id(“ctl00_portalmaster_txtUserName”)).getLocation(); Robot robot = new Robot(); robot.mouseMove(coordinates.getX(),coordinates.getY()+120); Webdriver provide document coordinates, where as Robot class is based on Screen coordinates, so I have added +120 to compensate the browser header. Screen Coordinates: These […]
File pathToBinary = new File(“C:\\Program Files\\Mozilla Firefox15\\Firefox.exe”); FirefoxBinary ffBinary = new FirefoxBinary(pathToBinary); FirefoxProfile firefoxProfile = new FirefoxProfile(); FirefoxDriver _driver = new FirefoxDriver(ffBinary,firefoxProfile);
Install Jenkins (we already have that on our server) None needed. Install plugins for Jenkins (which ones?) As far as I remember no specific plugin is required just for this purpose. Jenkins should be able to run maven or ant job, it’s out of the box. Install xvfb so tests are run in a headless […]
Locating UI Elements (WebElements) Locating elements in WebDriver can be done on the WebDriver instance itself or on a WebElement. Each of the language bindings expose a “Find Element” and “Find Elements” method. The first returns a WebElement object otherwise it throws an exception. The latter returns a list of WebElements, it can return an […]