Skip to content

Instantly share code, notes, and snippets.

View costea32's full-sized avatar

Constantin Pascal costea32

View GitHub Profile
@costea32
costea32 / timeZoneRoulette.sh
Created May 20, 2020 08:00
Shell script to set system to a random time zone
echo "checking current date time:"
date
TIMEZONES=()
readarray -t TIMEZONES < <(timedatectl list-timezones)
NEW_TZ=${TIMEZONES[$RANDOM % ${#TIMEZONES[@]}]}
echo "Setting up time zone:${NEW_TZ}..."
sudo timedatectl set-timezone "${NEW_TZ}"
echo "Time zone set, checking time:"
date
public class User
{
public int Id { get; set; }
public string FullName { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
@costea32
costea32 / BDDfyexample.cs
Created September 25, 2015 12:27
The cool way to use bddfy
[Test]
public void TestBddFy()
{
this.Given(_ => GivenIHaveAnApple(1), "Given I have {0} apples")
.When(_ => WhenIEatAnApple(null), "I eat an apple")
.Then(_ => ThenIHaveNoApples(), "I have no apples")
.BDDfy();
}
@costea32
costea32 / ElementNotPresent_With_FindElements.cs
Created August 7, 2015 04:24
BlogExample_ElementNotPresent_With_FindElements
...
var btn=driver.FindElements(By.XPath("//button[@class='notExisting']")).FirstOrDefault();
if (btn != null)
{
btn.Click();
}
...
@costea32
costea32 / ElementNotPresent_With_DriverExtension.cs
Created August 7, 2015 04:23
BlogExample_ElementNotPresent_With_DriverExtension
public static class WebDriverExtensions{
public static bool ElementExists(this IWebDriver webDriver, By @by)
{
return webDriver.FindElements(@by).Any();
}
public static IWebElement FindElementOrDefault(this IWebDriver webDriver, By @by)
{
return webDriver.FindElements(@by).FirstOrDefault();
}
@costea32
costea32 / ElementNotPresent_With_DriverExtension.cs
Last active August 29, 2015 14:11
Checking Element is not present on web page
public static class WebDriverExtensions{
public static bool ElementExists(this IWebDriver webDriver, By @by)
{
return webDriver.FindElements(@by).Any();
}
public static IWebElement FindElementOrDefault(this IWebDriver webDriver, By @by)
{
return webDriver.FindElements(@by).FirstOrDefault();
}
@costea32
costea32 / Page.cs
Created September 23, 2014 20:29
ObjectMap decent base Page
public abstract class Page
{
protected readonly IWebDriver driver;
protected Page(IWebDriver driver)
{
this.driver = driver;
MaxLoadingTime = TimeSpan.FromSeconds(30);
}
@costea32
costea32 / ObjMap.cs
Last active August 29, 2015 14:06
Object Map - Simple Object Map Example
public class Page
{
protected readonly IWebDriver driver;
public Page(IWebDriver driver)
{
this.driver = driver;
}
public string Title
@costea32
costea32 / gist:bb5573b6fc5cc7e257d1
Created September 22, 2014 17:59
Object Map - Usual Examples
package org.openqa.selenium.example;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
public class Example {
public static void main(String[] args) {
// Create a new instance of the html unit driver
@costea32
costea32 / HtmlTable.cs
Last active August 29, 2015 14:05
Selenium TableElement
public class HtmlTable<T> : HtmlControl where T : HtmlRow, new()
{
private string rowFilterXpath = "descendant::tr";
public HtmlTable(IWebElement webElement): base(webElement)
{
}
public string RowFilterXpath
{