We can run the tests in a remote machine by using remotewebdriver. For this user needs to start a server in the remote machine where he intends to run the test. More details are here .
Once the server is started execute the below code.
DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox();
// URL remoteAddress = new URL("http://127.0.0.1:4444/wd/hub");
HttpCommandExecutor executor = new HttpCommandExecutor(new URL("http://Remote address:4444/wd/hub"));
WebDriver driver = new RemoteWebDriver(executor, desiredCapabilities);
driver.get("http://www.google.com/");
driver.quit();
We can see the firefox browser getting invoked in remote machine.
Thursday, June 30, 2011
Friday, May 13, 2011
Fucking Railways
I recently had to travel from alleppy to nagercoil. It was the worst experience i ever had. I don't remember the name of that fucking thing. Anyway it started from Alleppey by around 11:50 am. So i thought to have lunch from the train itself. I have heard that the food served by irctc is really tasty. Why i opted for this specific train bcoz was actually a super fast train.So from Alleppey the next stop will be Kayamkulam , followed by Kollam and Trivandrum.
After a half hour journey it reached some where and waited for a crossing. From there starts the worst part. As it was a really hot day i thought of drinking some water and searched the entire train for person supplying water. It was then i realized that the train had no pantry car. We waited for the crossing for about an hour. No food no water, i was really tired. Same condition for the other passengers. Finally the train started again and before another half hour journey halted for another crossing. Luckily this time it was in a railway station. So i thought of buying some water plus food from the station. But to my surprise that station had only a ticket counter and a small waiting shed. I searched outside of station but no luck. Same condition. Not even a small shop anyway near. I cursed the whole railways and i got into train. Finally out of exhaustion i slept.
After a half hour journey it reached some where and waited for a crossing. From there starts the worst part. As it was a really hot day i thought of drinking some water and searched the entire train for person supplying water. It was then i realized that the train had no pantry car. We waited for the crossing for about an hour. No food no water, i was really tired. Same condition for the other passengers. Finally the train started again and before another half hour journey halted for another crossing. Luckily this time it was in a railway station. So i thought of buying some water plus food from the station. But to my surprise that station had only a ticket counter and a small waiting shed. I searched outside of station but no luck. Same condition. Not even a small shop anyway near. I cursed the whole railways and i got into train. Finally out of exhaustion i slept.
Wednesday, May 11, 2011
Select new window using selenium
Selecting a newly opened window using selenium will me a nightmare for all who are trying to automate using selenium.
Selenium provides selectWindow(windowID) method for handling this situation. In most cases we wont get the window id. So we are forced to go with other parameters like "title= Title of newly opened page" or "name = Name of Window" etc. Most often window.open method will be provided with a window name. If so we can go for selectWindow("name=window_Name").
If both the above cases cannot be applied go for the code snippet given below.
Selenium selenium;
String new_Window = this.driver.getWindowHandle();
Set<String> wh1 = driver.getWindowHandles();
selenium.click("Link of window");
Set<String> wh2 = driver.getWindowHandles();
wh2.removeAll(wh1);
new_Window = (String) wh2.toArray()[0];
selenium.selectWindow(new_Window);
Selenium provides selectWindow(windowID) method for handling this situation. In most cases we wont get the window id. So we are forced to go with other parameters like "title= Title of newly opened page" or "name = Name of Window" etc. Most often window.open method will be provided with a window name. If so we can go for selectWindow("name=window_Name").
If both the above cases cannot be applied go for the code snippet given below.
Selenium selenium;
String new_Window = this.driver.getWindowHandle();
Set<String> wh1 = driver.getWindowHandles();
selenium.click("Link of window");
Set<String> wh2 = driver.getWindowHandles();
wh2.removeAll(wh1);
new_Window = (String) wh2.toArray()[0];
selenium.selectWindow(new_Window);
Measure it!
Did you ever wonder or check out for a tool which can be used to measure the length/width of page elements in pixels. Yes, Mozilla has got an addon "Measure it" which does the exact purpose. Just install the addon. Now a icon of "Measure it" will be rendered in the bottom left corner of status bar. Just click on it and measure the length of any page element.
Measure it is also available as a Chrome pluigin.
Measure it is also available as a Chrome pluigin.
Tuesday, April 26, 2011
Tools to check whether links are 404ing
Checking whether all links are working properly in one of the worst nightmares of a tester. Firefox has come with an addon, PINGER to check whether any link is 404ing.
After installing the addon, right click on the page to render the context menu. There will be the option "Ping All links". Click on it to check whether any links are 404ing. Once the test is run, the different links in the page will be colored based on the type of link.
Check the options of pinger addon the see the different options provided.Firefox is claiming that it is much faster than other tools. My own experience also proves the same.
After installing the addon, right click on the page to render the context menu. There will be the option "Ping All links". Click on it to check whether any links are 404ing. Once the test is run, the different links in the page will be colored based on the type of link.
Check the options of pinger addon the see the different options provided.Firefox is claiming that it is much faster than other tools. My own experience also proves the same.
Monday, April 11, 2011
Maven and Selenium
Sample pom for testng based selenium script
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Sample</groupId>
<artifactId>Sample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.6</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>5.8</version>
<classifier>jdk15</classifier>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium</artifactId>
<version>2.0b3</version>
<type>pom</type>
</dependency>
</dependencies>
</project>
Sample selenium code
package foo;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverBackedSelenium;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class MavenBackedSelenium
{
WebDriver webdriver;
WebDriverBackedSelenium selenium;
@BeforeClass
public void firstTest()
{
webdriver = new FirefoxDriver();
selenium = new WebDriverBackedSelenium(webdriver, "");
}
@Test
public void openGoogle(){
String page = "http://www.google.com";
selenium.open(page);
selenium.type("q", "water");
selenium.click("search");
}
@AfterClass
public void closeSession(){
selenium.close();
}
}
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Sample</groupId>
<artifactId>Sample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.6</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>5.8</version>
<classifier>jdk15</classifier>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium</artifactId>
<version>2.0b3</version>
<type>pom</type>
</dependency>
</dependencies>
</project>
Sample selenium code
package foo;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverBackedSelenium;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class MavenBackedSelenium
{
WebDriver webdriver;
WebDriverBackedSelenium selenium;
@BeforeClass
public void firstTest()
{
webdriver = new FirefoxDriver();
selenium = new WebDriverBackedSelenium(webdriver, "");
}
@Test
public void openGoogle(){
String page = "http://www.google.com";
selenium.open(page);
selenium.type("q", "water");
selenium.click("search");
}
@AfterClass
public void closeSession(){
selenium.close();
}
}
Monday, March 21, 2011
Hudson slave in remote windows machine
Here i am using hudson slave to run an automation script which is written using selenium. As my local machine is not having the required browser, best option before me is to use the hudson slave.
In my local machine the hudson console is opened using http://hudon_jack:8080
Steps to set up remote slave
1.Login in to remote machine.
2.Enter the following url into any browser
http://hudon_jack:8080/
If you are in some vpn or other network use the ip of the local machine.
http://local machine ip:8080/
3.From the "Manage Hudson" page click on "Manage Nodes".
4.Click on "New Node" to create a new slave node. Give a new name for node and save the settings.
5.Enter the details like "# of executers" and "remote FS root". "remote FS root" is the folder where user intends to set up the workspace. Under "Node Properties" user needs to specify the tools used for execution of the project. If maven is used specify the directory location of maven. Similar of the case of java.
There are various ways to start the slave agent. Here i will mention about starting a slave agent using jnlp.
6.Open cmd and execute this
java -jar slave.jar -jnlpUrl http://hudson_jack:8080/computer/slave_node_name/slave-agent.jnlp
Where slave_node_name is the name of the newly created slave node. Now a tcp/ip connection is established between slave and master.
slave.jar should be downloaded or it will be available in the folder assigned for slave.
Steps to run a test in slave
1. From the local machine open the hudson console.
2. Select the newly created slave job and check the radio button "Restrict where this project can be run" and give the name of the slave node just created.
In my local machine the hudson console is opened using http://hudon_jack:8080
Steps to set up remote slave
1.Login in to remote machine.
2.Enter the following url into any browser
http://hudon_jack:8080/
If you are in some vpn or other network use the ip of the local machine.
http://local machine ip:8080/
3.From the "Manage Hudson" page click on "Manage Nodes".
4.Click on "New Node" to create a new slave node. Give a new name for node and save the settings.
5.Enter the details like "# of executers" and "remote FS root". "remote FS root" is the folder where user intends to set up the workspace. Under "Node Properties" user needs to specify the tools used for execution of the project. If maven is used specify the directory location of maven. Similar of the case of java.
There are various ways to start the slave agent. Here i will mention about starting a slave agent using jnlp.
6.Open cmd and execute this
java -jar slave.jar -jnlpUrl http://hudson_jack:8080/computer/slave_node_name/slave-agent.jnlp
Where slave_node_name is the name of the newly created slave node. Now a tcp/ip connection is established between slave and master.
slave.jar should be downloaded or it will be available in the folder assigned for slave.
Steps to run a test in slave
1. From the local machine open the hudson console.
2. Select the newly created slave job and check the radio button "Restrict where this project can be run" and give the name of the slave node just created.
Subscribe to:
Posts (Atom)