How to use equals method of org.openqa.selenium.Rectangle class

Best Selenium code snippet using org.openqa.selenium.Rectangle.equals

Source:RoboDriverServerTest.java Github

copy

Full Screen

...231 DesiredCapabilities roboCapabilities = RoboDriver.getDesiredCapabilities();232 RoboDriver roboDriver = new RoboDriver(roboCapabilities);233 RemoteWebElement screen1 = (RemoteWebElement) roboDriver.findElementByXPath("//screen[0]");234 RemoteWebElement screen2 = (RemoteWebElement) roboDriver.findElementByXPath("//screen[0]");235 assertTrue(screen1.equals(screen2));236 }237 @Test238 public void testRoboScreenRectangleTestEquals() {239 DesiredCapabilities roboCapabilities = RoboDriver.getDesiredCapabilities();240 RoboDriver roboDriver = new RoboDriver(roboCapabilities);241 WebElement screen = roboDriver.findElementByXPath("//screen[@default=true]");242 WebElement rectangle1 = screen.findElement(By.xpath("//rectangle[@dim='70,80,100,200']"));243 WebElement rectangle2 = screen.findElement(By.xpath("//rectangle[@dim='70,80,100,200']"));244 WebElement rectangle3 = screen.findElement(By.xpath("//rectangle[@dim='90,80,100,200']"));245 assertTrue(rectangle1.equals(rectangle2));246 assertFalse(rectangle1.equals(rectangle3));247 assertFalse(rectangle2.equals(rectangle3));248 }249 private void assertEqualsImage(String expectedImage, File imageFile) throws IOException {250 File expectedImageFile = new File(this.getClass().getClassLoader().getResource(expectedImage).getFile());251 assertTrue(new RoboUtil().matchImages(expectedImageFile, imageFile));252 }253 private String getServerNotRunningInfoText() {254 return format("Ignored, server '%s' not connectable.", serverURL.toString());255 }256}...

Full Screen

Full Screen

Source:Topic_07_UserInteractions.java Github

copy

Full Screen

