Download Ubuntu desktop ISO file (2.5GB size) : https://ubuntu.com/download/desktop
Installing virtual box Video: https://youtu.be/x5MhydijWmc
download and install virtual box :https://www.virtualbox.org/wiki/Downloads
General --> Advance --> Bidirectional both options
Network --> Adaptor --> Attached to "Bridged Adaptor"
start Ubuntu in vritualbox
go to terminal
$sudo apt-get update
$sudo apt- install openjdk-11-jdk
$java -version
from https://www.selenium.dev/downloads/ download selenium GRID Latest Stable Version
go to downloads and unzip the downloaded file
go to terminal
$cd Downloads
$ java -jar selenium-server-4.11.0.jar standalone --selenium-manager true
take the URL from CLI and launch it in the browser
add testNG dependency in maven pom.xml and ensure TestNG plugin is installed
Write test case in TestParallel.java
Run the testngGrid.xml in Eclipse.
++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
testngGrid.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite parallel="tests" name="GridSuite">
<test thread-count="5" parallel="tests" name="Chrome Test">
<parameter name="browser" value="chrome" />
<classes>
<class name="gridpkg.TestParallel" />
</classes>
</test>
<test thread-count="5" parallel="tests" name="FireFox Test">
<parameter name="browser" value="firefox" />
<classes>
<class name="gridpkg.TestParallel" />
</classes>
</test>
</suite>
++++++++++++++++++++++++++++++++++++++++++++++++++++
TestParallel.java
package grid;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class TestParallel
{
protected static ThreadLocal<RemoteWebDriver> driver = new ThreadLocal<RemoteWebDriver>();
public Capabilities cap;
public WebDriver getDriver()
{
return driver.get();
}
@Parameters({"browser"})
@Test
public void doSearch(String browser) throws MalformedURLException, InterruptedException
{
if (browser.equals("chrome"))
{
cap = new ChromeOptions();
}
else if (browser.equals("firefox"))
{
cap = new FirefoxOptions();
}
//driver.set(new RemoteWebDriver(new URL("http://192.168.0.109:4444"), cap)); // kali
driver.set(new RemoteWebDriver(new URL("http://192.168.0.107:4444"), cap)); // windows
getDriver().get("http://google.com");
System.out.println(getDriver().getTitle());
getDriver().findElement(By.name("q")).sendKeys("helloGrid : " + browser);
System.out.println(getDriver().getTitle() + " --- on browser ---" + browser);
Thread.sleep(10000);
getDriver().quit();
}
}
No comments:
Post a Comment