How to run the local script in remote machine?
In manual testing we often used to do cross browser testing. The same thing we can do by automation using selenium webdriver. Followings are some steps to run a local script in a remote machine.
Steps:
1. Download "
selenium-server-standalone-2.*.jar" in the remote machine.
Download
from here
(If this jar is deprecated please try for a new jar.Just type selenium
standalone jar for web driver in Google for new jar)
Note: Download the jar
file in remote machine not in the local machine.
2. Open the command prompt in the remote machine and run the following command "java -jar < downloaded jar filepath>". This command will run a selenium server. If it will not able to run the selenium server, please just open this
link in browser and click on "okk".
Note: Be sure that java has been installed in the client machine. If not installed please install java first.
3. Then run the following java code from the machine from which you are going to initiate the remote machine.
import java.io.File;
import java.net.URL;
import org.openqa.selenium.OutputType;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
public class RemotelyRunningScript {
public static void main(String s[]) throws Exception {
System.out.println("coming to this only");
URL url = new URL( "http", "local host", 4444, "/wd/hub" );
DesiredCapabilities capabilities =DesiredCapabilities.firefox();
System.out.println("1");
capabilities.setJavascriptEnabled(true);
System.out.println("2");
WebDriver driver = new RemoteWebDriver(url,capabilities);
System.out.println("4");
driver.get("http://www.yahoo.com");
//File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
//FileUtils.copyFile(scrFile, new File("c:\\screenshot\\googlesearch-webdriverapi.png"));
System.out.println("opened yahoo page succesfully");
driver.quit();
}
}
Note: In place of "local host" please provide the remote IP. e.g. 192.145.12.45