TESTEVERYTHING

Showing posts with label QA. Show all posts
Showing posts with label QA. Show all posts

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");








Which one is right ?

Translate







Tweet