Select -> option abstraction

No such thing in Protractor, but we can write our own: select-wrapper.js ‘use strict’; var SelectWrapper = function(selector) { this.webElement = element(selector); }; SelectWrapper.prototype.getOptions = function() { return this.webElement.all(by.tagName(‘option’)); }; SelectWrapper.prototype.getSelectedOptions = function() { return this.webElement.all(by.css(‘option[selected=”selected”]’)); }; SelectWrapper.prototype.selectByValue = function(value) { return this.webElement.all(by.css(‘option[value=”‘ + value + ‘”]’)).click(); }; SelectWrapper.prototype.selectByPartialText = function(text) { return this.webElement.all(by.cssContainingText(‘option’, text)).click(); … Read more

How to run only one unit test class using Gradle

To run a single test class Airborn’s answer is good. With using some command line options, which found here, you can simply do something like this. gradle test –tests org.gradle.SomeTest.someSpecificFeature gradle test –tests *SomeTest.someSpecificFeature gradle test –tests *SomeSpecificTest gradle test –tests all.in.specific.package* gradle test –tests *IntegTest gradle test –tests *IntegTest*ui* gradle test –tests *IntegTest.singleMethod gradle … Read more

Before and After Suite execution hook in jUnit 4.x

Yes, it is possible to reliably run set up and tear down methods before and after any tests in a test suite. Let me demonstrate in code: package com.test; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; @RunWith(Suite.class) @SuiteClasses({Test1.class, Test2.class}) public class TestSuite { @BeforeClass public static void setUp() { System.out.println(“setting up”); } … Read more

Check if any alert exists using selenium with python

What I do is to set a conditional delay with WebDriverWait just before the point I expect to see the alert, then switch to it, like this: from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.common.exceptions import TimeoutException browser = webdriver.Firefox() browser.get(“url”) browser.find_element_by_id(“add_button”).click() try: WebDriverWait(browser, 3).until(EC.alert_is_present(), ‘Timed out … Read more

How to properly assert that an exception gets raised in pytest?

pytest.raises(Exception) is what you need. Code import pytest def test_passes(): with pytest.raises(Exception) as e_info: x = 1 / 0 def test_passes_without_info(): with pytest.raises(Exception): x = 1 / 0 def test_fails(): with pytest.raises(Exception) as e_info: x = 1 / 1 def test_fails_without_info(): with pytest.raises(Exception): x = 1 / 1 # Don’t do this. Assertions are caught … Read more

How to check whether dynamically attached event listener exists or not?

I did something like that: const element = document.getElementById(‘div’); if (element.getAttribute(‘listener’) !== ‘true’) { element.addEventListener(‘click’, function (e) { const elementClicked = e.target; elementClicked.setAttribute(‘listener’, ‘true’); console.log(‘event has been attached’); }); } Creating a special attribute for an element when the listener is attached and then checking if it exists.