TESTEVERYTHING

Wednesday, 18 July 2018

Install Sauce Connect on Mac OSX and Run from local

   Install Sauce Connect on Mac OSX



Install the App

  1. Press Command+Space and type Terminal and press enter/return key.
  2. Run in Terminal app:
    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null ; brew install caskroom/cask/brew-cask 2> /dev/null
    and press enter/return key. 
    If the screen prompts you to enter a password, please enter your Mac's user password to continue. When you type the password, it won't be displayed on screen, but the system would accept it. So just type your password and press ENTER/RETURN key. Then wait for the command to finish.
  3. Run:
    brew cask install sauce-connect
  4. In terminal set all the required parameter
  5. export SAUCELABS_HOST="127.0.0.1"
    export SAUCELABS_PORT="4448"
    export SAUCELABS_USER_NAME="<YOUR USER ACCOUNT>"
    export SAUCELABS_KEY="<YOUR SAUCELABS LAB KEY>"
    export SAUCE_LAB_GULP_TASK="<TASK NAME>"
    export SAUCELABS_TUNNEL="Tunnel Name"
    export APPLICATION_ENVIRONMENT="ENVIRONMENT NAME"
  6. Execute below command once the parameter set in terminal
  7. sc --no-autodetect -u $SAUCELABS_USER_NAME -k $SAUCELABS_KEY -i $SAUCELABS_TUNNEL -l /tmp/sauce_connect.log --se-port 4448

Thursday, 13 July 2017

Handle custom tags using WebDriver

Sometime while doing automation we have to identify the element which have custom tags like <g> <svg> etc. For this we normally use * that will identify all elements tags in case we have to identify only specified custom tag then we can use below example for this.


<svg height="600" width="910" xmlns:xlink="http://www.w3.org/1999/xlink"  
   id="svgcontent" overflow="visible" x="910" y="600" viewBox="0 0 910 600">
    <g style="pointer-events:all">
      <text fill="rgb(0,0,0)" font-family="Sans-Serif" font-size="13" id="80-155-126" 
        transform="rotate(-90, 168, 126)" y="126" x="168" style="pointer-
         events:inherit">A100A</text>
   </g>
  </svg>

Following Xpath will work here

By.xpath("//*[local-name()='svg']")

By.xpath("//*[local-name()='text']")


By.xpath("//*[local-name()='g']")


Sunday, 5 February 2017

EXTRACT CSS PROPERTY VLAUE OF PSEUDO ELEMENTS CONTAINING :after/:before CSS TAG USING JAVASCRIPT IN WEBDRIVER :

We cannot extract css properties of pseudo elements using web driver commands such as ‘.getPropertyValue’ . For this, we need to use JavaScript and execute a js script in selenium web driver.


A CSS pseudo-element is used to style specified parts of an element.
   For example, it can be used to:
   Style the first letter, or line, of an element
   Insert content before, or after, the content of an element

ISSUE:



In above scenario, we need to get the text “Internal Use Only” from UI which is associated with an Anchor (a) tag in DOM with :after CSS tag. The text is present in “content” Style Property as shown in right highlighted box.

The :after CSS tag cannot be located directly using web driver and thus required text cannot be retrieved simply by using .getPropertyValue() function in selenium.

To achieve this, a javascript needs to be executed in our selenium code :

WebElement elementObj = driver.findElement(By.xpath("<YourXpath>"));
String pseudoElementText = ((JavascriptExecutor)driver).executeScript("return window.getComputedStyle(arguments[0],':after').getPropertyValue(content');", elementObj).toString();

System.out.println(pseudoElementText);


In same way we can extract another properties values as well.

Thanks


Wednesday, 16 November 2016

Actual differences between Explicit and Implicit Waits

Hi All,

As i have already mentioned the differences Explicit and Implicit Waits in my earlier post but now we will see the actual results. there will be two conditions we can think of it what will happen if implicit wait is greater than explicit wait OR  implicit wait is lower than explicit wait

lets see what will happen


Condition 1: implicit wait is greater than explicit wait

           implicitlyWait = 10 seconds
            explicitWait = 2 seconds
            ///////////////////////////////////////
            public static void main(String[]args) {
            FirefoxDriver driver = new FirefoxDriver();
            driver.manage().window().maximize();
            driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
            driver.get("https://www.google.com");
            try {
                        Date date = new Date();
                        System.out.println(" before " + new Timestamp(date.getTime()));
                        WebDriverWait wait = new WebDriverWait(driver, 2);
                        wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[contains(text(),'NOT FOUND ELEMENT')]")));
            } catch (Exception e) {
                        // TODO Auto-generated catch block
                        Date date = new Date();
                        System.out.println(" after " + new Timestamp(date.getTime()));
                        e.printStackTrace();
            }


/////////////////////////////////

let see the output in console:   taking 10 seconds

before 2016-11-16 16:24:33.128
after 2016-11-16 16:24:43.321

Condition 2: implicit wait is lower than explicit wait
           implicitlyWait = 2 seconds
            explicitWait = 10 seconds
            ///////////////////////////////////////
            public static void main(String[]args) {
            FirefoxDriver driver = new FirefoxDriver();
            driver.manage().window().maximize();
            driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
            driver.get("https://www.google.com");
            try {
                        Date date = new Date();
                        System.out.println(" before " + new Timestamp(date.getTime()));
                        WebDriverWait wait = new WebDriverWait(driver, 10);
                        wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[contains(text(),'NOT FOUND ELEMENT')]")));
            } catch (Exception e) {
                        // TODO Auto-generated catch block
                        Date date = new Date();
                        System.out.println(" after " + new Timestamp(date.getTime()));
                        e.printStackTrace();
            }


/////////////////////////////////

let see the output in console:   taking 10 seconds

before 2016-11-16 16:26:53.355
 after 2016-11-16 16:27:03.53

Monday, 14 November 2016

WebDriver | Automation | launch/Execute on different version of Firefox

Run tests on specific Firefox version | Selenium


Firefox binary

Imagine a situation where you have to test your web application against two different versions of the Firefox browser. By default, when you instantiate FirefoxDriver, the Firefox version that is available on the PATH variable is launched. But if you want to launch a different version of Firefox, we need to use Firefox Binary. For this first steps you have to install all the versions of Firefox which you want to test on your system.

Make sure the installed Firefox versions on different path locations using Custom installation

Installing multiple versions of Firefox


Suppose you have already installed the Firefox(version 22) means default Firefox is already installed. this can be found on your program file location like this..

"C:\Program Files (x86)\Mozilla Firefox"

Now we have to install another Firefox version (lets take Firefox version 23).

1. Download this version from Mozilla site and start installing it.

2. When you reach the following screen in your installation, select Custom.




3. Enter the path as "C:\Mozilla Firefox\" in the path field as shown as follows, and proceed with the installation:



4. Now try to launch Firefox from your code; it will launch Firefox 22 version (default Firefox browser) as it is available in the PATH variable.

5. So, in order to use Firefox 23.0, try to use Firefox Binary. The following is the code example for it:

Here we have to define the path of my another installed Firefox version


import java.io.File;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;

private WebDriver driver;

FirefoxBinary binary = new FirefoxBinary(new File("C:\\Mozilla Firefox\\firefox.exe"));

FirefoxProfile profile = new FirefoxProfile();   

driver = new FirefoxDriver(binary, profile);

driver.get("http://www.google.com");








Translate







Tweet