Showing posts with label selenium. Show all posts
Showing posts with label selenium. Show all posts

Saturday, 11 July 2015

object doesn't support this property or method attachevent





  • When I try to launch the Internet Explorer 11 via Selenium RC server, faced with the below pop.
  • After surfing found attachEvent is a deprecated function used in older versions of Internet Explorer and modern browsers use addEventListener instead.
  • So if you are using earlier version of Selenium server try using the latest selenium standalone server. Which will solve the reported pop up issue.



couldn't open app window; is the pop-up blocker enabled

When I try to launch the Internet Explorer 11 via Selenium RC server, faced with the below pop.

After marking the pop up blocking to be turned off and disabling the “Enable protected mode settings” under security tab, the reported issues got resolved. Please find the helpful screen shots.





Tuesday, 24 March 2015

Running testng class file from cmd prompt and jenkins

we can run the testng class files through eclipse by adding the testng libraries in Build path.
If we need to run the same testng class files from command prompt and through any tools we could do so by adding the testng libraries to the CLASSPATH variable. or by giving the path with -cp option available in java. Also can add any jar files which are referred in the class files.



set CLASSPATH = %CLASSPATH%;D:\Are\Sel\Ecom_project\TestNG\testng-6.8.jar

D:\Area\Sel\>java org.testng.TestNG testng.xml
[TestNG] Running:
  D:\Are\Sel\Ecom_project\src\scripts\testng.xml

TestNG is working fine
===============================================
Suite1
Total tests run: 1, Failures: 0, Skips: 0
===============================================



To run the same testng scripts via Jenkins can add the CLASSPATH variable at master level or at node level specifying the path of the jar files. Represented the same in below snaps.










 

Friday, 13 March 2015

Selenium grid implementation on two different machines and browsers


This post guides us for the GRID implementation of Selenium where we launch a grid server and register two nodes in two different machines.

Here we launch the HUB in machine1 and start node 1 with two instances of chrome browser and node 2 with two instances of Firefox.


To start Hub

HUB: Machine 1

java -jar selenium-server-standalone-2.43.1.jar -role hub -port 4455

To start nodes

Node : Machine 2 (launching only chrome browser of 2 instances)
 

java -jar selenium-server-standalone-2.43.1.jar -role node -hub http://<ip_of_hub_machine:4455>/grid/register -port 5557 -Dwebdriver.chrome.driver=chromedriver.exe -browser browserName=chrome,platform=WINDOWS,maxInstances=2

Node: Machine 3 (
launching only firefox browser of 2 instances)

java -jar selenium-server-standalone-2.45.0.jar -role node -hub http://
<ip_of_hub_machine:4455>/grid/register -port 5587 -browser browserName=firefox,platform=WINDOWS,maxInstances=2

After launching hub and nodes we can see the instances of the nodes in grid console under URL http://localhost:4455/grid/console

















 

Sample program:

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class GridTest {

    static DesiredCapabilities dc = null;
    WebDriver driver;

    public GridTest() throws MalformedURLException {
        dc = new DesiredCapabilities();
       

    }

    public void firefox() throws MalformedURLException, InterruptedException {
        dc.setBrowserName(DesiredCapabilities.firefox().getBrowserName());
        excute("firefox");
    }

    public void chorme() throws MalformedURLException, InterruptedException {
        dc.setBrowserName(DesiredCapabilities.chrome().getBrowserName());
        excute("chrome");
    }

    public void excute(String browsername) throws MalformedURLException, InterruptedException {
       
        dc.setPlatform(Platform.WINDOWS);
        driver = new RemoteWebDriver(new URL(
                "http://<ip_of_hub_machine:4455>/wd/hub"), dc);
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        System.out.println("In "+browsername);
        driver.get("https://www.google.co.in/");
        System.out.println(driver.getCurrentUrl());
        driver.quit();
    }

    public static void main(String[] args) throws MalformedURLException, InterruptedException {
        // TODO Auto-generated method stub

        GridTest t1 = new GridTest();

        t1.firefox();
        t1.chorme();

    }
}




Firefox in Machine 1

Chrome in Machine 2

Monday, 29 December 2014

Few selenium webdriver exceptions


NoAlertPresentException - Occurs when Code exists to handle the alert, but there is no alert present in real time during execution. 
UnexpectedAlertPresentException - When there is a alert present which is not handled by the  code, this exception occurs. 
NoSuchElementException - When the Web element doesn't match with the element present in the browser or when the selenium tries to identify the specified element when its actually not  completed  loading the browser. 
NoSuchFrameException - Thrown when Code existsto handle a frame, but the frame didn't actually present execution. 
NoSuchWindowException- Occurs when Code exists to navigate to new window using driver.switchTo().window(session id) , but there is no window exists with the referenced window element. 
StaleElementReferenceException - Occurs when the refereed element is no more on DOM or the element has been deleted entirely by navigating to different page or refreshing the page. 
ElementNotVisibleException - This occurs when the element actually present in the DOM, however not visible or its in hidden to be referred.

