Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static WebElement $(ExpectedCondition<WebElement> conditionToWaitParentElement, String innerElementCssSelector) {
- public static WebElement $(ExpectedCondition<WebElement> conditionToWaitParentElement, By innerElementLocator) {
- /*
- лучше в $(ExpectedCondition<WebElement> conditionToWaitParentElement, String innerElementCssSelector)
- использовать вызов $(ExpectedCondition<WebElement> conditionToWaitParentElement, By innerElementLocator)
- мы не много выиграем в лаконичности
- но - таким образом мы лучше обеспечим - что оба метода работают одинаково
- */
- ********************************************
- public static ExpectedCondition<List<WebElement>> exactVisibleTexts(final By elementsLocator, final String... texts) {
- ...
- public String toString() {
- return String.format("Expected texts: %s, Actual texts: %s", Arrays.toString(texts), String.join(", ", actualTexts));
- }
- /*
- exactTextsOfVisible - предлагаю такое имя для кондишена, оно чуть точнее отражает суть происходящего
- можно подробнее - exactTextsOfVisibleElements. Мне кажется - это уже лишнее
- в toString() - лучше следовать некой схеме
- ... list/element located by ...
- т е - указать - про что речь - что проверяем
- и уточнить локатор (что тоже важно)
- should ...
- описываем expected
- while actual ...
- описываем actual
- тут например
- exact texts of visible elements of list located by __elementsLocator__
- should be __Arrays.toString(texts)__
- while actual are __String.join(", ", actualTexts)__
- касается и других кондишенов
- */
- **************************************************
- public static ExpectedCondition<WebElement> listElementWithText(final By elementsLocator, final String taskText) {
- /*
- taskText - не очень подходящее имя для параметра универсального кондишена
- просто text, expectedText - поточнее будет
- тут - выбирая имя для параметра кондишена - смотри на все кондишены
- в аналогичных ситуациях - используй аналогичные термины
- */
- ******************************************************
- public static ExpectedCondition<WebElement> listElementWithText(final By elementsLocator, final String taskText) {
- ...
- actualTexts = getTexts(elements);
- for (WebElement element : elements) {
- actualText = element.getText();
- if (actualText.equals(taskText)) {
- return element;
- }
- }
- /*
- taskText - не очень подходящее имя для параметра универсального кондишена
- мы получили тексты - вызов getTexts
- и в следующем цикле - мы снова получаем у элементов тексты
- экономнее будет - в этом цикле оперироватьранее полученными текстами
- и возвращать elements.get(i) - если найден нужный элемент
- переискиваться тут ничего не будет - т к мы не оперируем лейзи прокси списком
- так что - этой проблемы уже нет
- получая elements.get(i) - ты получишь нужный тебе элемент
- */
- *********************************************************
- public static ExpectedCondition<WebElement> exactText(final String elementsLocator, final String taskText) {
- /*
- taskText - не очень подходящее имя для параметра универсального кондишена
- логика у кондишена - как и у listElementWithText
- лучше и тут остаться в тех же терсинах listElementWithExactText
- к реализации - аналогичные рекомендации
- */
- **********************************************************
- public static ExpectedCondition<WebElement> listElementWithClass(final By elementsLocator, final String elementsClass) {
- ...
- if (element.getAttribute("class").contains(elementsClass)) {
- ...
- public String toString() {
- return String.format("Element \nof %s \nto have class: %s\n, Actual class: %s", elementsLocator, elementsClass, String.join(", ", actualTexts));
- }
- /*
- elementsClass - лучше cssClass, так поточнее будет
- что касается условия element.getAttribute("class").contains
- например - у элемента атрибут class содержит - "active editing"
- а мы проверяем - есть ли класс edit
- и посчитаем - что есть
- правильнее - разбить "active editing" на набор слов (разделитель = пробел)
- и в случае если одно из слов равно искомому классу - мы нашли нужный элемент
- ну и про actualTexts
- в данном случае - это и правда не нужная нам информация, как ты сама верно заметила
- она не поможет нам - если мы будем анализировать такое сообщение об ошибке
- в toString - лучше вывести - как раз содержимое атрибута class - для всех элементов списка
- */
- ******************************************************
- // вот этому вроде и не место в пейдже, но если перенести в ConciseAPI - начинает почему-то глючить BaseTest
- public static Actions act = new Actions(getDriver());
- public static JavascriptExecutor js = (JavascriptExecutor) getDriver();
- public static void executeJavaScript(String JavaScript) {
- js.executeScript(JavaScript);
- }
- /*
- это и правда нужно перенести в ConciseAPI
- не надо объявлять статические переменные act и js
- в executeJavaScript - выполняй ((JavascriptExecutor) getDriver()).executeScript(JavaScript);
- аналогично и для act
- реализуй метод actions()
- возвращающий new Actions(getDriver());
- проблем не должно быть
- */
- *******************************
- public static void doubleClick(WebElement element) {
- /*
- это тоже переноси в ConciseAPI
- если используешь метод actions() - проблем не должно возникнуть
- */
- ***********************************************
- public static void hover(WebElement element)
- /*
- это тоже переноси в ConciseAPI
- если используешь метод actions() - проблем не должно возникнуть
- build().perform() vs perform()
- http://stackoverflow.com/questions/29071144/wbdriver-actions-build-perform
- http://stackoverflow.com/questions/16435798/webdriver-actions-perform-or-actions-build-perform
- http://www.ufthelp.com/2014/11/working-with-action-class-in-selenium.html
- */
- *****************************************************
- $(listElementWithText(tasks, taskText)...
- /*
- корректнее для определения таски использовать кондишен listElementWithExactText
- */
- ***************************************************
- $(....).clear();
- $(...).sendKeys(taskTextEdited);
- return $(...);
- /*
- в ConciseAPI реализуй такой метод
- WebElement setValue(WebElement element, String text)
- */
- ***************************************************
- public class BaseTest {
- static File pathBinary = new File("C:\\program files\\Mozilla Firefox\\firefox.exe");
- static FirefoxBinary firefoxBinary = new FirefoxBinary(pathBinary);
- static FirefoxProfile firefoxProfile = new FirefoxProfile();
- static {
- setDriver(new FirefoxDriver(firefoxBinary, firefoxProfile));
- }
- /*
- можно и так
- уточнить - что за FirefoxDriver вызываем
- уверена, что тебе недостаточно setDriver(new FirefoxDriver()); ?
- */
Advertisement
Add Comment
Please, Sign In to add comment