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
@Before is executed before each test, @BeforeClass runs once before the entire test fixture. If your test class has ten tests, @Before code will be executed ten times, but @BeforeClass will be executed only once. In general, you use @BeforeClass when multiple tests need to share the same computationally expensive setup code. Establishing a database connection falls into this category. You can move […]
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
You can use Linux Screen to run tests without maintaining an active shell session. To do that start Linux Screen by typing screen in the console you can either close the session or hit Ctrl + a , d. To reattach to the screen. To Reconnect type screen -r . if you have more than […]
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();
locate your sdk installation folder (windows c:\Users\{user}\AppData\Local\Android\Sdk\platform-tools) locate adb.exe Open Terminal in that folder ( Shift + right click) open command window here type adb.exe – e install {path to apk}
new Select(driver.findElement(By.id(“DropDownId”))).selectByVisibleText(“Germany”);
import org.junit.Rule; public class NameRuleTest { @Rule public TestName name = new TestName(); @Test public void testA() { assertEquals(“testA”, name.getMethodName()); } @Test public void testB() { assertEquals(“testB”, name.getMethodName()); } }
Selenium IDE (firefox) Selenium IDE Chrome Nimbus Screen Capture and edit
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 […]
1. download the version of jenkins you want to use 2. Navigate to /usr/share/jenkins 3 Replace the war file Restart the service
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 […]
This class is used to generate native system input events for the purposes of test automation, self-running demos, and other applications where control of the mouse and keyboard is needed. The primary purpose of Robot is to facilitate automated testing of Java platform implementations. http://docs.oracle.com/javase/7/docs/api/java/awt/Robot.html
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 { }
Selenium WebDriver / Grid Simulates user interphase with the web application and distributes tests among a network Selenium IDE Firefox Plug in that helps non coders to produce C# test scripts for test case expansion and maintenance Nunit Unit Testing environment used to run test scripts and report Oracle Virtual Box system emulator
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 […]