Saturday, 27 December 2014

Password field value entered twice on using selenium webdriver

While running webdriver script to login to webpage by provide the username and password credentials, you may notice that the password field is actually entered twice once you enter the username and then entering the password.

The reason is when you have logged in before via manually/script and if the auto save feature of user name and passwords are enabled and saved this may occur.

If Auto save feature is enabled for username and password, after entering the username via script and tabbing out to enter the password itself put the saved password.

Here the password is 7 characters, but 14 characters has been updated.

Password typed twice


Solution:

1. Remove the auto save of user name and password feature at browser level
2. Or do a clear on the fields before entering the values.
 

Thursday, 25 December 2014

The method sendKeys(CharSequence[]) in the type WebElement is not applicable for the arguments (String)

When using sendKeys on an web element using selenium, the reported exception may be thrown as below.

Exception in thread "main" java.lang.Error: Unresolved compilation problem:
    The method sendKeys(CharSequence[]) in the type WebElement is not applicable for the arguments (String)

    at scripts.VerifyLogin.main(VerifyLogin.java:12)


This can be corrected by changing the java compilation level tot he latest availabe verison in eclipse.
Project propeties > Build Path > configure Build Path > Java compiler > compiler compilation level (Change to latest available version).


   

Thursday, 9 October 2014

org.openqa.selenium.remote.SessionNotFoundException: Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones. Enable Protected Mode must be set to the same value (enabled or disabled) for all zones. (WARNING: The server did not provide any stacktrace information)


[TestNG] Running:
  C:\Users\tester\AppData\Local\Temp\testng-eclipse-520368244\testng-customsuite.xml

Started InternetExplorerDriver server (32-bit)
2.42.0.0
Listening on port 30903
FAILED CONFIGURATION: @BeforeMethod beforeMethod
org.openqa.selenium.remote.SessionNotFoundException: Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones. Enable Protected Mode must be set to the same value (enabled or disabled) for all zones. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 1.69 seconds
Build info: version: '2.43.1', revision: '5163bce', time: '2014-06-10 19:27:58'


Driver info: org.openqa.selenium.ie.InternetExplorerDriver
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

.
.
.

The protected mode setting in internet explorer must be enabled for all zones listed under the security tab on Internet Options menu.
Correcting it to have the setting enables would solve the above reported issue.



Monday, 1 September 2014

Exception in thread "main" java.lang.IllegalStateException

When executing a selenium script written in java to use IE/Chrome driver, an exception would have been thrown to check System.setProperty. The code below seems to be exactly right but 'webdriver' is coded as 'Webdriver' in the first argument, and there stands the exception.

File file = new File("G:\\Data\\git\\Test\\lib\\IEDriverServer.exe");
System.setProperty("Webdriver.ie.driver", file.getAbsolutePath());
WebDriver driver = new InternetExplorerDriver();


Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.ie.driver system property; for more information, see http://code.google.com/p/selenium/wiki/InternetExplorerDriver. The latest version can be downloaded from http://selenium-release.storage.googleapis.com/index.html

Tuesday, 15 July 2014

write a HYPERLINK into excel using jxl

HYPERLINK's can be written into excel using java using jxl. This will be useful to add screenshots of the web pages captured on running automated test cases through selenium

String scn = "HYPERLINK(\"D:\\snaps\\"+step_num+".jpg\",\"Click\")";
Formula link = new Formula(3,0,scn);
wws.addCell(link);


Monday, 5 May 2014

Exception in thread "main" org.openqa.selenium.WebDriverException: f.QueryInterface is not a function

While running java class file for selenium webdriver facing with the issue as below:

Exception in thread "main" org.openqa.selenium.WebDriverException: f.QueryInterface is not a function
Command duration or timeout: 30 milliseconds
Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:18:15'
System info: host: 'rgfr12321', ip: '104.43.244.18', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_45'
Session ID: 7afc8ea4-c911-4da7-a435-5f34622ca096
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, browserConnectionEnabled=true, webStorageEnabled=true, nativeEvents=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=28.0}]
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
 at java.lang.reflect.Constructor.newInstance(Unknown Source)
 at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193)
 at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
 at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:595)
 at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:300)
 at sample.Gmail.main(Gmail.java:14)
Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: f.QueryInterface is not a function
Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:18:15'
System info: host: 'rgfr12321', ip: '104.43.244.18', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_45'
Driver info: driver.version: unknown


This can be corrected by having the pull path of the url as below


Change:
WebDriver driver = new FirefoxDriver();
driver.get("www.gmail.com");

To:
WebDriver driver = new FirefoxDriver();
driver.get("http://www.gmail.com");