How to use Enum Colors class of org.openqa.selenium.support package

Best Selenium code snippet using org.openqa.selenium.support.Enum Colors

Source:LocatorExamplesTests.java Github

copy

Full Screen

1package selenium_testing.locators;2import io.github.bonigarcia.wdm.WebDriverManager;3import org.junit.jupiter.api.*;4import org.openqa.selenium.*;5import org.openqa.selenium.chrome.ChromeDriver;6import org.openqa.selenium.support.ByIdOrName;7import org.openqa.selenium.support.Color;8import org.openqa.selenium.support.Colors;9import org.openqa.selenium.support.events.AbstractWebDriverEventListener;10import org.openqa.selenium.support.events.EventFiringWebDriver;11import org.openqa.selenium.support.pagefactory.ByAll;12import org.openqa.selenium.support.pagefactory.ByChained;13import org.openqa.selenium.support.ui.*;14import java.util.List;15public class LocatorExamplesTests {16 private WebDriver driver;17 @BeforeEach18 public void createDriver() {19 WebDriverManager.chromedriver().setup();20 driver = new ChromeDriver();21 driver.get("https://eviltester.github.io/supportclasses/");22 }23 // The select class makes it easy to work with Select options24 // rather than finding the select menu and then all the options25 // below it - this is the only Element Abstraction in the26 // support classes27 @Test28 public void canSelectAnOptionUsingSelect(){29 final WebElement selectMenu = driver.findElement(By.id("select-menu"));30 final Select select = new Select(selectMenu);31 select.selectByVisibleText("Option 3");32 Assertions.assertEquals("3",33 select.getFirstSelectedOption().34 getAttribute("value"));35 }36 @Test37 public void findInstructionsByIdOrName(){38 // findElement returns the element with the id if it exists, and if not searches for it via the name39 final WebElement instructionsPara = driver.findElement(40 new ByIdOrName("instruction-text"));41 final List<WebElement> instructionsParaAgain = driver.findElements(42 new ByIdOrName("instructions"));43 Assertions.assertEquals(instructionsPara.getText(),44 instructionsParaAgain.get(0).getText());45 }46 @Test47 public void quotesEscapingToCreateXPath(){48 Assertions.assertEquals("\"literal\"",49 Quotes.escape("literal"));50 Assertions.assertEquals("\"'single-quoted'\"",51 Quotes.escape("'single-quoted'"));52 Assertions.assertEquals("'\"double-quoted\"'",53 Quotes.escape("\"double-quoted\""));54 Assertions.assertEquals("concat(\"\", '\"', \"quot'end\", '\"')",55 Quotes.escape("\"quot'end\""));56 Assertions.assertEquals("concat(\"'quo\", '\"', \"ted'\")",57 Quotes.escape("'quo\"ted'"));58 }59 @Test60 public void checkColors(){61 final WebElement title = driver.findElement(By.id("instruction-title"));62 // Colors is an enum of named Color objects63 final Color blackValue = Colors.BLACK.getColorValue();64 // Color has methods to help convert between RBG, HEX65 Assertions.assertEquals("#000000",blackValue.asHex());66 Assertions.assertEquals("rgba(0, 0, 0, 1)",blackValue.asRgba());67 Assertions.assertEquals("rgb(0, 0, 0)",blackValue.asRgb());68 // color values returned by WebElement's getCSSValue are always69 // RGBA format, not the HTML source HEX or RGB70 Assertions.assertEquals(title.getCssValue("background-color"),71 blackValue.asRgba());72 // can create custom colors using the RGB input constructor73 // if the Colors enum does not have what we need74 final Color redValue = new Color(255,0,0, 1);75 Assertions.assertEquals(title.getCssValue("color"), redValue.asRgba());76 }77 @Test78 public void waitForMessage() {79 final WebElement selectMenu = driver.findElement(By.id("select-menu"));80 final Select select = new Select(selectMenu);81 select.selectByVisibleText("Option 2");82 // We are so used to using WebDriverWait and the ExpectedConditions class83 // that we might not have realised these are part of the support packages84 new WebDriverWait(driver, 10).until(85 ExpectedConditions.textToBe(By.id("message"), "Received message: selected 2"));86 }87 @Test88 public void canGetInfoAboutSelect(){89 final WebElement selectMenu = driver.findElement(By.id("select-menu"));90 final Select select = new Select(selectMenu);91 // the isMultiple method should be false for the select-menu item92 final WebElement multiSelectMenu = driver.findElement(By.id("select-multi"));93 final Select multiSelect = new Select(multiSelectMenu);94 // the isMultiple method should be true for multi select95 Assertions.assertFalse(select.isMultiple());96 Assertions.assertTrue(multiSelect.isMultiple());97 }98 @Test99 public void canGetAllOptionsFromSelect(){100 final WebElement selectMenu = driver.findElement(By.id("select-menu"));101 final Select select = new Select(selectMenu);102 // getOptions will return a List of WebElement103 // and allow me to access the options using104 // simple List methods105 List<WebElement> options = select.getOptions();106 Assertions.assertEquals(4,options.size());107 Assertions.assertEquals("Option 1", options.get(0).getText());108 }109 @Test110 public void canSelectSingleOptions(){111 // demo test to show single-select capabilities112 final WebElement selectMenu = driver.findElement(By.id("select-menu"));113 final Select select = new Select(selectMenu);114 // select will do nothing because this option is selected by default115 select.selectByIndex(0);116 Assertions.assertEquals("Option 1", select.getFirstSelectedOption().getText());117 // I can select the second item by Index 1 to chooose Option 2118 select.selectByIndex(1);119 Assertions.assertEquals("Option 2", select.getFirstSelectedOption().getText());120 // I can select the first by using the value "1"121 select.selectByValue("1");122 Assertions.assertEquals("Option 1", select.getFirstSelectedOption().getText());123 // and I can select using the text in the option124 select.selectByVisibleText("Option 3");125 Assertions.assertEquals("3", select.getFirstSelectedOption().getAttribute("value"));126 }127 @Test128 public void canSelectAndDeselectMultiOptions(){129 // demo test to show multi-select capabilities130 final WebElement selectMenu = driver.findElement(By.id("select-multi"));131 final Select select = new Select(selectMenu);132 // make sure nothing is selected with deselectAll133 select.deselectAll();134 // A normal select by index to get the First item135 select.selectByIndex(0);136 Assertions.assertEquals("First", select.getFirstSelectedOption().getText());137 // if I select I can deselect - by index, text or value138 select.deselectByIndex(0);139 // when nothing is selected a NoSuchElementException is thrown140 Assertions.assertThrows(NoSuchElementException.class, () -> {141 select.getFirstSelectedOption(); });142 // select two items - values 20 and 30143 select.selectByValue("20");144 select.selectByValue("30");145 // use getAllSelectedOptions, there should be 2 in the list146 final List<WebElement> selected = select.getAllSelectedOptions();147 Assertions.assertEquals(2, selected.size());148 // assert on the getText for the list entries149 Assertions.assertEquals("Second", selected.get(0).getText());150 Assertions.assertEquals("Third", selected.get(1).getText());151 // deselect the first one - assert visible text "Second"152 select.deselectByVisibleText("Second");153 // and assert that the first selected option text is "Third"154 Assertions.assertEquals("Third", select.getFirstSelectedOption().getText());155 // deselect them all to finish156 select.deselectAll();157 Assertions.assertEquals(0, select.getAllSelectedOptions().size());158 Assertions.assertEquals(selectMenu, select.getWrappedElement());159 }160 //@Disabled("To be enabled if run independently")161 @Test162 public void canClickAButton(){163 final WebElement buttonElement = driver.findElement(By.id("resend-select"));164 Button button = new Button(buttonElement);165 // rather than click on a button element,166 // could we click on a Button?167 Assertions.assertEquals("Resend Single Option Message",168 button.getText());169 button.click();170 new WebDriverWait(driver, 10).171 until(ExpectedConditions.textToBe(By.id("message"),172 "Received message: selected 1"));173 }174 @Test175 public void byIdOrName(){176 WebElement idButton = driver.findElement(By.id("resend-select"));177 Assertions.assertEquals("Resend Single Option Message",178 idButton.getText());179 WebElement namedButton = driver.findElement(By.name("resend-select"));180 Assertions.assertEquals("Resend Multi Option Message",181 namedButton.getText());182 // ByIdOrName can match by id, and if that doesn't match treat it as a name183 // use ByIdOrName to find a button element "resend-select"184 // and the assertions should pass185 WebElement button = driver.findElement(new ByIdOrName("resend-select"));186 Assertions.assertEquals(idButton, button);187 Assertions.assertNotEquals(namedButton, button);188 //ByIdOrName findElements returns all id and name matches189 //findElements for "resend-select" should find 2 buttons190 List<WebElement> buttons = driver.findElements(new ByIdOrName("resend-select"));191 Assertions.assertEquals(2, buttons.size());192 // the elements identified should be the same as we found initially193 Assertions.assertTrue(buttons.contains(idButton));194 Assertions.assertTrue(buttons.contains(namedButton));195 }196 @Test197 public void byAll(){198 // we could use ByAll to find by id or by name199 // by all is a collator, so given a number of locators, find all items that match200 final List<WebElement> buttons = driver.findElements(201 new ByAll(By.id("resend-select"),202 By.name("resend-select")));203 Assertions.assertEquals(2, buttons.size());204 Assertions.assertTrue(buttons.contains(driver.findElement(By.id("resend-select"))));205 Assertions.assertTrue(buttons.contains(driver.findElement(By.name("resend-select"))));206 }207 @Test208 public void byChained(){209 final WebElement resendSingle = driver.findElement(By.id("resend-select"));210 resendSingle.click();211 resendSingle.click();212 resendSingle.click();213 resendSingle.click();214 final WebElement resend = driver.findElement(By.id("resend-multi"));215 resend.click();216 resend.click();217 // TODO: make this more specific to only find messages under a 'list'218 final List<WebElement> allMessages = driver.findElements(219 new ByChained(By.name("list"),220 By.className("message")));221 Assertions.assertEquals(6, allMessages.size());222 // then just the #single list .message223 final List<WebElement> singleMessages = driver.findElements(224 new ByChained(By.id("single"),By.name("list"),225 By.className("message")));226 Assertions.assertEquals(4, singleMessages.size());227 // then the #multi list .message228 final List<WebElement> multiMessages = driver.findElements(229 new ByChained(By.id("multi"),By.name("list"),230 By.className("message")));231 Assertions.assertEquals(2, multiMessages.size());232 }233 @Test234 public void loggingFindingElements() {235 final By resend = By.id("resend-select");236 final By noSuchElement = By.id("no-such-element");237 EventFiringWebDriver events = new EventFiringWebDriver(driver);238 events.register(new LocalEventFiringListener());239 WebElement resendElem = events.findElement(resend);240 Assertions.assertNotNull(resendElem);241 Assertions.assertThrows(NoSuchElementException.class, () -> {242 events.findElement(noSuchElement);243 });244 }245 private class LocalEventFiringListener extends AbstractWebDriverEventListener {246 @Override247 public void beforeFindBy(By by, WebElement element, WebDriver driver) {248 System.out.println("Looking For " + by.toString());249 }250 @Override251 public void afterFindBy(By by, WebElement element, WebDriver driver) {252 System.out.println("Finished looking for " + by.toString());253 }254 }255 @AfterEach256 public void closeDriver() { driver.quit(); }257 private class Button implements WrapsElement {258 private final WebElement button;259 public Button(WebElement buttonElement) {260 this.button = buttonElement;261 }262 @Override263 public WebElement getWrappedElement() {264 return button;265 }266 public String getText() {267 return button.getText();268 }269 public void click() {270 button.click();271 }272 }273}...

Full Screen

Full Screen

Source:QuickWinsTest.java Github

copy

Full Screen

1package ch_01_02_quick_wins.end;2import io.github.bonigarcia.wdm.WebDriverManager;3import org.junit.jupiter.api.AfterAll;4import org.junit.jupiter.api.Assertions;5import org.junit.jupiter.api.BeforeAll;6import org.junit.jupiter.api.Test;7import org.openqa.selenium.By;8import org.openqa.selenium.JavascriptExecutor;9import org.openqa.selenium.WebDriver;10import org.openqa.selenium.WebElement;11import org.openqa.selenium.chrome.ChromeDriver;12import org.openqa.selenium.support.ByIdOrName;13import org.openqa.selenium.support.Color;14import org.openqa.selenium.support.Colors;15import org.openqa.selenium.support.ui.ExpectedConditions;16import org.openqa.selenium.support.ui.Quotes;17import org.openqa.selenium.support.ui.Select;18import org.openqa.selenium.support.ui.WebDriverWait;19import java.util.List;20public class QuickWinsTest {21/*22 This test contains code to demo:23 - Select, which is a WebElement Abstraction24 - a custom By Selector ByIdOrName25 - Quotes for creating XPath quoted locators26 - Colours for working with Colours27 */28 static WebDriver driver;29 @BeforeAll30 public static void createDriver(){31 WebDriverManager.chromedriver().setup();32 driver = new ChromeDriver();33 driver.get("https://eviltester.github.io/supportclasses/");34 }35 // The select class makes it easy to work with Select options36 // rather than finding the select menu and then all the options37 // below it - this is the only Element Abstraction in the38 // support classes39 @Test40 public void canSelectAnOptionUsingSelect(){41 final WebElement selectMenu = driver.findElement(By.id("select-menu"));42 final Select select = new Select(selectMenu);43 select.selectByVisibleText("Option 3");44 Assertions.assertEquals("3",45 select.getFirstSelectedOption().46 getAttribute("value"));47 }48 @Test49 public void findInstructionsByIdOrName(){50 // findElement returns the element with the id if it exists, and if not searches for it via the name51 final WebElement instructionsPara = driver.findElement(52 new ByIdOrName("instruction-text"));53 final List<WebElement> instructionsParaAgain = driver.findElements(54 new ByIdOrName("instructions"));55 Assertions.assertEquals(instructionsPara.getText(),56 instructionsParaAgain.get(0).getText());57 }58 @Test59 public void quotesEscapingToCreateXPath(){60 Assertions.assertEquals("\"literal\"",61 Quotes.escape("literal"));62 Assertions.assertEquals("\"'single-quoted'\"",63 Quotes.escape("'single-quoted'"));64 Assertions.assertEquals("'\"double-quoted\"'",65 Quotes.escape("\"double-quoted\""));66 Assertions.assertEquals("concat(\"\", '\"', \"quot'end\", '\"')",67 Quotes.escape("\"quot'end\""));68 Assertions.assertEquals("concat(\"'quo\", '\"', \"ted'\")",69 Quotes.escape("'quo\"ted'"));70 }71 @Test72 public void colors(){73 final WebElement title = driver.findElement(By.id("instruction-title"));74 // Colors is an enum of named Color objects75 final Color blackValue = Colors.BLACK.getColorValue();76 // Color has methods to help convert between RBG, HEX77 Assertions.assertEquals("#000000",blackValue.asHex());78 Assertions.assertEquals("rgba(0, 0, 0, 1)",blackValue.asRgba());79 Assertions.assertEquals("rgb(0, 0, 0)",blackValue.asRgb());80 // color values returned by WebElement's getCSSValue are always81 // RGBA format, not the HTML source HEX or RGB82 Assertions.assertEquals(title.getCssValue("background-color"),83 blackValue.asRgba());84 // can create custom colors using the RGB input constructor85 // if the Colors enum does not have what we need86 final Color redValue = new Color(255,0,0, 1);87 Assertions.assertEquals(title.getCssValue("color"), redValue.asRgba());88 }89 @Test90 public void waitForMessage() {91 final WebElement selectMenu = driver.findElement(By.id("select-menu"));92 final Select select = new Select(selectMenu);93 select.selectByVisibleText("Option 2");94 // We are so used to using WebDriverWait and the ExpectedConditions class95 // that we might not have realised these are part of the support packages96 new WebDriverWait(driver, 10).until(97 ExpectedConditions.textToBe(98 By.id("message"), "Received message: selected 2"));99 }100 @AfterAll101 public static void closeDriver(){102 driver.quit();103 }104}...

Full Screen

Full Screen

Source:BoardCreation.java Github

copy

Full Screen

1package org.example.trello.ui.pages.board;2import java.util.Collections;3import java.util.EnumMap;4import java.util.HashMap;5import java.util.Map;6import org.openqa.selenium.By;7import org.openqa.selenium.WebElement;8import org.openqa.selenium.support.FindBy;9import org.openqa.selenium.support.ui.ExpectedConditions;10import org.example.core.ui.AbstractPage;11import org.example.trello.ui.pages.common.ISteps;12/**13 * Page object of the Creation page for boards.14 */15public class BoardCreation extends AbstractPage {16 @FindBy(css = "input[data-test-id='create-board-title-input']")17 private WebElement titleTextInputField;18 @FindBy(css = "div[role='dialog'] button[data-test-id='create-board-submit-button']")19 private WebElement createBoardButton;20 @FindBy(css = "span[name='private']")21 private WebElement selectPrivacyButton;22 @FindBy(css = "input[data-test-id='create-board-title-input'] + button > span")23 private WebElement selectTeamButton;24 @FindBy(css = ".window-overlay .window")25 private WebElement windowOverlay;26 private String titleString;27 private String privacyString;28 private String backgroundString;29 private static final Map<String, String> COLORSBACKGROUND;30 static {31 Map<String, String> colors = new HashMap<>();32 colors.put("green", "rgba(81, 152, 57, 1)");33 colors.put("red", "rgba(176, 70, 50, 1)");34 colors.put("blue", "rgba(0, 121, 191, 1)");35 colors.put("orange", "rgba(210, 144, 52, 1)");36 colors.put("null", null);37 COLORSBACKGROUND = Collections.unmodifiableMap(colors);38 }39 /**40 * Method for create a board with some specs.41 *42 * @param data List of the data specs.43 * @return the PO of the Selected Board.44 */45 public SelectedBoard createNewBoard(final Map<BoardFields, String> data) {46 action.pause();47 EnumMap<BoardFields, ISteps> boardSteps = new EnumMap<>(BoardFields.class);48 titleString = data.get(BoardFields.TITLE);49 action.waitVisibility(titleTextInputField);50 boardSteps.put(BoardFields.TITLE, () -> action.setValue(titleTextInputField, titleString));51 boardSteps.put(BoardFields.PRIVACY, () -> selectPrivacy(data));52 boardSteps.put(BoardFields.BACKGROUND, () -> selectBackground(data));53 for (BoardFields key : data.keySet()) {54 boardSteps.get(key).run();55 }56 action.click(createBoardButton);57 wait.until(ExpectedConditions.invisibilityOf(windowOverlay));58 return new SelectedBoard();59 }60 /**61 * Method for select a Background.62 *63 * @param data input map.64 */65 private void selectBackground(final Map<BoardFields, String> data) {66 backgroundString = data.get(BoardFields.BACKGROUND);67 final String locatorColorBackgroundButton = String.format("div[role='dialog'] li button[title='%s']",68 backgroundString);69 By colorBgButton = By.cssSelector(locatorColorBackgroundButton);70 action.waitVisibility(colorBgButton);71 action.click(colorBgButton);72 }73 /**74 * Method for select Privacy .75 *76 * @param data input map.77 */78 private void selectPrivacy(final Map<BoardFields, String> data) {79 privacyString = data.get(BoardFields.PRIVACY).toLowerCase();80 if (privacyString.equals("public")) {81 action.click(selectPrivacyButton);82 String privacyButtonString = String.format("[class$='icon-%s']", privacyString);83 By privacyButtonLocator = By.cssSelector(privacyButtonString);84 action.waitVisibility(privacyButtonLocator);85 action.click(privacyButtonLocator);86 By confirmPublicButtonLocator = By.cssSelector("[class='js-confirm full primary']");87 action.waitVisibility(confirmPublicButtonLocator);88 action.click(confirmPublicButtonLocator);89 }90 }91 /**92 * @return title of board created.93 */94 public String getTitleString() {95 return titleString;96 }97 /**98 * @return privacy of board created.99 */100 public String getPrivacyString() {101 return privacyString;102 }103 /**104 * @return background of board created.105 */106 public String getBackgroundString() {107 return COLORSBACKGROUND.get(backgroundString == null ? "null" : backgroundString.toLowerCase());108 }109}...

Full Screen

Full Screen

Source:BoardCreationPage.java Github

copy

Full Screen

1package org.fundacionjala.trello.pages.board;2import org.fundacionjala.core.ui.AbstractPage;3import org.fundacionjala.trello.pages.card.BoardPage;4import org.fundacionjala.core.ui.ISteps;5import org.openqa.selenium.By;6import org.openqa.selenium.WebElement;7import org.openqa.selenium.support.FindBy;8import org.openqa.selenium.support.ui.ExpectedConditions;9import java.util.Collections;10import java.util.EnumMap;11import java.util.HashMap;12import java.util.Map;13public class BoardCreationPage extends AbstractPage {14 private String titleString;15 private String privacyString;16 private String backgroundString;17 private static final Map<String, String> BACKGROUNDCOLORS;18 static {19 Map<String, String> backgroundColors = new HashMap<>();20 backgroundColors.put("blue", "rgb(0, 121, 191)");21 backgroundColors.put("orange", "rgb(210, 144, 52)");22 backgroundColors.put("green", "rgb(81, 152, 57)");23 backgroundColors.put("red", "rgb(176, 70, 50)");24 backgroundColors.put("null", "null");25 BACKGROUNDCOLORS = Collections.unmodifiableMap(backgroundColors);26 }27 @FindBy(css = "input[data-test-id='create-board-title-input']")28 private WebElement addBoardTitle;29 @FindBy(css = "button[data-test-id='create-board-submit-button']")30 private WebElement createBoardButton;31 //Privacy32 @FindBy(css = "button[class='subtle-chooser-trigger unstyled-button vis-chooser-trigger']")33 private WebElement selectPrivacyButton;34 @FindBy(css = "input[class='js-confirm full primary']")35 private WebElement confirmPublicButton;36 public String getTitleString() {37 return titleString;38 }39 public String getPrivacyString() {40 return privacyString;41 }42 public String getBackgroundString() {43 return "background-color: " + BACKGROUNDCOLORS.get(backgroundString == null44 ? "null" : backgroundString.toLowerCase()) + ";";45 }46 public BoardPage createNewBoard(final Map<BoardFields, String> inputData) {47 EnumMap<BoardFields, ISteps> enumMap = new EnumMap<>(BoardFields.class);48 titleString = inputData.get(BoardFields.TITLE);49 webDriverWait.until(ExpectedConditions.visibilityOf(addBoardTitle));50 enumMap.put(BoardFields.TITLE, () -> addBoardTitle.sendKeys(titleString));51 enumMap.put(BoardFields.BACKGROUND, () -> selectBackground(inputData));52 enumMap.put(BoardFields.PRIVACY, () -> selectPrivacy(inputData));53 for (BoardFields key : inputData.keySet()) {54 enumMap.get(key).execute();55 }56 createBoardButton.click();57 return new BoardPage();58 }59 public void selectBackground(final Map<BoardFields, String> inputData) {60 backgroundString = inputData.get(BoardFields.BACKGROUND);61 final String locatorColorBackgroundButton = String.format("button[title='%s']",62 backgroundString);63 By colorBgButton = By.cssSelector(locatorColorBackgroundButton);64 webDriver.findElement(colorBgButton).click();65 }66 public void selectPrivacy(final Map<BoardFields, String> inputData) {67 privacyString = inputData.get(BoardFields.PRIVACY);68 if (privacyString.equals("public")) {69 webDriverWait.until(ExpectedConditions.visibilityOf(selectPrivacyButton));70 selectPrivacyButton.click();71 String privacyButtonString = String.format("[class$='%s']", privacyString);72 By privacyButtonLocator = By.cssSelector(privacyButtonString);73 webDriver.findElement(privacyButtonLocator).click();74 confirmPublicButton.click();75 }76 }77}...

Full Screen

Full Screen

Source:DiffElementsPage.java Github

copy

Full Screen

1package ru.training.at.hw4.pages;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.WebElement;4import org.openqa.selenium.support.FindBy;5import java.util.List;6public class DiffElementsPage extends CommonElementsOnPage {7 @FindBy(css = ".info-panel-body-log ul li")8 List<WebElement> logRows;9 @FindBy(css = ".checkbox-row input")10 List<WebElement> checkboxes;11 @FindBy(css = ".checkbox-row .label-radio ")12 List<WebElement> radiobuttons;13 @FindBy(className = "colors")14 WebElement dropdown;15 @FindBy(css = ".colors option")16 List<WebElement> colorsInDropdown;17 public enum ChooseRb {18 Gold, Silver, Bronze, Selen19 }20 public void chooseRadiobutton(ChooseRb rbName) {21 switch (rbName) {22 case Gold:23 radiobuttons.get(0).click();24 break;25 case Silver:26 radiobuttons.get(1).click();27 break;28 case Bronze:29 radiobuttons.get(2).click();30 break;31 case Selen:32 radiobuttons.get(3).click();33 break;34 default:35 System.out.println("There isn't that text on the page");36 }37 }38 public enum ChooseColor {39 Red, Green, Blue, Yellow40 }41 public void chooseColorInDropdown(ChooseColor colorName) {42 dropdown.click();43 switch (colorName) {44 case Red:45 colorsInDropdown.get(0).click();46 break;47 case Green:48 colorsInDropdown.get(1).click();49 break;50 case Blue:51 colorsInDropdown.get(2).click();52 break;53 case Yellow:54 colorsInDropdown.get(3).click();55 break;56 default:57 System.out.println("There isn't that text on the page");58 }59 }60 public enum ChooseCheckbox {61 Water, Wind, Earth, Fire62 }63 public void chooseChk(ChooseCheckbox box) {64 switch (box) {65 case Water:66 checkboxes.get(0).click();67 break;68 case Earth:69 checkboxes.get(1).click();70 break;71 case Wind:72 checkboxes.get(2).click();73 break;74 case Fire:75 checkboxes.get(3).click();76 break;77 default:78 System.out.println("There isn't that text on the page");79 break;80 }81 }82 public String getCuttedTextFromLog() {83 String[] splitRow = logRows.get(0).getText()84 .split("(\\d+):(\\d+):(\\d+) ");85 return splitRow[1];86 }87 public DiffElementsPage(WebDriver driver) {88 super(driver);89 }90}...

Full Screen

Full Screen

Source:EpamJDISite.java Github

copy

Full Screen

1package com.epam.jdi.uitests.testing.unittests.pageobjects;2import com.epam.jdi.uitests.testing.unittests.pageobjects.pages.*;3import com.epam.jdi.uitests.testing.unittests.pageobjects.sections.Footer;4import com.epam.jdi.uitests.testing.unittests.pageobjects.sections.Header;5import com.epam.jdi.uitests.web.selenium.elements.complex.TextList;6import com.epam.jdi.uitests.web.selenium.elements.composite.WebSite;7import com.epam.jdi.uitests.web.selenium.elements.pageobjects.annotations.JPage;8import com.epam.jdi.uitests.web.selenium.elements.pageobjects.annotations.JSite;9import org.openqa.selenium.support.FindBy;10/**11 * Created by Maksim_Palchevskii on 9/10/2015.12 */13@JSite(domain = "https://epam.github.io/JDI/")14public class EpamJDISite extends WebSite {15 @JPage(url = "/index.htm", title = "Index Page")16 public static HomePage homePage;17 @JPage(url = "/page1.htm", title = "Contact Form")18 public static ContactPage contactFormPage;19 @JPage(url = "/page2.htm", title = "Metal and Colors")20 public static MetalsColorsPage metalsColorsPage;21 @JPage(url = "/page3.htm", title = "Support")22 public static SupportPage supportPage;23 @JPage(url = "/page3.htm", title = "Support")24 public static SortingTablePage sortingTablePage;25 @JPage(url = "/page7.htm", title = "Table sort")26 public static DynamicTablePage dynamicTablePage;27 @JPage(url = "/page5.htm", title = "Table Scroll")28 public static SimpleTablePage simpleTablePage;29 @JPage(url = "/page6.htm", title = "Simple Table")30 public static DatesPage dates;31 @FindBy(css = ".uui-profile-menu")32 public static Login login;33 @FindBy(css = ".uui-header")34 public static Header header;35 @FindBy(css = ".footer-content")36 public static Footer footer;37 @FindBy(css = ".logs li")38 public static TextList<Enum> actionsLog;39 @FindBy(css = ".results")40 public static TextList<Enum> resultsLog;41}...

Full Screen

Full Screen

Source:DifferentElementPage.java Github

copy

Full Screen

1package com.marizueva.laboratory.hw5.pages;2import org.openqa.selenium.NotFoundException;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.WebElement;5import org.openqa.selenium.support.FindBy;6import java.util.List;7public class DifferentElementPage extends BasePage {8 public DifferentElementPage(WebDriver driver) {9 super(driver);10 }11 @FindBy(css = "input[type='checkbox']")12 List<WebElement> checkBoxes;13 @FindBy(css = "div.checkbox-row > label.label-radio:nth-child(4)")14 private WebElement radioSelen;15 @FindBy(css = "div.colors>.uui-form-element")16 private WebElement openColorDropdown;17 @FindBy(xpath = "//div[@class='colors']/select/option[text()='Yellow']")18 private WebElement dropdownYellow;19 @FindBy(css = "ul.logs>li")20 private List<WebElement> allLogs;21 public void clickCheckbox(String checkbox) {22 Checkboxes checkboxEnum = null;23 switch (checkbox) {24 case "Water":25 checkboxEnum = Checkboxes.WATER;26 break;27 case "Wind":28 checkboxEnum = Checkboxes.WIND;29 break;30 case "Fire":31 checkboxEnum = Checkboxes.FIRE;32 break;33 case "Earth":34 checkboxEnum = Checkboxes.EARTH;35 break;36 default: throw new NotFoundException("item " + checkbox + " not found");37 }38 checkBoxes.get(checkboxEnum.getIndex()).click();39 }40 public void chooseRadioSelen() {41 radioSelen.click();42 }43 public void chooseYellowDropdown() {44 openColorDropdown.click();45 dropdownYellow.click();46 }47 public List<WebElement> getAllLogs() {48 return allLogs;49 }50}...

Full Screen

Full Screen

Source:Colors.java Github

copy

Full Screen

1package org.openqa.selenium.support;2// Basic colour keywords as defined by the W3C HTML4 spec3// See http://www.w3.org/TR/css3-color/#html44import org.openqa.selenium.support.Color;5public enum Colors {6 BLACK(new Color(0, 0, 0, 1d)),7 SILVER(new Color(192, 192, 192, 1d)),8 GRAY(new Color(128, 128, 128, 1d)),9 WHITE(new Color(255, 255, 255, 1d)),10 MAROON(new Color(128, 0, 0, 1d)),11 RED(new Color(255, 0, 0, 1d)),12 PURPLE(new Color(128, 0, 128, 1d)),13 FUCHSIA(new Color(255, 0, 255, 1d)),14 GREEN(new Color(0, 128, 0, 1d)),15 LIME(new Color(0, 255, 0, 1d)),16 OLIVE(new Color(128, 128, 0, 1d)),17 YELLOW(new Color(255, 255, 0, 1d)),18 NAVY(new Color(0, 0, 128, 1d)),19 BLUE(new Color(0, 0, 255, 1d)),20 TEAL(new Color(0, 128, 128, 1d)),21 AQUA(new Color(0, 255, 255, 1d));22 private final Color colorValue;23 private Colors(Color colorValue) {24 this.colorValue = colorValue;25 }26 public Color getColorValue() {27 return this.colorValue;28 }29}...

Full Screen

Full Screen

Enum Colors

Using AI Code Generation

copy

Full Screen

1package org.openqa.selenium.support;2public enum Colors {3 AQUA("Aqua"), BLACK("Black"), BLUE("Blue"), FUCHSIA("Fuchsia"), GRAY("Gray"), GREEN("Green"),4 LIME("Lime"), MAROON("Maroon"), NAVY("Navy"), OLIVE("Olive"), PURPLE("Purple"), RED("Red"),5 SILVER("Silver"), TEAL("Teal"), WHITE("White"), YELLOW("Yellow");6 private String colorName;7 private Colors(String colorName) {8 this.colorName = colorName;9 }10 public String getColorName() {11 return colorName;12 }13 public String toString() {14 return getColorName();15 }16}17package org.openqa.selenium.support;18import java.util.List;19import org.openqa.selenium.By;20import org.openqa.selenium.WebDriver;21import org.openqa.selenium.WebElement;22import org.openqa.selenium.chrome.ChromeDriver;23import org.openqa.selenium.support.Colors;24import org.testng.Assert;25import org.testng.annotations.AfterTest;26import org.testng.annotations.BeforeTest;27import org.testng.annotations.Test;28public class ColorsTest {29 private WebDriver driver;30 private String baseUrl;31 private StringBuffer verificationErrors = new StringBuffer();32 public void setUp() throws Exception {33 System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");34 driver = new ChromeDriver();35 }36 public void testColors() throws Exception {37 driver.get(baseUrl + "/?gws_rd=ssl");38 driver.findElement(By.id("lst-ib")).clear();39 driver.findElement(By.id("lst-ib")).sendKeys("Selenium");40 List<WebElement> links = driver.findElements(By.tagName("a"));41 for (WebElement link : links) {42 System.out.println("Text: " + link.getText() + " and Color: " + link.getCssValue("color"));43 }44 String color = links.get(0).getCssValue("color");45 String convertedColor = Color.fromString(color).asHex();

Full Screen

Full Screen

Enum Colors

Using AI Code Generation

copy

Full Screen

1package org.openqa.selenium.support;2import java.util.Map;3import java.util.HashMap;4public enum Colors {5 AQUA("aqua", 0x00FFFF),6 BLACK("black", 0x000000),7 BLUE("blue", 0x0000FF),8 FUCHSIA("fuchsia", 0xFF00FF),9 GRAY("gray", 0x808080),10 GREEN("green", 0x008000),11 LIME("lime", 0x00FF00),12 MAROON("maroon", 0x800000),13 NAVY("navy", 0x000080),14 OLIVE("olive", 0x808000),15 PURPLE("purple", 0x800080),16 RED("red", 0xFF0000),17 SILVER("silver", 0xC0C0C0),18 TEAL("teal", 0x008080),19 WHITE("white", 0xFFFFFF),20 YELLOW("yellow", 0xFFFF00);21 private String colorName;22 private int colorCode;23 private Colors(String colorName, int colorCode) {24 this.colorName = colorName;25 this.colorCode = colorCode;26 }27 public String getColorName() {28 return this.colorName;29 }30 public int getColorCode() {31 return this.colorCode;32 }33 private static final Map<String, Colors> lookup = new HashMap<String, Colors>();34 static {35 for (Colors color : Colors.values()) {36 lookup.put(color.getColorName(), color);37 }38 }39 public static Colors get(String colorName) {40 return lookup.get(colorName);41 }42}43package org.openqa.selenium.support;44import org.openqa.selenium.By;45import org.openqa.selenium.WebDriver;46import org.openqa.selenium.WebElement;47import org.openqa.selenium.chrome.ChromeDriver;48public class ColorsTest {49 public static void main(String[] args) {50 WebDriver driver = new ChromeDriver();51 WebElement searchBox = driver.findElement(By.name("q"));52 searchBox.sendKeys("Selenium");53 searchBox.submit();54 driver.quit();55 }56}57package org.openqa.selenium.support;58import org.openqa.selenium.By;59import org.openqa.selenium.WebDriver;60import org

Full Screen

Full Screen

Enum Colors

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.support.Colors;2import org.openqa.selenium.support.Color;3Color color = Colors.RED;4import org.openqa.selenium.support.Colors;5import org.openqa.selenium.support.Color;6Color color = Colors.RED;7import org.openqa.selenium.support.Colors;8import org.openqa.selenium.support.Color;9Color color = Colors.RED;10import org.openqa.selenium.support.Colors;11import org.openqa.selenium.support.Color;12Color color = Colors.RED;13import org.openqa.selenium.support.Colors;14import org.openqa.selenium.support.Color;15Color color = Colors.RED;16import org.openqa.selenium.support.Colors;17import org.openqa.selenium.support.Color;18Color color = Colors.RED;19import org.openqa.selenium.support.Colors;20import org.openqa.selenium.support.Color;21Color color = Colors.RED;22import org.openqa.selenium.support.Colors;23import org.openqa.selenium.support.Color;24Color color = Colors.RED;25import org.openqa.selenium.support.Colors;26import org.openqa.selenium.support.Color;27Color color = Colors.RED;28import org.openqa.selenium.support.Colors;29import org.openqa.selenium.support.Color;30Color color = Colors.RED;31import org.openqa.selenium.support.Colors;32import org.openqa.selenium.support.Color;33Color color = Colors.RED;34import org.openqa.selenium.support.Colors;35import org.openqa.selenium.support.Color;36Color color = Colors.RED;37import org.openqa.selenium.support.Colors;38import org.openqa.selenium.support.Color;39Color color = Colors.RED;40import org.openqa.selenium.support.Colors;41import org.openqa.selenium.support.Color;42Color color = Colors.RED;43import org.openqa.selenium.support.Colors;

Full Screen

Full Screen

Enum Colors

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.support.Colors;2import org.openqa.selenium.support.Color;3import org.openqa.selenium.support.Colors.ColorName;4public class EnumColors {5 public static void main(String[] args) {6 Colors colors = new Colors();7 ColorName colorName = colors.getColorName("#FF0000");8 System.out.println("Color Name of #FF0000 is " + colorName);9 Color color = colors.getColor("#FF0000");10 System.out.println("Color Object of #FF0000 is " + color);11 String colorHex = colors.getColor(ColorName.RED);12 System.out.println("Color Hex of ColorName.RED is " + colorHex);13 }14}15getColorName(String colorHex)16getColor(String colorHex)17getColor(ColorName colorName)18asHex()19asRgba()20asHsla()21asRgb()22asHsl()23asCssRgba()24asCssHsla()25asCssRgb()

Full Screen

Full Screen

Enum Colors

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.support.Colors;2import java.awt.Color;3import org.openqa.selenium.Color;4Color color = new Color(0, 0, 0);5String colorName = Colors.getColorName(color);6System.out.println(colorName);7org.openqa.selenium.Color seleniumColor = new org.openqa.selenium.Color(0, 0, 0);8String seleniumColorName = Colors.getColorName(seleniumColor);9System.out.println(seleniumColorName);10org.openqa.selenium.support.Color colorsColor = new org.openqa.selenium.support.Color(0, 0, 0);11String colorsColorName = Colors.getColorName(colorsColor);12System.out.println(colorsColorName);

Full Screen

Full Screen

Enum Colors

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.support.Colors;2public class ColorTest {3public static void main(String[] args) {4Colors color = new Colors();5System.out.println("Color of Red is: "+color.getColor("red"));6System.out.println("Color of Blue is: "+color.getColor("blue"));7System.out.println("Color of Green is: "+color.getColor("green"));8System.out.println("Color of Yellow is: "+color.getColor("yellow"));9System.out.println("Color of Orange is: "+color.getColor("orange"));10System.out.println("Color of Purple is: "+color.getColor("purple"));11System.out.println("Color of Black is: "+color.getColor("black"));12System.out.println("Color of White is: "+color.getColor("white"));13System.out.println("Color of Gray is: "+color.getColor("gray"));14System.out.println("Color of Brown is: "+color.getColor("brown"));15System.out.println("Color of Maroon is: "+color.getColor("maroon"));16System.out.println("Color of Navy is: "+color.getColor("navy"));17System.out.println("Color of Olive is: "+color.getColor("olive"));18System.out.println("Color of Lime is: "+color.getColor("lime"));19System.out.println("Color of Aqua is: "+color.getColor("aqua"));20System.out.println("Color of Teal is: "+color.getColor("teal"));21System.out.println("Color of Fuchsia is: "+color.getColor("fuchsia"));22System.out.println("Color of Silver is: "+color.getColor("silver"));23System.out.println("Color of Cyan is: "+color.getColor("cyan"));24System.out.println("Color of Magenta is: "+color.getColor("magenta"));25System.out.println("Color of Gold is: "+color.getColor("gold"));26System.out.println("Color of Pink is: "+color.getColor("pink"));27System.out.println("Color of DarkRed is: "+color.getColor("darkred"));28System.out.println("Color of DarkBlue is: "+color.getColor("darkblue"));29System.out.println("Color of DarkGreen is: "+color.getColor("darkgreen"));30System.out.println("Color of DarkYellow is: "+color.getColor("darkyellow"));31System.out.println("Color of DarkOrange is: "+color.getColor("darkorange"));32System.out.println("Color of DarkPurple is: "+color.getColor("darkpurple"));33System.out.println("Color of DarkBlack is: "+color.getColor

Full Screen

Full Screen

Enum Colors

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.support.Colors;2Colors colors = new Colors();3String color = colors.getColor("text");4String backgroundColor = colors.getColor("background");5String borderColor = colors.getColor("border");6String linkColor = colors.getColor("link");7String visitedLinkColor = colors.getColor("visitedLink");8String activeLinkColor = colors.getColor("activeLink");9String hoverLinkColor = colors.getColor("hoverLink");10String selectedTextColor = colors.getColor("selectedText");11String selectedBackgroundColor = colors.getColor("selectedBackground");12String selectedBorderColor = colors.getColor("selectedBorder");13String selectedLinkColor = colors.getColor("selectedLink");14String selectedVisitedLinkColor = colors.getColor("selectedVisitedLink");15String selectedActiveLinkColor = colors.getColor("selectedActiveLink");16String selectedHoverLinkColor = colors.getColor("selectedHoverLink");17String focusOutlineColor = colors.getColor("focusOutline");18String focusBorderColor = colors.getColor("focusBorder");19String focusTextColor = colors.getColor("focusText");20String focusBackgroundColor = colors.getColor("focusBackground");21String focusLinkColor = colors.getColor("focusLink");22String focusVisitedLinkColor = colors.getColor("focusVisitedLink");23String focusActiveLinkColor = colors.getColor("focusActiveLink");24String focusHoverLinkColor = colors.getColor("focusHoverLink");25String focusSelectedTextColor = colors.getColor("focusSelectedText");

Full Screen

Full Screen
copy
1private void initializeEdgeDriver() 2 {34 System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir").concat("\\drivers\\msedgedriver.exe"));5 ChromeOptions chromeOptions = new ChromeOptions();6 chromeOptions.setBinary(7 "C:\\Program Files (x86)\\Microsoft\\Edge Dev\\Application\\msedge.exe");8 EdgeOptions edgeOptions = new EdgeOptions().merge(chromeOptions);9 webDriver = new ChromeDriver(edgeOptions);10 webDriver.manage().window().maximize();11 webDriverWait = new WebDriverWait(webDriver, GLOBAL_TIMEOUT);12}13
Full Screen
copy
1string edgeDriverPath = SolutionDirPath() + "\\edgedriver_win64";2string edgeBrowserPath = ProgramFilesx86() + "\\Microsoft\\Edge\\Application\\msedge.exe";34var service = EdgeDriverService.CreateChromiumService(@edgeDriverPath, "msedgedriver.exe");5service.UseVerboseLogging = true;67var optionsEdge = new EdgeOptions();8optionsEdge.UseChromium = true;9// ignore if any security related alerts10optionsEdge.AddArguments("--ignore-certificate-errors");11optionsEdge.BinaryLocation = @edgeBrowserPath;1213driver = new EdgeDriver(service, optionsEdge);14
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 Enum-Colors

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