How to use PageFactory class of org.openqa.selenium.support package

Best Selenium code snippet using org.openqa.selenium.support.PageFactory

Source:BasePage.java Github

copy

Full Screen

...7import org.openqa.selenium.WebDriver;8import org.openqa.selenium.WebElement;9import org.openqa.selenium.interactions.Actions;10import org.openqa.selenium.support.FindBy;11import org.openqa.selenium.support.PageFactory;12import org.openqa.selenium.support.ui.ExpectedConditions;13import org.openqa.selenium.support.ui.WebDriverWait;14public class BasePage {15 /**16 * Менеджер страниц17 *18 * @see PageManager19 */20 protected PageManager appManager = PageManager.getPageManager();21 /**22 * Объект для имитации реального поведения мыши или клавиатуры23 *24 * @see Actions25 */26 protected Actions action = new Actions(DriverManager.getDriver());27 /**28 * Объект для выполнения любого js кода29 *30 * @see JavascriptExecutor31 */32 protected JavascriptExecutor js = (JavascriptExecutor) DriverManager.getDriver();33 /**34 * Объект явного ожидания35 * При применении будет ожидать задонного состояния 10 секунд с интервалом в 1 секунду36 *37 * @see WebDriverWait38 */39 protected WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), 10, 1000);40 /**41 * Конструктор позволяющий инициализировать все странички и их эелементы помеченные анотацией {@link FindBy}42 * Подробнее можно просмотреть в класс {@link org.openqa.selenium.support.PageFactory}43 *44 * @see FindBy45 * @see PageFactory46 * @see PageFactory#initElements(WebDriver, Object)47 */48 public BasePage() {49 PageFactory.initElements(DriverManager.getDriver(), this);50 }51 /**52 * Функция позволяющая скролить до любого элемента с помощью js53 *54 * @param element - веб-элемент странички55 * @see JavascriptExecutor56 */57 protected void scrollToElementJs(WebElement element) {58 js.executeScript("arguments[0].scrollIntoView(true);", element);59 }60 /**61 * Явное ожидание состояния кликабельности элемента62 *63 * @param element - веб-элемент который требует проверки на кликабельность...

Full Screen

Full Screen

Source:UIComponents.java Github

copy

Full Screen

...19import com.aconex.fieldautomation.pageobjects.mail.SendMail;20import org.openqa.selenium.WebDriver;21public class UIComponents {22 public static WebDriver driver = DriverFactory.driver;23 public static Login login = org.openqa.selenium.support.PageFactory.initElements(driver, Login.class);24 public static AddIssue addIssue = org.openqa.selenium.support.PageFactory.initElements(driver, AddIssue.class);25 public static AccessField accessField = org.openqa.selenium.support.PageFactory.initElements(driver, AccessField.class);26 public static Comments addComments = org.openqa.selenium.support.PageFactory.initElements(driver, Comments.class);27 public static PhotoUpload photoUpload = org.openqa.selenium.support.PageFactory.initElements(driver, PhotoUpload.class);28 public static AreaSelect selectArea = org.openqa.selenium.support.PageFactory.initElements(driver, AreaSelect.class);29 public static IssuesSearch issuesSearch = org.openqa.selenium.support.PageFactory.initElements(driver, IssuesSearch.class);30 public static StatusChange statusChange = org.openqa.selenium.support.PageFactory.initElements(driver, StatusChange.class);31 public static SelectInspection selectInspection = org.openqa.selenium.support.PageFactory.initElements(driver, SelectInspection.class);32 public static EnterSettings enterSettings = org.openqa.selenium.support.PageFactory.initElements(driver, EnterSettings.class);33 public static AccessSections accessSections = org.openqa.selenium.support.PageFactory.initElements(driver, AccessSections.class);34 public static CreateChecklist createChecklist = org.openqa.selenium.support.PageFactory.initElements(driver, CreateChecklist.class);35 public static YourOrganization yourOrg = org.openqa.selenium.support.PageFactory.initElements(driver, YourOrganization.class);36 public static StatusFilters issuesFilters = org.openqa.selenium.support.PageFactory.initElements(driver, StatusFilters.class);37 public static ExportInspections exportInspections = org.openqa.selenium.support.PageFactory.initElements(driver, ExportInspections.class);38 public static IssueAssignment issueAssignment = org.openqa.selenium.support.PageFactory.initElements(driver, IssueAssignment.class);39 public static AccessGridView accessGridView = org.openqa.selenium.support.PageFactory.initElements(driver, AccessGridView.class);40 public static Logout logout = org.openqa.selenium.support.PageFactory.initElements(driver, Logout.class);41 public static SwitchProject switchProject = org.openqa.selenium.support.PageFactory.initElements(driver, SwitchProject.class);42 public static ProjectFieldFilters projectFieldFilter = org.openqa.selenium.support.PageFactory.initElements(driver, ProjectFieldFilters.class);43 public static CustomField selectCustomField = org.openqa.selenium.support.PageFactory.initElements(driver, CustomField.class);44 public static Refresh refreshButton = org.openqa.selenium.support.PageFactory.initElements(driver, Refresh.class);45 public static EventLog checkEventLogValues = org.openqa.selenium.support.PageFactory.initElements(driver, EventLog.class);46 public static SendMail sendMail = org.openqa.selenium.support.PageFactory.initElements(driver, SendMail.class);47 public static ClearAllFilters clearAllFilter = org.openqa.selenium.support.PageFactory.initElements(driver, ClearAllFilters.class);48 public static IssuesGroupBy issuesGroupBy = org.openqa.selenium.support.PageFactory.initElements(driver, IssuesGroupBy.class);49 public static CollapseFilters filtercollapseicon = org.openqa.selenium.support.PageFactory.initElements(driver, CollapseFilters.class);50}...

Full Screen

Full Screen

Source:ElementFactory.java Github

copy

Full Screen

1package com.orasi.core.interfaces.impl.internal;2import java.lang.reflect.Constructor;3import java.lang.reflect.InvocationTargetException;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.support.PageFactory;6import org.openqa.selenium.support.pagefactory.FieldDecorator;7import com.orasi.exception.automation.PageInitialization;8import com.orasi.utils.OrasiDriver;9import com.orasi.utils.TestReporter;10/**11 * Element factory for wrapped elements. Similar to {@link org.openqa.selenium.support.PageFactory}12 */13public class ElementFactory {14 /**15 * See {@link org.openqa.selenium.support.PageFactory#initElements(org.openqa.selenium.WebDriver driver, Class)}16 */17 public static <T> T initElements(OrasiDriver driver, Class<T> pageClassToProxy) {18 TestReporter.logTrace("Entering ElementFactory#initElements");19 TestReporter.logTrace("Creating Page Object");20 T page = instantiatePage(driver, pageClassToProxy);21 TestReporter.logTrace("Successfully created Page Object");22 final OrasiDriver driverRef = driver;23 TestReporter.logTrace("Initialize Page Elements");24 PageFactory.initElements(new ElementDecorator(new CustomElementLocatorFactory(driverRef)), page);25 TestReporter.logTrace("Successfully created Page Elements");26 TestReporter.logTrace("Exiting ElementFactory#initElements");27 return page;28 }29 /**30 * See {@link org.openqa.selenium.support.PageFactory#initElements(org.openqa.selenium.support.pagefactory.FieldDecorator, Object)}31 */32 public static void initElements(OrasiDriver driver, Object page) {33 TestReporter.logTrace("Entering ElementFactory#initElements");34 final OrasiDriver driverRef = driver;35 TestReporter.logTrace("Initialize Page Elements");36 PageFactory.initElements(new ElementDecorator(new CustomElementLocatorFactory(driverRef), driverRef), page);37 TestReporter.logTrace("Successfully created Page Elements");38 TestReporter.logTrace("Exiting ElementFactory#initElements");39 }40 /**41 * see {@link org.openqa.selenium.support.PageFactory#initElements(org.openqa.selenium.support.pagefactory.ElementLocatorFactory, Object)}42 */43 public static void initElements(CustomElementLocatorFactory factory, Object page) {44 TestReporter.logTrace("Entering ElementFactory#initElements");45 final CustomElementLocatorFactory factoryRef = factory;46 TestReporter.logTrace("Initialize Page Elements");47 PageFactory.initElements(new ElementDecorator(factoryRef), page);48 TestReporter.logTrace("Successfully created Page Elements");49 TestReporter.logTrace("Exiting ElementFactory#initElements");50 }51 /**52 * see {@link org.openqa.selenium.support.PageFactory#initElements(org.openqa.selenium.support.pagefactory.ElementLocatorFactory, Object)}53 */54 public static void initElements(FieldDecorator decorator, Object page) {55 TestReporter.logTrace("Entering ElementFactory#initElements");56 TestReporter.logTrace("Initialize Page Elements");57 PageFactory.initElements(decorator, page);58 TestReporter.logTrace("Successfully created Page Elements");59 TestReporter.logTrace("Exiting ElementFactory#initElements");60 }61 /**62 * Copy of {@link org.openqa.selenium.support.PageFactory#instantiatePage(org.openqa.selenium.WebDriver, Class)}63 */64 private static <T> T instantiatePage(WebDriver driver, Class<T> pageClassToProxy) {65 TestReporter.logTrace("Entering ElementFactory#instantiatePage");66 try {67 try {68 TestReporter.logTrace("Create Constructor of Page object");69 Constructor<T> constructor = pageClassToProxy.getConstructor(WebDriver.class);70 TestReporter.logTrace("Successfully created Constructor");71 TestReporter.logTrace("Create new instance of Page object");72 T instance = constructor.newInstance(driver);73 TestReporter.logTrace("Successfully created new Page instance");74 TestReporter.logTrace("Exiting ElementFactory#instantiatePage");75 return instance;76 } catch (NoSuchMethodException e) {...

Full Screen

Full Screen

Source:SmallTests.java Github

copy

Full Screen

...49 HowTest.class,50 LoadableComponentTest.class,51 LocatingElementHandlerTest.class,52 LocatingElementListHandlerTest.class,53 PageFactoryTest.class,54 SelectTest.class,55 QuotesTest.class,56 SlowLoadableComponentTest.class,57 ThreadGuardTest.class,58 WebDriverWaitTest.class59})60public class SmallTests {}...

Full Screen

Full Screen

Source:Homepage.java Github

copy

Full Screen

...3import java.util.concurrent.TimeUnit;4import org.openqa.selenium.By;5import org.openqa.selenium.WebElement;6import org.openqa.selenium.support.FindBy;7import org.openqa.selenium.support.PageFactory;8import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory;9import org.openqa.selenium.support.ui.ExpectedCondition;10import org.openqa.selenium.support.ui.ExpectedConditions;11import org.openqa.selenium.support.ui.WebDriverWait;12import com.rakesh.base.Page;13import com.rakesh.pages.locators.HomePageLocators;14public class Homepage extends Page {15 16 17 public HomePageLocators home;18 WebDriverWait wait = new WebDriverWait(driver, 30);19 20 public Homepage() {21 this.home = new HomePageLocators();22 AjaxElementLocatorFactory factory = new AjaxElementLocatorFactory(driver, 30);23 PageFactory.initElements(factory, this.home);24 }25 26 public Homepage goToFlights() {27 28 click(home.flights);29 return this;30 31 }32 33 public void goToHotels() {34 35 }36 37 public void goToBundleAndSave() {...

Full Screen

Full Screen

Source:LoginPage_PF.java Github

copy

Full Screen

2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.WebElement;4import org.openqa.selenium.support.CacheLookup;5import org.openqa.selenium.support.FindBy;6import org.openqa.selenium.support.PageFactory;7import org.openqa.selenium.support.pagefactory.AjaxElementLocator;8import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory;9public class LoginPage_PF {10 WebDriver d;11 12 @FindBy(id="name")13 //@CacheLookup // to store in memory dont use for ajax or where element keep on changing14 WebElement txt_username;15 16 @FindBy(id="password")17 WebElement txt_password;18 19 @FindBy(id="login")20 WebElement btn_login;21 22// @FindBy(id="logout")23// WebElement btn_logout;24 25 public LoginPage_PF(WebDriver d) {26 27 this.d=d;28 PageFactory.initElements(d, this);29 //or30 //PageFactory.initElements(d,LoginPage_PF.class);31 //for ajax element loading we can use32 //PageFactory.initElements(new AjaxElementLocatorFactory(d, 30),this);33 34 }35 36 public void enterUserName(String username) {37 txt_username.sendKeys(username);38 39 }40 41 public void enterPassword(String password) {42 txt_password.sendKeys(password);43 44 }45 46 public void clickOnLogin() {...

Full Screen

Full Screen

PageFactory

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.support.PageFactory;2import org.openqa.selenium.WebElement;3import org.openqa.selenium.By;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.chrome.ChromeDriver;6import org.openqa.selenium.support.ui.ExpectedConditions;7import org.openqa.selenium.support.ui.WebDriverWait;8import org.openqa.selenium.interactions.Actions;9import org.openqa.selenium.Keys;10import org.openqa.selenium.Alert;11import org.openqa.selenium.JavascriptExecutor;12import org.openqa.selenium.support.ui.Select;13import java.awt.Robot;14import java.awt.AWTException;15import java.awt.event.KeyEvent;16import java.util.concurrent.TimeUnit;17import org.openqa.selenium.Dimension;18import org.openqa.selenium.Point;19import org.openqa.selenium.TakesScreenshot;20import java.io.File;21import java.io.IOException;22import java.text.SimpleDateFormat;23import java.util.Date;24import java.util.Calendar;25import java.text.SimpleDateFormat;26import java.util.Date;27import java.util.Calendar;

Full Screen

Full Screen

PageFactory

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.support.PageFactory;2import org.openqa.selenium.support.ui.Page;3import org.openqa.selenium.support.ui.WebDriverWait;4import org.openqa.selenium.support.ui.ExpectedConditions;5import org.openqa.selenium.By;6import org.openqa.selenium.WebElement;7import org.openqa.selenium.WebDriver;8import org.openqa.selenium.chrome.ChromeDriver;9import org.openqa.selenium.chrome.ChromeOptions;10public class PageFactoryDemo {11 public static void main(String[] args) {12 System.setProperty("webdriver.chrome.driver", "C:\\Users\\sandeep\\Desktop\\selenium\\chromedriver.exe");13 ChromeOptions options = new ChromeOptions();14 options.addArguments("start-maximized");15 WebDriver driver = new ChromeDriver(options);16 PageFactoryDemo obj = new PageFactoryDemo();17 obj.testPageFactory(driver);18 }19 public void testPageFactory(WebDriver driver) {20 GooglePage page = PageFactory.initElements(driver, GooglePage.class);21 page.search("selenium webdriver");22 page.clickSearch();23 }

Full Screen

Full Screen

PageFactory

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.By;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.WebElement;4import org.openqa.selenium.support.FindBy;5import org.openqa.selenium.support.PageFactory;6public class PageFactoryDemo {7 WebDriver driver;8 public PageFactoryDemo(WebDriver driver){9 this.driver = driver;10 PageFactory.initElements(driver, this);11 }12 @FindBy(name="q")13 WebElement searchBox;14 @FindBy(name="btnK")15 WebElement searchButton;16 public void search(String text){17 searchBox.sendKeys(text);18 searchButton.click();19 }20}21import org.openqa.selenium.By;22import org.openqa.selenium.WebDriver;23import org.openqa.selenium.WebElement;24import org.openqa.selenium.support.FindBy;25import org.openqa.selenium.support.PageFactory;26public class PageFactoryDemo {27 WebDriver driver;28 public PageFactoryDemo(WebDriver driver){29 this.driver = driver;30 PageFactory.initElements(driver, this);31 }32 @FindBy(name="q")33 WebElement searchBox;34 @FindBy(name="btnK")35 WebElement searchButton;36 public void search(String text){37 searchBox.sendKeys(text);38 searchButton.click();39 }40}41import org.openqa.selenium.By;42import org.openqa.selenium.WebDriver;43import org.openqa.selenium.WebElement;44import org.openqa.selenium.support.FindBy;45import org.openqa.selenium.support.PageFactory;46public class PageFactoryDemo {47 WebDriver driver;48 public PageFactoryDemo(WebDriver driver){49 this.driver = driver;50 PageFactory.initElements(driver, this);51 }52 @FindBy(name="q")53 WebElement searchBox;54 @FindBy(name="btnK")55 WebElement searchButton;56 public void search(String text){57 searchBox.sendKeys(text);58 searchButton.click();59 }60}61import org.openqa.selenium.By;62import org.openqa.selenium.WebDriver;63import org.openqa.selenium.WebElement;64import org.openqa.selenium.support.FindBy;65import org.openqa.selenium.support.PageFactory;66public class PageFactoryDemo {67 WebDriver driver;

Full Screen

Full Screen

PageFactory

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.WebDriver;2import org.openqa.selenium.WebElement;3import org.openqa.selenium.support.FindBy;4import org.openqa.selenium.support.PageFactory;5public class PageFactoryClass {6 private WebDriver driver;7 @FindBy(id = "search_query_top")8 private WebElement searchBox;9 @FindBy(name = "submit_search")10 private WebElement searchButton;11 public PageFactoryClass(WebDriver driver) {12 this.driver = driver;13 PageFactory.initElements(driver, this);14 }15 public void search(String text) {16 searchBox.sendKeys(text);17 searchButton.click();18 }19}

Full Screen

Full Screen

PageFactory

Using AI Code Generation

copy

Full Screen

1package com.seleniumeasy.tests;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.WebElement;4import org.openqa.selenium.support.FindBy;5import org.openqa.selenium.support.PageFactory;6public class PageFactoryDemo {7 @FindBy(name = "q") 8 WebElement searchBox;9 WebElement searchButton;10 public PageFactoryDemo(WebDriver driver) {11 PageFactory.initElements(driver, this);12 }13 public void searchFor(String text) {14 searchBox.sendKeys(text);15 searchButton.click();16 }17}18package com.seleniumeasy.tests;19import org.openqa.selenium.WebDriver;20import org.openqa.selenium.WebElement;21import org.openqa.selenium.support.FindBy;22import org.openqa.selenium.support.PageFactory;23public class PageFactoryDemo {24 @FindBy(name = "q") 25 WebElement searchBox;26 WebElement searchButton;27 public PageFactoryDemo(WebDriver driver) {28 PageFactory.initElements(driver, this);29 }30 public void searchFor(String text) {31 searchBox.sendKeys(text);32 searchButton.click();33 }34}35package com.seleniumeasy.tests;36import org.openqa.selenium.WebDriver;37import org.openqa.selenium.WebElement;38import org.openqa.selenium.support.FindBy;39import org.openqa.selenium.support.PageFactory;40public class PageFactoryDemo {41 @FindBy(name = "q") 42 WebElement searchBox;43 WebElement searchButton;

Full Screen

Full Screen

PageFactory

Using AI Code Generation

copy

Full Screen

1PageFactory.initElements(driver, Class)2PageFactory.initElements(driver, Class, parent)3PageFactory.initElements(new AppiumFieldDecorator(driver), this)4PageFactory.initElements(new AppiumFieldDecorator(driver, 10, TimeUnit.SECONDS), this)5PageFactory.initElements(new AppiumFieldDecorator(driver, 10, TimeUnit.SECONDS, this), this)6PageFactory.initElements(new AppiumFieldDecorator(driver, 10, TimeUnit.SECONDS, this, true), this)7PageFactory.initElements(new AppiumFieldDecorator(driver, 10, TimeUnit.SECONDS, this, true, true), this)8PageFactory.initElements(new AppiumFieldDecorator(driver, 10, TimeUnit.SECONDS, this, true, true, true), this)9PageFactory.initElements(new AppiumFieldDecorator(driver, 10, TimeUnit.SECONDS, this, true, true, true, true), this)10PageFactory.initElements(new AppiumFieldDecorator(driver, 10, TimeUnit.SECONDS, this, true, true, true, true, true), this)11PageFactory.initElements(new AppiumFieldDecorator(driver, 10, TimeUnit.SECONDS, this, true, true, true, true, true, true), this)12PageFactory.initElements(new AppiumFieldDecorator(driver, 10, TimeUnit.SECONDS, this, true, true, true, true, true, true, true), this)13PageFactory.initElements(new AppiumFieldDecorator(driver, 10, TimeUnit.SECONDS, this, true, true, true, true, true, true, true, true), this)14PageFactory.initElements(new AppiumFieldDecorator(driver, 10, TimeUnit.SECONDS, this, true, true, true, true, true, true, true, true, true), this)15PageFactory.initElements(new AppiumFieldDecorator(driver, 10, TimeUnit.SECONDS, this, true, true, true, true, true, true, true, true, true, true), this)16PageFactory.initElements(new AppiumFieldDecorator(driver, 10, TimeUnit.SECONDS, this, true, true, true, true, true, true, true,

Full Screen

Full Screen

PageFactory

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.support.PageFactory;2import org.openqa.selenium.support.FindBy;3import org.openqa.selenium.WebElement;4public class SearchPage {5 public SearchPage(WebDriver driver) {6 PageFactory.initElements(driver, this);7 }8 @FindBy(id = "search")9 private WebElement searchBox;10 @FindBy(className = "searchButton")11 private WebElement searchButton;12 @FindBy(className = "results")13 private WebElement searchResult;14 @FindBy(className = "result")15 private List<WebElement> searchResults;16 @FindBy(className = "result__title")17 private List<WebElement> searchResultTitles;18 @FindBy(className = "result__title__snippet")19 private List<WebElement> searchResultSnippets;20 @FindBy(className = "result__url")21 private List<WebElement> searchResultUrls;22 @FindBy(className = "result__extras__url")23 private List<WebElement> searchResultExtraUrls;24 @FindBy(className = "result__extras__item")25 private List<WebElement> searchResultExtraItems;26 @FindBy(className = "result__extras__item__date")27 private List<WebElement> searchResultExtraItemDates;28 @FindBy(className = "result__extras__item__source")29 private List<WebElement> searchResultExtraItemSources;30 @FindBy(className = "result__extras__item__author")31 private List<WebElement> searchResultExtraItemAuthors;32 @FindBy(className = "result__extras__item__source__url")33 private List<WebElement> searchResultExtraItemSourceUrls;34 @FindBy(className = "result__extras__

Full Screen

Full Screen
copy
1import java.awt.BasicStroke;2import java.awt.BorderLayout;3import java.awt.Color;4import java.awt.Dimension;5import java.awt.EventQueue;6import java.awt.Graphics;7import java.awt.Graphics2D;8import java.awt.Point;9import java.awt.RenderingHints;10import java.awt.event.ActionEvent;11import java.awt.event.KeyEvent;12import java.awt.event.MouseAdapter;13import java.awt.event.MouseEvent;14import javax.swing.AbstractAction;15import javax.swing.JButton;16import javax.swing.JFrame;17import javax.swing.JPanel;18import javax.swing.KeyStroke;1920/**21 * @see https://stackoverflow.com/questions/699164822 * @see https://stackoverflow.com/questions/688729623 * @see https://stackoverflow.com/questions/579796524 */25public class LinePanel extends JPanel {2627 private MouseHandler mouseHandler = new MouseHandler();28 private Point p1 = new Point(100, 100);29 private Point p2 = new Point(540, 380);30 private boolean drawing;3132 public LinePanel() {33 this.setPreferredSize(new Dimension(640, 480));34 this.addMouseListener(mouseHandler);35 this.addMouseMotionListener(mouseHandler);36 }3738 @Override39 protected void paintComponent(Graphics g) {40 super.paintComponent(g);41 Graphics2D g2d = (Graphics2D) g;42 g2d.setColor(Color.blue);43 g2d.setRenderingHint(44 RenderingHints.KEY_ANTIALIASING,45 RenderingHints.VALUE_ANTIALIAS_ON);46 g2d.setStroke(new BasicStroke(8,47 BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));48 g.drawLine(p1.x, p1.y, p2.x, p2.y);49 }5051 private class MouseHandler extends MouseAdapter {5253 @Override54 public void mousePressed(MouseEvent e) {55 drawing = true;56 p1 = e.getPoint();57 p2 = p1;58 repaint();59 }6061 @Override62 public void mouseReleased(MouseEvent e) {63 drawing = false;64 p2 = e.getPoint();65 repaint();66 }6768 @Override69 public void mouseDragged(MouseEvent e) {70 if (drawing) {71 p2 = e.getPoint();72 repaint();73 }74 }75 }7677 private class ControlPanel extends JPanel {7879 private static final int DELTA = 10;8081 public ControlPanel() {82 this.add(new MoveButton("\u2190", KeyEvent.VK_LEFT, -DELTA, 0));83 this.add(new MoveButton("\u2191", KeyEvent.VK_UP, 0, -DELTA));84 this.add(new MoveButton("\u2192", KeyEvent.VK_RIGHT, DELTA, 0));85 this.add(new MoveButton("\u2193", KeyEvent.VK_DOWN, 0, DELTA));86 }8788 private class MoveButton extends JButton {8990 KeyStroke k;91 int dx, dy;9293 public MoveButton(String name, int code, final int dx, final int dy) {94 super(name);95 this.k = KeyStroke.getKeyStroke(code, 0);96 this.dx = dx;97 this.dy = dy;98 this.setAction(new AbstractAction(this.getText()) {99100 @Override101 public void actionPerformed(ActionEvent e) {102 LinePanel.this.p1.translate(dx, dy);103 LinePanel.this.p2.translate(dx, dy);104 LinePanel.this.repaint();105 }106 });107 ControlPanel.this.getInputMap(108 WHEN_IN_FOCUSED_WINDOW).put(k, k.toString());109 ControlPanel.this.getActionMap().put(k.toString(), new AbstractAction() {110111 @Override112 public void actionPerformed(ActionEvent e) {113 MoveButton.this.doClick();114 }115 });116 }117 }118 }119120 private void display() {121 JFrame f = new JFrame("LinePanel");122 f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);123 f.add(this);124 f.add(new ControlPanel(), BorderLayout.SOUTH);125 f.pack();126 f.setLocationRelativeTo(null);127 f.setVisible(true);128 }129130 public static void main(String[] args) {131 EventQueue.invokeLater(new Runnable() {132133 @Override134 public void run() {135 new LinePanel().display();136 }137 });138 }139}140
Full Screen
copy
1import java.awt.*;2import java.awt.event.*;3import javax.swing.*;45public class TimerAnimation extends JLabel implements ActionListener6{7 int deltaX = 2;8 int deltaY = 3;9 int directionX = 1;10 int directionY = 1;1112 public TimerAnimation(13 int startX, int startY,14 int deltaX, int deltaY,15 int directionX, int directionY,16 int delay)17 {18 this.deltaX = deltaX;19 this.deltaY = deltaY;20 this.directionX = directionX;21 this.directionY = directionY;2223 setIcon( new ImageIcon("dukewavered.gif") );24// setIcon( new ImageIcon("copy16.gif") );25 setSize( getPreferredSize() );26 setLocation(startX, startY);27 new javax.swing.Timer(delay, this).start();28 }2930 public void actionPerformed(ActionEvent e)31 {32 Container parent = getParent();3334 // Determine next X position3536 int nextX = getLocation().x + (deltaX * directionX);3738 if (nextX < 0)39 {40 nextX = 0;41 directionX *= -1;42 }4344 if ( nextX + getSize().width > parent.getSize().width)45 {46 nextX = parent.getSize().width - getSize().width;47 directionX *= -1;48 }4950 // Determine next Y position5152 int nextY = getLocation().y + (deltaY * directionY);5354 if (nextY < 0)55 {56 nextY = 0;57 directionY *= -1;58 }5960 if ( nextY + getSize().height > parent.getSize().height)61 {62 nextY = parent.getSize().height - getSize().height;63 directionY *= -1;64 }6566 // Move the label6768 setLocation(nextX, nextY);69 }7071 public static void main(String[] args)72 {73 JPanel panel = new JPanel();74 JFrame frame = new JFrame();7576 frame.setContentPane(panel);77 frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );78 frame.getContentPane().setLayout(null);79// frame.getContentPane().add( new TimerAnimation(10, 10, 2, 3, 1, 1, 10) );80 frame.getContentPane().add( new TimerAnimation(300, 100, 3, 2, -1, 1, 20) );81// frame.getContentPane().add( new TimerAnimation(0, 000, 5, 0, 1, 1, 20) );82 frame.getContentPane().add( new TimerAnimation(0, 200, 5, 0, 1, 1, 80) );83 frame.setSize(400, 400);84 frame.setLocationRelativeTo( null );85 frame.setVisible(true);86// frame.getContentPane().add( new TimerAnimation(10, 10, 2, 3, 1, 1, 10) );87// frame.getContentPane().add( new TimerAnimation(10, 10, 3, 0, 1, 1, 10) );88 }89}90
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.

Most used methods in PageFactory

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful