Skip to content

Instantly share code, notes, and snippets.

View andreidbr's full-sized avatar

Andrei Dobra andreidbr

View GitHub Profile
package PortfolioTests;
import java.util.Arrays;
public class CodeWars {
public static void main(String[] args) {
Integer[] ar = {100, 5, 3, 99, 34, 63, 2};
int sum = 39;
// bubble(ar);
// findSum(ar, sum);
const {webdriver, Builder, By, Key, until} = require('selenium-webdriver'),
test = require('selenium-webdriver/testing'),
assert = require('assert');
test.describe('PortfolioTestsAsyncAwait', function() {
test.before(async function () {
driver = await new Builder().forBrowser('chrome').build();
});
test.it('01 Drums Access Await', async function () {
@andreidbr
andreidbr / mochaTest.js
Created March 27, 2018 17:37
A Selenium test using JS and Mocha
const {webdriver, Builder, By, Key, until} = require('selenium-webdriver'),
test = require('selenium-webdriver/testing'),
assert = require('assert');
let driver;
test.describe('PortfolioTests', function() {
test.before(function *() {
driver = new Builder().forBrowser('chrome').build();
});
@andreidbr
andreidbr / simpleTest.js
Created March 27, 2018 17:17
A simple test in JavaScript using Selenium Webdriver
const {Builder, By, Key, until} = require('selenium-webdriver');
let driver = new Builder().forBrowser('chrome').build();
driver.get("https://andreidbr.github.io/JS30/");
driver.findElement(By.xpath('/html/body/div[2]/div[1]')).click();
driver.wait(until.titleIs('JS30: 01 Drums'), 1000);
driver.close();
@andreidbr
andreidbr / forLoopSelenium
Created March 18, 2018 16:31
A simple for loop with Selenium
@Test(testName = "Check all sounds", description = "Check that, when clicking every key, a sound is played", groups = {"01Drums"})
public void soundsPlayTest() throws InterruptedException {
driver.findElement(By.xpath("/html/body/div[2]/div[1]")).click();
List<WebElement> keyList = driver.findElements(By.className("key"));
List<WebElement> audioList = driver.findElements(By.tagName("audio"));
Actions builder = new Actions(driver);
for (int i = 0; i < keyList.size(); i++) {
Action sendKey = builder.moveToElement(keyList.get(i)).sendKeys(String.valueOf(keyList.get(i).getText().charAt(0))).build();
sendKey.perform();
@andreidbr
andreidbr / forEachSelenium
Created March 18, 2018 15:54
A forEach loop in Selenium
@Test(testName = "06 Filter Functionality Test", description = "Check that the 06 Filter page functions correctly", groups = {"06Filter"})
public void verifyFilterTest() throws InterruptedException {
driver.findElement(By.xpath("/html/body/div[2]/div[6]")).click();
driver.findElement(By.xpath("/html/body/form/input")).sendKeys("an");
Thread.sleep(500);
driver.findElement(By.xpath("/html/body/form/input")).sendKeys("dr");
if (driver.findElement(By.className("name")).isDisplayed()) {
List<WebElement> resultList = driver.findElements(By.className("name"));
@andreidbr
andreidbr / soundPlayingTest.java
Last active April 22, 2021 15:21
A Selenium test to check if a sound is playing / has played
@Test(testName = "Listen for Sound", description = "Check that, when clicking the 'A' key, a sound is played", groups = {"01Drums"})
public void soundPlayTest() throws InterruptedException {
driver.findElement(By.xpath("/html/body/div[2]/div[1]")).click();
WebElement aKey = driver.findElement(By.xpath("/html/body/div/div[1]"));
Actions builder = new Actions(driver);
Action sendAKey = builder.moveToElement(aKey).sendKeys("A").build();
sendAKey.perform();
Thread.sleep(1000);
WebElement audio = driver.findElement(By.tagName("audio"));
@Test(testName = "03 CSS Variable Functionality Test", description = "Check that the 03 CSS Variable page functions correctly", groups = {"03CSS"})
public void verifyCSSTest() {
driver.findElement(By.xpath("/html/body/div[2]/div[3]")).click();
String initialStyle = driver.findElement(By.xpath("/html")).getAttribute("style");
WebElement slider = driver.findElement(By.xpath("/html/body/div/p[1]/input[2]"));
slider.click();
slider.sendKeys(Keys.ARROW_RIGHT);
String secondStyle = driver.findElement(By.xpath("/html")).getAttribute("style");
Assert.assertNotEquals(initialStyle, secondStyle);
@andreidbr
andreidbr / cssVariableDemo02.java
Created March 15, 2018 18:56
A Selenium test to compare two CSS styles of an element
@Test(testName = "02 Clock Functionality Test", description = "Check that the 02 Clock page functions correctly", groups = {"02Clock"})
public void verifyClockTest() throws InterruptedException {
driver.findElement(By.xpath("/html/body/div[2]/div[2]")).click();
String firstStyle = driver.findElement(By.xpath("/html/body/div/div/div[3]")).getAttribute("style");
Thread.sleep(2000);
String secondStyle = driver.findElement(By.xpath("/html/body/div/div/div[3]")).getAttribute("style");
Assert.assertNotEquals(firstStyle, secondStyle, "There are no differences in the two styles");
}
@andreidbr
andreidbr / cssVariableDemo01.java
Created March 15, 2018 18:43
A Selenium Webdriver test that compares CSS classes
@Test(testName = "Click 'A' Test", description = "Check that you can click the 'A' key and the correct response triggers", groups = {"01Drums"})
public void aKeyTest() {
driver.findElement(By.xpath("/html/body/div[2]/div[1]")).click();
WebElement aKey = driver.findElement(By.xpath("/html/body/div/div[1]"));
Actions builder = new Actions(driver);
Action sendAKey = builder.moveToElement(aKey).sendKeys("A").build();
sendAKey.perform();
Assert.assertEquals(aKey.getAttribute("class"), "key playing");
}