Skip to content

Instantly share code, notes, and snippets.

View MaksymKrut's full-sized avatar

Max Krutskykh MaksymKrut

View GitHub Profile
@MaksymKrut
MaksymKrut / DriverBuilder.java
Last active October 18, 2018 09:41
Options for maximising window in Java. window.maximize() broken in 70th chromedriver release.
package utilities;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.InvalidArgumentException;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
package com.softalp.viner.utils;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.telephony.TelephonyManager;
public class NetworkType {
private Context context;
@MaksymKrut
MaksymKrut / Common.java
Created October 2, 2016 15:56
File upload with Selenium.
public static void uploadFile(WebElement uploadField, String name) throws InterruptedException, IOException {
File file = new File("src/main/resources/test.pdf");
String absolutePath = file.getAbsolutePath();
System.out.println("\n\nFile absolute path: " + absolutePath + "\n\n");
uploadField.sendKeys(absolutePath);
Thread.sleep(100 * 1000);
@MaksymKrut
MaksymKrut / FeatureContext.php
Created August 18, 2016 07:35
@mink @Behat Name all existing fields on page with JS. Workaround against "id|name|label|value missing" error during getPage()->fillField($field, $value).
/**
* Differ from Mink as does not have fixStepArgument check
* Fills in form field with specified id|name|label|value
* Example: When I fill in "username" with: "bwayne"
* Example: And I fill in "bwayne" for "username"
* @When /^(?:|I )fill in field "(?P<field>(?:[^"]|\\")*)" with "(?P<value>(?:[^"]|\\")*)"$/
* @param $field
* @param $value
* @throws \Behat\Mink\Exception\ElementNotFoundException
*/
@MaksymKrut
MaksymKrut / FeatureContext.php
Created August 7, 2016 16:54
Behat Mink Selenium WebDriver spin() helper function implementation. Checks if XPath, CSS element exists on the page defined number of times/seconds.
/**
* Wait for function return true, trying to execute it number of times
* @param $lambda
* @param int $tries
* @return bool
* @throws Exception
*/
public function spin($lambda, $tries = 60)
{
for ($i = 0; $i < $tries; $i++) {
@MaksymKrut
MaksymKrut / FeatureContext.php
Last active August 1, 2016 17:25
Make Behat recognise unnamed iframes on the page. We do not care how to name them, just how to operate with them.
/**
* @Given I switch to iframe with locator :locator
* @param String $locator
*/
public function iSwitchToIFrameWithLocator($locator)
{
$value = $this->takeValueFromIniFile('locators', $locator);
$iframe = $this->getSession()->getPage()->find("css", $value);
$iframeName = $iframe->getAttribute("name");
if ($iframeName == "") {