1package selenium_api;2import org.testng.annotations.Test;3import org.junit.Assert;4import org.testng.annotations.BeforeClass;5import java.util.List;6import java.util.concurrent.TimeUnit;7import org.openqa.selenium.Alert;8import org.openqa.selenium.By;9import org.openqa.selenium.JavascriptExecutor;10import org.openqa.selenium.WebDriver;11import org.openqa.selenium.WebElement;12import org.openqa.selenium.firefox.FirefoxDriver;13import org.openqa.selenium.interactions.Actions;14import org.testng.annotations.AfterClass;15public class Topic_07_UserInteractions {16 WebDriver driver;17 @BeforeClass18 public void beforeClass() {19 driver = new FirefoxDriver();20 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);21 driver.manage().window().maximize();22 }23 @Test(enabled = false)24 public void TC_HoverMouse() {25 driver.get("http://daominhdam.890m.com/");26 // Hover chuột vào title: 'Hover over me'27 WebElement hoverText = driver.findElement(By.xpath("//a[text()='Hover over me']"));28 Actions action = new Actions(driver);29 action.moveToElement(hoverText).perform();30 // Verify tooltip này được hiển thị31 Assert.assertEquals(32 driver.findElement(By.xpath("//div[@role='tooltip']/div[@class='tooltip-inner']")).getText(),33 "Hooray!");34 }35 @Test(enabled = false)36 public void TC_HoverText() {37 driver.get("http://www.myntra.com/");38 // Hover chuột vào menu login39 WebElement hovermenu = driver.findElement(By.xpath("//div[@class='desktop-userActions']"));40 Actions action = new Actions(driver);41 action.moveToElement(hovermenu).perform();42 // Chọn Login button43 String login = "//a[text()='login']";44 clickElementByJavascript(login);45 // Verify Login form được hiển thị46 Assert.assertTrue(driver.findElement(By.xpath("//div[@class='login-box']")).isDisplayed());47 }48 @Test49 public void TC_Click_holdElement() {50 driver.get("http://jqueryui.com/resources/demos/selectable/display-grid.html");51 // Click and hold từ 1-> 452 List<WebElement> listitems = driver.findElements(By.xpath("//ol[@id='selectable']/li"));53 Actions moveitems = new Actions(driver);54 moveitems.clickAndHold(listitems.get(0)).moveToElement(listitems.get(3)).release().perform();55 // Sau khi chọn kiểm tra rằng có đúng 4 phần tử đã được chọn thành công với56 List<WebElement> selectableselected = driver.findElements(By.xpath("//li[@class='ui-state-default ui-selectee ui-selected']"));57 Assert.assertEquals(selectableselected.size(), 4);58 }59 @Test(enabled = false)60 public void TC_Doubleclick() throws InterruptedException {61 driver.get("http://www.seleniumlearn.com/double-click");62 Thread.sleep(3000);63 // Double click vào element: Double-Click Me!64 WebElement DoubleclickMe = driver.findElement(By.xpath("//button [text()='Double-Click Me!']"));65 Actions action = new Actions(driver);66 action.doubleClick(DoubleclickMe).perform();67 // Verify text trong alert được hiển thị: 'The Button was double-clicked.'68 Alert alert = driver.switchTo().alert();69 String ConfirmAlert = alert.getText();70 Assert.assertEquals(ConfirmAlert, "The Button was double-clicked.");71 Thread.sleep(3000);72 // Accept Javascript alert73 alert.accept();74 }75 // Right click to element76 @Test(enabled = false)77 public void TC_Rightclick() {78 driver.get("http://swisnl.github.io/jQuery-contextMenu/demo.html");79 // Right click vào element80 WebElement RightclickMe = driver.findElement(By.xpath("//span[text()='right click me']"));81 Actions action = new Actions(driver);82 action.contextClick(RightclickMe).perform();83 // Hover chuột vào element quit84 WebElement hoverquit = driver.findElement(By.xpath("//li[contains(@class,'context-menu-icon-quit')]"));85 Actions action2 = new Actions(driver);86 action2.moveToElement(hoverquit).perform();87 // Verify element Quit (visible + hover)88 Assert.assertTrue(driver.findElement(By.xpath(89 "//li[contains(@class,'context-menu-icon-quit')and contains(@class,'context-menu-hover')and contains(@class,'context-menu-visible')]"))90 .isDisplayed());91 // Click chọn Quit92 hoverquit.click();93 // Accept Javascript alert (cannot see this popup)94 Alert alert = driver.switchTo().alert();95 String textonAlert = alert.getText();96 Assert.assertEquals(textonAlert, "clicked: quit");97 // Accept alert98 alert.accept();99 }100 // Drag and drop element101 @Test(enabled = false)102 public void TC_Drag_drop() {103 // // Case 1104 // driver.get("http://demos.telerik.com/kendo-ui/dragdrop/angular");105 // // Kéo hình tròn nhỏ vào hình tròn lớn106 // WebElement small_circle =107 // driver.findElement(By.xpath("//*[@id='draggable']"));108 // WebElement big_circle= driver.findElement(By.xpath("//*[@id='droptarget']"));109 // Actions action3 = new Actions(driver);110 // action3.dragAndDrop(small_circle, big_circle).build().perform();111 // // Verify message đã thay đổi: You did great!112 // Assert.assertEquals(big_circle.getText(), "You did great!");113 //--------------------------------------------------------------------------114 // Case 2115 driver.get("http://jqueryui.com/resources/demos/droppable/default.html");116 // Kéo hình chữ nhật: Drag me to my target vào hình Drop here117 WebElement small_rectangle = driver.findElement(By.xpath("//*[@id='draggable']"));118 WebElement big_rectangle = driver.findElement(By.xpath("//*[@id='droppable']"));119 Actions action4 = new Actions(driver);120 action4.dragAndDrop(small_rectangle, big_rectangle).build().perform();121 // Verify message đã thay đổi: Dropped!122 Assert.assertEquals(big_rectangle.getText(),"Dropped!");123 }124 @AfterClass125 public void afterClass() {126 driver.quit();127 }128 public void clickElementByJavascript(String locator) {129 WebElement element = driver.findElement(By.xpath(locator));130 JavascriptExecutor je = (JavascriptExecutor) driver;131 je.executeScript("arguments[0].click();", element);132 }133}...

Full Screen

Full Screen

Source:RoboDriverFindImageTest.java Github

copy

Full Screen

1package io.test.automation.robodriver;2import static org.junit.Assert.assertEquals;3import static org.junit.Assert.assertTrue;4import java.io.File;5import java.io.IOException;6import org.junit.AfterClass;7import org.junit.Before;8import org.junit.BeforeClass;9import org.junit.Test;10import org.openqa.selenium.By;11import org.openqa.selenium.Rectangle;12import org.openqa.selenium.WebDriverException;13import org.openqa.selenium.WebElement;14import org.openqa.selenium.remote.DesiredCapabilities;15import org.openqa.selenium.remote.RemoteWebDriver;16public class RoboDriverFindImageTest {17 private static RemoteWebDriver browser;18 private static TestUtil util;19 private static WebElement clickInfo;20 private static WebElement testImageInWebPage;21 /**22 * Same image as {@link #testImageInWebPage}23 */24 private static File testImageToFind;25 private static File testImageNotToFind;26 private RoboDriver robo;27 @BeforeClass28 public static void onBeforeClass() throws IOException {29 util = new TestUtil();30 browser = util.startChrome();31 util.navigateToTestPage(browser);32 clickInfo = browser.findElementById("outputs");33 assertTrue("click info must be empty", clickInfo.getAttribute("value").isEmpty());34 testImageInWebPage = browser.findElementById("testimage");35 testImageToFind = new File(36 RoboDriverFindImageTest.class.getClassLoader().getResource("test_image_1.png").getFile());37 testImageNotToFind = new File(38 RoboDriverFindImageTest.class.getClassLoader().getResource("test_image_2.png").getFile());39 }40 @AfterClass41 public static void onAfterClass() {42 if (browser != null) {43 browser.quit();44 util.stopServices();45 }46 }47 @Before48 public void onBeforeTest() throws IOException {49 DesiredCapabilities roboCapabilities = RoboDriver.getDesiredCapabilities();50 robo = new RoboDriver(roboCapabilities);51 }52 @Test53 public void testFindImageOnScreenByFileUri() throws IOException {54 RoboDriverUtil roboUtil = new RoboDriverUtil();55 Rectangle expectedImageRect = roboUtil.getScreenRectangleOfBrowserElement(testImageInWebPage);56 // when57 WebElement foundImageRectangle = robo.findElementByXPath(58 String.format("//screen[@default=true]//rectangle[@img='%s']", testImageToFind.toURI()));59 // then60 assertEquals(util.toString(expectedImageRect), util.toString(foundImageRectangle.getRect()));61 }62 @Test63 public void testFindImageOnScreenByDataUri() throws IOException {64 RoboDriverUtil roboUtil = new RoboDriverUtil();65 Rectangle expectedImageRect = roboUtil.getScreenRectangleOfBrowserElement(testImageInWebPage);66 // when (data URI represents image: scr/test/resources/test_image_1.png67 WebElement foundImageRectangle = robo.findElementByXPath(String.format(68 "//screen[@default=true]//rectangle[@img='%s']",69 "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAClSURBVDhPpdFbDoUgDEXR4zz0T+c/Mp2CeoglRUupsBMvmktXfEwAzrt7ASZedfSM41i2rHEZap/XtGZpBBWMFU4PWmKG8QfVGDNBFkHfGKuCzEMtjLkgs/6sYawJMr3Bw1gIZNzUwlgYJBbZGAL1nbU2N0HrMb0BF/TeWW2oCsY+wHfQBCOY9B7+gH8wSQMJfM67MKlA+TOCSYJCY+mWOw4JwHkBGJ9CpvqlAE0AAAAASUVORK5CYII="));70 // then71 assertEquals(util.toString(expectedImageRect), util.toString(foundImageRectangle.getRect()));72 }73 @Test74 public void testFindImageWithinRectangle() throws IOException {75 RoboDriverUtil roboUtil = new RoboDriverUtil();76 Rectangle expectedImageRect = roboUtil.getScreenRectangleOfBrowserElement(testImageInWebPage);77 WebElement testImage = browser.findElementById("testimage");78 Rectangle rect = roboUtil.getScreenRectangleOfBrowserElement(testImage);79 WebElement rectangle = robo80 .findElementByXPath(String.format("//screen[@default=true]//rectangle[@dim='%d,%d,%d,%d']",81 rect.getX() - 10, rect.getY() - 10, rect.getWidth() + 20, rect.getHeight() + 20));82 // when83 WebElement foundImageRectangle = rectangle.findElement(By.xpath(String.format("//rectangle[@img='%s']",84 "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAClSURBVDhPpdFbDoUgDEXR4zz0T+c/Mp2CeoglRUupsBMvmktXfEwAzrt7ASZedfSM41i2rHEZap/XtGZpBBWMFU4PWmKG8QfVGDNBFkHfGKuCzEMtjLkgs/6sYawJMr3Bw1gIZNzUwlgYJBbZGAL1nbU2N0HrMb0BF/TeWW2oCsY+wHfQBCOY9B7+gH8wSQMJfM67MKlA+TOCSYJCY+mWOw4JwHkBGJ9CpvqlAE0AAAAASUVORK5CYII=")));85 // then86 assertEquals(util.toString(expectedImageRect), util.toString(foundImageRectangle.getRect()));87 }88 @Test89 public void testClickToCenterOfImageOnScreenByUri() throws IOException {90 // when91 WebElement foundImageRectangle = robo.findElementByXPath(92 String.format("//screen[@default=true]//rectangle[@img='%s']", testImageToFind.toURI()));93 foundImageRectangle.click();94 // then95 assertEquals("image click position (10,10)", clickInfo.getAttribute("value").trim());96 }97 @Test(expected = WebDriverException.class) // TODO fix exception type, should be NoSuchElementException98 public void testCannotFindImageOnScreenByUri() throws IOException {99 robo.findElementByXPath(100 String.format("//screen[@default=true]//rectangle[@img='%s']", testImageNotToFind.toURI()));101 }102}...

Full Screen

Full Screen

Source:RoboScreenRectangleTest.java Github

copy

Full Screen

1package io.test.automation.robodriver;2import static org.junit.Assert.assertEquals;3import static org.junit.Assert.assertFalse;4import static org.junit.Assert.assertTrue;5import java.io.IOException;6import org.junit.AfterClass;7import org.junit.Before;8import org.junit.BeforeClass;9import org.junit.Test;10import org.openqa.selenium.By;11import org.openqa.selenium.Point;12import org.openqa.selenium.WebElement;13import org.openqa.selenium.remote.DesiredCapabilities;14import org.openqa.selenium.remote.RemoteWebDriver;15public class RoboScreenRectangleTest {16 private static Point casp; // click area screen position of left upper corner17 private static RemoteWebDriver browser;18 private static TestUtil util;19 private RoboDriver robo;20 @BeforeClass21 public static void onBeforeClass() throws IOException {22 util = new TestUtil();23 browser = util.startChrome();24 util.navigateToTestPage(browser);25 WebElement clickArea = browser.findElementById("clickarea");26 casp = new RoboDriverUtil().getScreenRectangleOfBrowserElement(clickArea).getPoint();27 WebElement clickInfo = browser.findElementById("outputs");28 assertTrue("click info must be empty", clickInfo.getAttribute("value").isEmpty());29 }30 @AfterClass31 public static void onAfterClass() {32 if (browser != null) {33 browser.quit();34 util.stopServices();35 }36 }37 @Before38 public void onBeforeTest() throws IOException {39 DesiredCapabilities roboCapabilities = RoboDriver.getDesiredCapabilities();40 robo = new RoboDriver(roboCapabilities);41 }42 @Test43 public void testRectangle() throws IOException {44 // when: retrieve rectangle x,y,width,height (x,y = position of left upper45 // corner)46 WebElement screenRectangle = robo47 .findElementByXPath("//screen[@default=true]//rectangle[@dim='10,20,500,300']");48 // then49 assertEquals(10, screenRectangle.getLocation().x);50 assertEquals(20, screenRectangle.getLocation().y);51 assertEquals(500, screenRectangle.getSize().width);52 assertEquals(300, screenRectangle.getSize().height);53 }54 @Test55 public void testRectangleOfScreen() throws IOException {56 WebElement screen = robo.findElementByXPath("//screen[@default=true]");57 // when: retrieve rectangle x,y,width,height (x,y = position of left upper58 // corner)59 WebElement screenRectangle = screen.findElement(By.xpath("rectangle[@dim='10,20,500,300']"));60 // then61 assertEquals(10, screenRectangle.getLocation().x);62 assertEquals(20, screenRectangle.getLocation().y);63 assertEquals(500, screenRectangle.getSize().width);64 assertEquals(300, screenRectangle.getSize().height);65 }66 /**67 * The location of a WebElement representing a rectangle is always relative to68 * the screen.69 * 70 * @throws IOException71 */72 @Test73 public void testRectangleWithinRectangle() throws IOException {74 WebElement screen = robo.findElementByXPath("//screen[@default=true]");75 WebElement screenRectangle = screen.findElement(By.xpath("rectangle[@dim='10,20,500,300']"));76 assertEquals(10, screenRectangle.getLocation().x);77 assertEquals(20, screenRectangle.getLocation().y);78 assertEquals(500, screenRectangle.getSize().width);79 assertEquals(300, screenRectangle.getSize().height);80 // when: retrieve rectangle x,y,width,height (x,y = position of left upper81 // corner)82 WebElement screenRectangleRectangle = screenRectangle.findElement(By.xpath("rectangle[@dim='5,12,100,200']"));83 // then84 assertEquals(5 + screenRectangle.getLocation().x, screenRectangleRectangle.getLocation().x);85 assertEquals(12 + screenRectangle.getLocation().y, screenRectangleRectangle.getLocation().y);86 assertEquals(100, screenRectangleRectangle.getSize().width);87 assertEquals(200, screenRectangleRectangle.getSize().height);88 }89 @Test90 public void testRectangleClick() throws IOException {91 WebElement clickInfo = browser.findElementById("outputs");92 // when: click to center of a rectangle from screen93 WebElement screenRectElem = robo.findElementByXPath(String94 .format("//screen[@default=true]//rectangle[@dim='%d,%d,%d,%d']", casp.getX(), casp.getY(), 100, 80));95 screenRectElem.click();96 // then97 String clickInfoText = clickInfo.getAttribute("value");98 assertFalse("click not executed, click info was empty", clickInfoText.isEmpty());99 assertTrue("unexpected click info: " + clickInfoText, clickInfoText.contains("50,40"));100 }101}...

Full Screen

Full Screen

Source:Home.java Github

copy

Full Screen

1package CashKaroPage;2import static org.testng.Assert.assertEquals;3import java.awt.Rectangle;4import java.awt.image.BufferedImage;5import java.io.File;6import javax.imageio.ImageIO;7import org.openqa.selenium.By;8import org.openqa.selenium.OutputType;9import org.openqa.selenium.Point;10import org.openqa.selenium.TakesScreenshot;11import org.openqa.selenium.WebDriver;12import org.openqa.selenium.WebElement;13import org.openqa.selenium.support.FindBy;14import org.openqa.selenium.support.PageFactory;15import org.openqa.selenium.firefox.FirefoxDriver;16import org.openqa.selenium.internal.WrapsDriver;17import org.openqa.selenium.WebDriver;18import org.openqa.selenium.WebElement;19import org.openqa.selenium.By;20 21 22 23import net.sourceforge.tess4j.*;24import java.io.File;25public class Home {26 27 @FindBy(id="link_join") WebElement freeJoinLink;28 @FindBy(id="firstname") WebElement Firstname;29 @FindBy(id="email") WebElement Email;30 @FindBy(id="pwd-txt") WebElement pwdtxt;31 @FindBy(id="mobile_number") WebElement mobile_number;32 @FindBy(id="to_be_check") WebElement to_be_check;33 @FindBy(id="join_free_submit") WebElement join_free_submit;34 WebDriver driver;35 String firstname;36 String email;37 String phonNumber;38 String Password;39 int captchaCount;40 41 public Home(WebDriver driver)42 {43 this.driver=driver;44 PageFactory.initElements(driver, this);45 }46 47 public void clickJoinFreeButton () throws InterruptedException48 {49 freeJoinLink.click();50 Thread.sleep(3000);51 }52 53 public void enterSignUpDetails(String firstname,54 String email,55 String phonNumber,56 String Password57 ) throws Exception {58 59 this.firstname=firstname;60 this.email=email;61 this.Password=Password;62 this.phonNumber=phonNumber;63 this.clickJoinFreeButton();64 Firstname.sendKeys(firstname);65 Email.sendKeys(email);66 mobile_number.sendKeys(phonNumber);67 pwdtxt.sendKeys(Password);68 this.readCapcha();69 70 Thread.sleep(3000);71 72 73 74 75 }76 77 public static File captureElementPicture(WebElement element)78 throws Exception {79 80 // get the WrapsDriver of the WebElement81 WrapsDriver wrapsDriver = (WrapsDriver) element;82 83 // get the entire screenshot from the driver of passed WebElement84 File screen = ((TakesScreenshot) wrapsDriver.getWrappedDriver())85 .getScreenshotAs(OutputType.FILE);86 87 // create an instance of buffered image from captured screenshot88 BufferedImage img = ImageIO.read(screen);89 90 // get the width and height of the WebElement using getSize()91 int width = element.getSize().getWidth();92 int height = element.getSize().getHeight();93 94 // create a rectangle using width and height95 Rectangle rect = new Rectangle(width, height);96 97 // get the location of WebElement in a Point.98 // this will provide X & Y co-ordinates of the WebElement99 Point p = element.getLocation();100 101 // create image for element using its location and size.102 // this will give image data specific to the WebElement103 BufferedImage dest = img.getSubimage(p.getX(), p.getY(), rect.width,104 rect.height);105 106 // write back the image data for element in File object107 ImageIO.write(dest, "png", screen);108 109 // return the File object containing image data110 return screen;111 }112 113 public void readCapcha() throws Exception114 {115 116 // get and capture the picture of the img element used to display the barcode image117 WebElement barcodeImage = driver.findElement(By.id("security_image"));118 File imageFile = Home.captureElementPicture(barcodeImage);119 120 // get the Tesseract direct interace121 Tesseract instance = new Tesseract();122 instance.setLanguage("eng");123 124 // the doOCR method of Tesseract will retrive the text125 // from image captured by Selenium126 String result = instance.doOCR(imageFile);127 128 // check the the result129 assertEquals("Application number did not match", "123-45678", result.trim());130 System.out.println("*********"+result.toString());131 132 }133 134 }135 ...

Full Screen

Full Screen

Source:NotepadDemoTest.java Github

copy

Full Screen

1package com.microfocus.silk.appdriver.tests;2import static org.junit.Assert.*;3import static org.junit.Assert.assertNotSame;4import java.io.File;5import java.net.URL;6import java.util.concurrent.TimeUnit;7import org.junit.After;8import org.junit.Before;9import org.junit.Test;10import org.openqa.selenium.By;11import org.openqa.selenium.OutputType;12import org.openqa.selenium.Point;13import org.openqa.selenium.Rectangle;14import org.openqa.selenium.TakesScreenshot;15import org.openqa.selenium.WebDriver;16import org.openqa.selenium.WebElement;17import org.openqa.selenium.interactions.Actions;18import org.openqa.selenium.remote.DesiredCapabilities;19import org.openqa.selenium.remote.RemoteWebDriver;20public class NotepadDemoTest {21 private static final String APP = "%WINDIR%\\notepad.exe";22 private WebDriver driver;23 @Before24 public void startApp() throws Exception {25 DesiredCapabilities capabilities = new DesiredCapabilities();26 capabilities.setCapability("app", APP);27 driver = new RemoteWebDriver(new URL("http://localhost:8080"), capabilities);28 driver.manage().timeouts().implicitlyWait(17, TimeUnit.SECONDS);29 String windowHandle = driver.getWindowHandle();30 assertNotNull(windowHandle);31 Point windowPosition = driver.manage().window().getPosition();32 assertNotNull(windowPosition);33 }34 @Test35 public void test() throws Exception {36 driver.manage().window().maximize();37 String title = driver.getTitle();38 assertEquals("Untitled - Notepad", title);39 WebElement textField = driver.findElement(By.xpath("//TextField")); // find40 // element41 Rectangle rect = textField.getRect();42 assertNotNull(rect);43 textField.clear();44 assertEquals("", textField.getText());45 assertEquals("com.borland.silktest.jtf.TextField", textField.getTagName());46 WebElement window = driver.findElement(By.xpath("//Window"));47 assertEquals("com.borland.silktest.jtf.Window", window.getTagName());48 textField = window.findElement(By.xpath("//TextField")); // find element49 // from50 // element51 textField.sendKeys("hello");52 assertEquals("hello", textField.getText());53 textField.sendKeys(", world");54 assertEquals("hello, world", textField.getText());55 driver.manage().timeouts().implicitlyWait(42, TimeUnit.SECONDS);56 }57 @Test58 public void testGetAttribute() {59 WebElement textField = driver.findElement(By.xpath("//TextField"));60 textField.sendKeys("hello");61 // TODO: Currently (Selenium 3.6) getAttribute delegates to62 // executeJavaScript with a complex script which we can't support.63 64 String enabled = textField.getAttribute("Enabled");65 // assertEquals("true", enabled);66 // assertEquals("Consolas", textField.getAttribute("Font"));67 // assertEquals("false", textField.getAttribute("IsPassword"));68 // assertEquals("MultiLine", textField.getAttribute("true"));69 }70 71 @Test72 public void testScreenshotAPI () {73 driver.findElement(By.xpath("//TextField")).sendKeys("hello!");74 75 File file = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);76 assertTrue(file.length() > 0);77 }78 @Test79 public void testActionAPI() {80 WebElement textField = driver.findElement(By.xpath("//TextField"));81 textField.sendKeys("hello");82 83 Actions actions = new Actions(driver);84 actions.moveByOffset(100, 100).moveByOffset(10, 10).click().perform();85 }86 @After87 public void closeApp() {88 driver.close(); // Tries to close the window, will ask "do you want to89 // save..."90 WebElement dontSave = driver.findElement(By.xpath("//PushButton[@caption=\"Don't Save\"]"));91 dontSave.click();92 driver.quit();93 }94}...

Full Screen

Full Screen

Source:RoboDriverScreenshotTest.java Github

copy

Full Screen

1package io.test.automation.robodriver;2import static org.junit.Assert.assertEquals;3import static org.junit.Assert.assertTrue;4import java.awt.Color;5import java.awt.image.BufferedImage;6import java.io.File;7import java.io.IOException;8import javax.imageio.ImageIO;9import org.junit.AfterClass;10import org.junit.Before;11import org.junit.BeforeClass;12import org.junit.Test;13import org.openqa.selenium.OutputType;14import org.openqa.selenium.Point;15import org.openqa.selenium.Rectangle;16import org.openqa.selenium.WebElement;17import org.openqa.selenium.remote.DesiredCapabilities;18import org.openqa.selenium.remote.RemoteWebDriver;19import io.test.automation.robodriver.internal.RoboUtil;20public class RoboDriverScreenshotTest {21 private static Point casp; // click area screen position of left upper corner22 private static RemoteWebDriver browser;23 private static TestUtil util;24 25 private RoboDriver robo;26 @BeforeClass27 public static void onBeforeClass() throws IOException {28 util = new TestUtil();29 browser = util.startChrome();30 util.navigateToTestPage(browser);31 WebElement clickArea = browser.findElementById("clickarea");32 casp = new RoboDriverUtil().getScreenRectangleOfBrowserElement(clickArea).getPoint();33 }34 35 @AfterClass36 public static void onAfterClass() {37 if (browser != null) {38 browser.quit();39 util.stopServices();40 }41 }42 43 @Before44 public void onBeforeTest() throws IOException {45 DesiredCapabilities roboCapabilities = RoboDriver.getDesiredCapabilities();46 robo = new RoboDriver(roboCapabilities);47 }48 49 @Test50 public void testScreenshot() throws IOException {51 // when52 File screenshotFile = robo.getScreenshotAs(OutputType.FILE);53 54 // then55 BufferedImage screenshot = ImageIO.read(screenshotFile);56 Color color = new Color(screenshot.getRGB(casp.x + 100, casp.y + 100));57 assertEquals(0x00, color.getRed());58 assertEquals(0x00, color.getGreen());59 assertEquals(0xFF, color.getBlue());60 }61 62 @Test63 public void testScreenshotFromScreenX() throws IOException {64 WebElement screen = robo.findElementByXPath("/screen[@default=true]");65 66 // when67 File screenshotFile = screen.getScreenshotAs(OutputType.FILE);68 69 // then70 BufferedImage screenshot = ImageIO.read(screenshotFile);71 Color color = new Color(screenshot.getRGB(casp.x + 100, casp.y + 100));72 assertEquals(0x00, color.getRed());73 assertEquals(0x00, color.getGreen());74 assertEquals(0xFF, color.getBlue());75 }76 77 @Test78 public void testScreenshotRectangle() throws IOException {79 RoboDriverUtil roboUtil = new RoboDriverUtil();80 WebElement testImage = browser.findElementById("testimage");81 Rectangle rect = roboUtil.getScreenRectangleOfBrowserElement(testImage);82 WebElement screenRectElem = robo.findElementByXPath(83 String.format("//screen[@default=true]//rectangle[@dim='%d,%d,%d,%d']", 84 rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight()));85 86 // when87 File screenRectangleFile = screenRectElem.getScreenshotAs(OutputType.FILE);88 89 // then90 assertEqualsImage("test_image_1.png", screenRectangleFile);91 }92 private void assertEqualsImage(String expectedImage, File imageFile) throws IOException {93 File expectedImageFile = new File(this.getClass().getClassLoader().getResource(expectedImage).getFile());94 assertTrue(new RoboUtil().matchImages(expectedImageFile, imageFile));95 }96}...

Full Screen

Full Screen

Source:NullWebElement.java Github

copy

Full Screen

...25 return instance;26 }2728 public static boolean isNull(WebElement element) {29 return getNull().equals(element);30 }3132 @Override33 public void click() {34 }3536 @Override37 public void submit() {38 }3940 @Override41 public void sendKeys(CharSequence... charSequences) {42 }43 ...

Full Screen

Full Screen

equals

Using AI Code Generation

copy

Full Screen

1Rectangle rect1 = new Rectangle(10, 20, 30, 40);2Rectangle rect2 = new Rectangle(10, 20, 30, 40);3System.out.println("rect1.equals(rect2) = " + rect1.equals(rect2));4System.out.println("rect1.equals(rect1) = " + rect1.equals(rect1));5System.out.println("rect1.equals(null) = " + rect1.equals(null));6System.out.println("rect1.equals(\"rect2\") = " + rect1.equals("rect2"));7rect1.equals(rect2) = true8rect1.equals(rect1) = true9rect1.equals(null) = false10rect1.equals("rect2") = false

Full Screen

Full Screen

equals

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.Rectangle;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.chrome.ChromeDriver;4public class RectangleEquals {5 public static void main(String[] args) {6 WebDriver driver = new ChromeDriver();7 Rectangle rect1 = driver.manage().window().getRect();8 Rectangle rect2 = driver.manage().window().getRect();9 if (rect1.equals(rect2)) {10 System.out.println("The rectangles are equal");11 } else {12 System.out.println("The rectangles are not equal");13 }14 driver.quit();15 }16}17Example 2: Using equals() method of org.openqa.selenium.Dimension class18import org.openqa.selenium.Dimension;19import org.openqa.selenium.WebDriver;20import org.openqa.selenium.chrome.ChromeDriver;21public class DimensionEquals {22 public static void main(String[] args) {23 WebDriver driver = new ChromeDriver();24 Dimension dim1 = driver.manage().window().getSize();25 Dimension dim2 = driver.manage().window().getSize();26 if (dim1.equals(dim2)) {27 System.out.println("The dimensions are equal");28 } else {29 System.out.println("The dimensions are not equal");30 }31 driver.quit();32 }33}34Example 3: Using equals() method of org.openqa.selenium.Point class35import org.openqa.selenium.Point;36import org.openqa.selenium.WebDriver;37import org.openqa.selenium.chrome.ChromeDriver;38public class PointEquals {39 public static void main(String[] args) {40 WebDriver driver = new ChromeDriver();41 Point point1 = driver.manage().window().getPosition();42 Point point2 = driver.manage().window().getPosition();43 if (point1.equals(point2)) {44 System.out.println("The points are equal");45 } else {46 System.out.println("The points are not equal");47 }48 driver.quit();49 }50}51Example 4: Using equals() method of org.openqa.selenium.interactions.internal.Coordinates class52import org.openqa.selenium.WebDriver;53import org.openqa.selenium.chrome.ChromeDriver;54import org.openqa

Full Screen

Full Screen

equals

Using AI Code Generation

copy

Full Screen

1Rectangle r1 = new Rectangle(1, 1, 10, 10);2Rectangle r2 = new Rectangle(1, 1, 10, 10);3System.out.println(r1.equals(r2));4java.awt.Rectangle r3 = new java.awt.Rectangle(1, 1, 10, 10);5java.awt.Rectangle r4 = new java.awt.Rectangle(1, 1, 10, 10);6System.out.println(r3.equals(r4));7Point p1 = new Point(1, 1);8Point p2 = new Point(1, 1);9System.out.println(p1.equals(p2));10java.awt.Point p3 = new java.awt.Point(1, 1);11java.awt.Point p4 = new java.awt.Point(1, 1);12System.out.println(p3.equals(p4));

Full Screen

Full Screen

equals

Using AI Code Generation

copy

Full Screen

1Rectangle rect1 = new Rectangle(0,0,10,10);2Rectangle rect2 = new Rectangle(0,0,10,10);3assertTrue(rect1.equals(rect2));4Dimension dim1 = new Dimension(10,10);5Dimension dim2 = new Dimension(10,10);6assertTrue(dim1.equals(dim2));7Point p1 = new Point(10,10);8Point p2 = new Point(10,10);9assertTrue(p1.equals(p2));10WebDriverException ex1 = new WebDriverException("exception 1");11WebDriverException ex2 = new WebDriverException("exception 1");12assertTrue(ex1.equals(ex2));13WebDriverException ex1 = new WebDriverException("exception 1");14WebDriverException ex2 = new WebDriverException("exception 2");15assertFalse(ex1.equals(ex2));16WebDriverException ex1 = new WebDriverException("exception 1");17WebDriverException ex2 = new WebDriverException("exception 1");18ex1.addInfo("key1", "value1");19ex2.addInfo("key1", "value1");20assertTrue(ex1.equals(ex2));21WebDriverException ex1 = new WebDriverException("exception 1");22WebDriverException ex2 = new WebDriverException("exception 1");23ex1.addInfo("key1", "value1");24ex2.addInfo("key1", "value2");25assertFalse(ex1.equals(ex2));26WebDriverException ex1 = new WebDriverException("exception 1");27WebDriverException ex2 = new WebDriverException("exception 1");28ex1.addInfo("key1", "value1");29ex2.addInfo("key2", "value1");30assertFalse(ex1.equals(ex2));

Full Screen

Full Screen

equals

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.Rectangle;2import org.openqa.selenium.Point;3Rectangle rect = new Rectangle(new Point(10, 10), new Point(20, 20));4System.out.println("Rectangle is: " + rect);5Rectangle rect2 = new Rectangle(10, 10, 20, 20);6System.out.println("Rectangle is: " + rect2);7if (rect.equals(rect2)) {8 System.out.println("rect and rect2 are equal");9}10Rectangle is: (10,10) - (20,20)11Rectangle is: (10,10) - (20,20)12public class Rectangle {13 private final Point p1;14 private final Point p2;15 public Rectangle(Point p1, Point p2) {16 this.p1 = p1;17 this.p2 = p2;18 }19 public Rectangle(int x, int y, int width, int height) {20 this(new Point(x, y), new Point(x + width, y + height));21 }22 public Point getPoint() {23 return p1;24 }25 public int getX() {26 return p1.getX();27 }28 public int getY() {29 return p1.getY();30 }31 public int getHeight() {32 return p2.getY() - p1.getY();33 }34 public int getWidth() {35 return p2.getX() - p1.getX();36 }37 public Point getCenter() {38 return new Point(getX() + (getWidth() / 2), getY() + (getHeight() / 2));39 }40 public boolean contains(Point point) {41 return point.getX() >= getX() && point.getX() <= getX() + getWidth() &&42 point.getY() >= getY() && point.getY() <= getY() + getHeight();43 }44 public boolean contains(Rectangle other) {45 return contains(other.getPoint()) && contains(other.getPoint().moveBy(other.getWidth(), other.getHeight()));46 }47 public boolean equals(Object o) {48 if (this == o) return true;49 if (!(o instanceof Rectangle)) return false

Full Screen

Full Screen

Selenium 4 Tutorial:

LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.

Chapters:

  1. Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.

  2. What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.

  3. Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.

  4. Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.

  5. How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.

  6. Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.

  7. Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.

Selenium 101 certifications:

LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful