When does Selenium hub run one node at a time? I might be wrong around both selenium code and testNG xml.
I've configured TestNG.xml to run parallel threads and grid framework seems alright, hub active on 5555, http://xx.xx.xx.xx:5555/grid/console shows two nodes connected and active with IE browser. IE driver server is used to launch IE on both these nodes, selenium-server-standalone-2.35.0 is used for the grid on all nodes and hub. When I 'run as TestNG Test' on eclipse or through Jenkins via pom.xml, the script launches on node1 first and in the next run launches on node 2.
Could it be: 1. Wrong testNG.xml/selenium grid code? 2. Hub starts up with maxinstances=1, is this causing it? What's the solution to it? Tried using hubconfig.json but doesn't seem to take affect. 3. Any misconfiguration at nodes? 4. IEDriverServer or selenium server version issues? [tried 37/39 versions as well]..
TestNG.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="CO" verbose='1' parallel="tests" thread-count="10" preserve-order="true">
<test name="FI" preserve-order="true">
<parameter name="browser" value="internet explorer" />
<parameter name="port" value="5566" />
<classes>
<class name="src/test/java.clickonce.remoteFresh"/>
</classes>
</test> <!-- Test -->
<test name="Ad" preserve-order="true">
<parameter name="browser" value="internet explorer" />
<parameter name="port" value="5567" />
<classes>
<class name="src/test/java.clickonce.Admin"/>
</classes>
</test>
</suite>
<!-- Suite -->
Selenium code for grid:
#BeforeTest
public void setUp() throws IOException {
baseUrl = "http://xxx/";
nodeUrl = "http://xx.xx.xx.xx/wd/hub";
String sUrl = "http://xxx";
DesiredCapabilities capability = DesiredCapabilities.internetExplorer();
capability.setBrowserName("iexplorer");
capability.setPlatform(Platform.WINDOWS);
capability.setCapability( InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true );
capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
File file = new File("d:/IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
WebDriver WebDriverObj = new InternetExplorerDriver();
WebDriverObj.get(sUrl);
driver = new RemoteWebDriver(new URL(nodeUrl), capability);
selenium = new WebDriverBackedSelenium(driver, baseUrl);
}
Node commands -
java -jar selenium-server-standalone-2.35.0.jar - Dwebdriver.ie.driver="D:\IEDriverServer.exe" -role webdriver -hub http://
xx.xx.xx.xx:5555/grid/register -port 5566 -browser "browserName=iexplorer,platform=WINDOWS"
node 2 on 5567 port
Instead of using -role webdriver on the Node command, use -role node. Also, change the way you specify the hub and its port: change -hub http://xx.xx.xx.xx:5555/grid/register -port 5566 by -hub http://xx.xx.xx.xx/grid/register -port 5555. In the node command, you have to use the port where the hub is listening.
So, the final version of the node command will be:
java -jar selenium-server-standalone-2.35.0.jar -role node -hub http://xx.xx.xx.xx/grid/register -port 5555 -Dwebdriver.ie.driver="D:\IEDriverServer.exe" -browser "browserName=iexplorer,platform=WINDOWS"
Check what the user-data-dir switch is set to in the RemoteWebDriver arguments. If every time you launch you write to the same profile, you won't be able to launch 2 nodes at the same time.
public ChromeUserImpl(URL url) {
DesiredCapabilities cap = DesiredCapabilities.chrome();
ChromeOptions o = new ChromeOptions();
o.addArguments("user-data-dir=" <SHOULD BE DIFFERENT IN ORDER TO RUN SIMULATANOUSLY>);
o.addArguments("test-type");
o.addArguments("--start-maximized");
cap.setCapability(ChromeOptions.CAPABILITY, o);
mDriver = new RemoteWebDriver(url, cap);
}
Related
I'm stuck in running parallel execution. Need help & use-full thought.
My Driver class:
#Parameters({"environment","browser"})
#BeforeClass(alwaysRun = true)
public void startUp(String environment, String browser) {
switch (browser) {
case "firefox":
System.setProperty("webdriver.gecko.driver", "/usr/local/bin/geckodriver");
driver = new FirefoxDriver();
break;
case "chrome":
System.setProperty("webdriver.chrome.driver", "/usr/local/bin/chromedirver";
driver = new ChromeDriver();
break;
default:
driver = new FirefoxDriver();
}
switch (environment) {
case "fb":
driver.get("https://facebook.com");
break;
case "yahoo":
driver.get("https://yahoo.com");
break;
case "google":
driver.get("https://google.com");
break;
}
Xml File:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Login Feature" parallel="classes" thread-count="2">
<test name="fbe chrome" >
<parameter name="browser" value="chrome"/>
<parameter name="environment" value="google"/>
<classes><class name="framework.google.googlepage"></class></classes>
</test>
<test name="faceboo firefox">
<parameter name="browser" value="firefox"/>
<parameter name="environment" value="google"/>
<classes><class name="framework.google.googlepage"></class></classes>
</test>
</suite>
I am using page object model and extending Driver Factory to Test Class
When I use parallel= "classes" thread-count="2"
it's run 1 after another class and in a different browser. [Not together/sametime]
When I use parallel="tests" Thread-count= "2"
Both browser open at the same time, 1 browser stop working and another browser does double click, double sendkeys. Work only 1 browser with both browser sets of data.
I want to run tests parallelly with a different browser same time.
Need help as my code is not working.
I want to run a cucumber feature in different browsers;
So, now I'm able to open the 3 browsers in parallel chrome, ff and ie but they can't continue the other steps in features !
My method is :
#Parameters("myBrowser")
#BeforeClass
#Given("^openaaaBrowser<myBrowser>$")
public void openaaaBrowser(#Optional("optional value") String myBrowser) throws InterruptedException {
WebDriver driver;
if (myBrowser.equalsIgnoreCase("ie")) {
System.setProperty("webdriver.ie.driver","C:\\Driver\\IEDriverServer\\IEDriverServer_32bits.exe");
driver = new InternetExplorerDriver();
}
if (myBrowser.equalsIgnoreCase("chrome")) {
System.setProperty("webdriver.chrome.driver","D:\\Drive\\chromedriver_win32\\chromedriver.exe");
driver= new ChromeDriver();
}
if (myBrowser.equalsIgnoreCase("firefox")){
System.setProperty("webdriver.gecko.driver","D:\\Drive\\geckodriver-v0.20.0-win64\\geckodriver.exe");
driver = new FirefoxDriver();
}}
My testng.xml :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="SuiteSopraHR" parallel="tests">
<test name="testff">
<parameter name="myBrowser" value="firefox" />
<classes>
<class name="com.soprahr.foryou.automation.steps.StepDefinitionConnect"/>
</classes>
</test> <!-- Test -->
<test name="testie">
<parameter name="myBrowser" value="ie" />
<classes>
<class name="com.soprahr.foryou.automation.steps.StepDefinitionConnect"/>
</classes>
</test> <!-- Test -->
<test name="testchrome">
<parameter name="myBrowser" value="chrome" />
<classes>
<class name="com.soprahr.foryou.automation.steps.StepDefinitionConnect"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
and I have those methods
#Test(priority=1)
#When("^Open browser$")
public void openBrowser() throws InterruptedException {
StepDefinition.DRIVER.get(URL);
Thread.sleep(N_3000);
StepDefinition.waitForJQueryProcessing(StepDefinition.DRIVER, N_30);
}
#Test(priority=2)
#Then("^Se connecter à l'environnement via ID '(.*)'$")
public void letThisOneConnect(final String Id) throws Throwable {
Thread.sleep(N_3000);
Utilities utilities = new Utilities();
TestCase testCase = utilities.getMyTestCase(Id);
StepDefinition.deleteAndEnterTextById(ID_LOGIN_INPUT_4YOU, testCase.getLogInId());
StepDefinition.deleteAndEnterTextById(ID_PASSWORD_INPUT_4YOU, testCase.getLogInPassword());
StepDefinition.clickButtonById(ID_LOGIN_BUTTON_4OU);
}
The problem here and I don't understand why it can't the #test methods
If you want to run a scenario with different browsers you have to run the scenario multiple times. i.e. if you have 3 browsers then you end up with 3 scenario instances.
You can't do is run one scenario in 3 browsers.
The simplest way to get your parallelism do this to take it out of Cucumber. If you ran in series you might have
cucumber features/my_feature BROWSER=chrome
cucumber features/my_feature BROWSER=firefox
cucumber features/my_feature BROWSER=ie
Now you could use your CI platform to run each of these commands in a separate instance. Then you'll get your parallelism, and all you have to do with Cucumber is get it to use an environment variable to control which driver and browser to use.
You won't succeed in getting Cucumber to work with more than one browser for a particular scenario instance.
Trying to run parallel tests in chrome and firefox. During the execution another chrome browser is being launched instead of the firefox browser and it is being ignored. below are the versions of files being used
OS - Ubuntu 16.04 LTS,
Firefox version - 54,
gecko version - v0.18,
Chrome version -60.0.311,
Chrome Driver - 2.53
testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="AutomationSuite" parallel="tests">
<test name="TestCaratLaneInFireFox">
<parameter name="node" value="http://*******:4444/wd/hub"/>
<parameter name="browser" value="Firefox"/>
<packages>
<package name="script"/>
</packages>
</test>
<test name="TestCaratLaneInChrome">
<parameter name="node" value="http://****:4444/wd/hub"/>
<parameter name="browser" value="chrome"/>
<packages>
<package name="script"/>
</packages>
</test>
</suite>
BaseTest.Java
public class BaseTest implements IAutoConst {
public WebDriver driver;
static {
System.setProperty(CHROME_KEY, CHROME_VALUE);
System.setProperty(GECKO_KEY, GECKO_VALUE);
}
#Parameters({"node","browser"})
#BeforeMethod
public void openApplication(String node,String browser) throws MalformedURLException {
// ChromeOptions options = new ChromeOptions();
// options.addArguments("--disable-notifications");
URL system = new URL(node);
DesiredCapabilities whichBrowser = new DesiredCapabilities();
whichBrowser.setBrowserName(browser);
driver = new RemoteWebDriver(system,whichBrowser);
driver.get(URL);
driver.manage().timeouts().implicitlyWait(ITO, TimeUnit.SECONDS);
//driver.manage().window().maximize();
}
#AfterMethod
public void closeApplication() {
driver.close();
}
}
Emailable Report:
Gecko driver version which was kept in hub had a different version than in the node. Hence it stopped the Firefox from launching.
I am new to selenium,I need to run my single selenium test case in two different nodes using FIREFOX browser (selenium grid),I have started my hub using below command
java -jar selenium-server-standalone-2.32.0.jar -role hub
Node 1:
java -jar selenium-server-standalone-2.32.0.jar -role webdriver -hub http://localhost:4444/grid/register -port 9595
Node 2:
java -jar selenium-server-standalone-2.32.0.jar -role webdriver -hub http://localhost:4444/grid/register -port 8585
two nodes has been created to hub .But when i run a testcase in hub,only one node is executing the test case and the other node remain available but not executing the testcase .
2) The node is selected randomly by hub while executing the testcase.
My question:
Run testcase in both the nodes simultaneously
Nodes can be declared as follow:-
Node 1 for chrome java -Dwebdriver.chrome.driver=C:\drivers\chromedriver.exe -jar selenium-server-standalone-2.44.0.jar -role node -hub http://localhost:4444/grid/register -port 8585 -browserName=chrome
Node 2 for firefox: java -jar selenium-server-standalone-2.44.0.jar -role node -hub http://localhost:4444/grid/register -port 9595 -browserName=firefox
You need to have following testng.xml to run same test case on different browsers:-
<suite name="Selenium TestNG Suite" parallel="tests" thread-count="5">
<test name="Selenium TestNG - 1">
<parameter name="browser" value="firefox" />
<parameter name="port" value="9595" />
<classes>
<class name="grid.testcase" />
</classes>
</test>
<test name="Selenium TestNG - 2">
<parameter name="browser" value="chrome" />
<parameter name="port" value="8585" />
<classes>
<class name="grid.testcase" />
</classes>
</test>
</suite>
In your test case, write code something like this:-
package grid;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class testcase {
public WebDriver driver=null;
#Parameters({"browser","port"})
#BeforeClass
public void initialize(String browser, String port) throws MalformedURLException{
DesiredCapabilities capability= new DesiredCapabilities();
capability.setBrowserName(browser);
driver= new RemoteWebDriver(new URL("http://localhost:".concat(port).concat("/wd/hub")), capability);
}
#Test
public void testThis() throws InterruptedException {
String url="https://www.google.com";
driver.get(url);
driver.manage().window().maximize();
//do something
driver.close();
}
}
I am not sure what framework you are using. I did parallel execution using "testng" framework.
For using testng you have to add testng jar file in your project build path or if you used IDE like eclipse add testng plugin.
Then create your class with proper annotation(ie. #test).
Create testNG.xml file and configure the things.(make sure You mentioned parallel=2. the count 2 is only how many test you want to execute in parallel)
Then right click the xml file and click runas testNG..
Refer :
testng-executing-parallel-tests
parallel-execution-of-test-methods-in-testng
I am new to Grid and am trying to set up Grid 2 in Selenium RC.
I have downloaded the selenium-server-standalone-2.1.0.jar. Also I have my TestNG test cases.
And I have a test XML like:
<suite thread-count="1" name="Suite" parallel="tests" verbose="10"><!-- tests -->
<test name="FFTest" preserve-order="true">
<parameter name="selenium.host" value="localhost"></parameter>
<parameter name="selenium.port" value="5569"></parameter>
<parameter name="selenium.browser" value="*firefox"></parameter>
<parameter name="selenium.url" value="http://www.google.com"></parameter>
<classes>
<class name="EmployeeHealth.TestScripts.EmployeeHealthRegressionSuite">
<methods>
<include name="InitScript"></include>
<include name="SelectAvoidableAdmissionModule"></include>
</methods>
</class>
</classes>
</test>
<test name="IETest" preserve-order="true">
<parameter name="selenium.host" value="localhost"></parameter>
<parameter name="selenium.port" value="5579"></parameter>
<parameter name="selenium.browser" value="*iehta"></parameter>
<parameter name="selenium.url" value="http://www.google.com"></parameter>
<classes>
<class name="EmployeeHealth.TestScripts.EmployeeHealthRegressionSuite">
<methods>
<include name="InitScript"></include>
<include name="SelectAvoidableAdmissionModule"></include>
</methods>
</class>
</classes>
</test>
</suite>
And I followed the below steps:
Start Hub:
java -jar selenium-server-standalone-2.5.0.jar -role hub
Start remote control supporting Firefox
java -jar selenium-server-standalone-2.5.0.jar -role RC -hub http://localhost:4444/grid/register -browser browserName=firefox,platform=WINDOWS -port 5579
Start another RC supporting Internet explore
java -jar selenium-server-standalone-2.5.0.jar -role RC -hub http://localhost:4444/grid/register -browser browserName=iexplore,platform=WINDOWS -port 5556.
And in my SetUp.java file, Am creating the selenium objects like:
selenium = new DefaultSelenium(host,Integer.parseInt(port),
browser, url);
if ( browser.equalsIgnoreCase("*chrome")) {
RemoteControlConfiguration rcc = new RemoteControlConfiguration();
rcc.setFirefoxProfileTemplate(new File(
"test\\Resources\\ThirdParty\\FirefoxProfile\\"));
seleniumServer = new SeleniumServer(rcc);
} else {
RemoteControlConfiguration rcc = new RemoteControlConfiguration();
rcc.setFirefoxProfileTemplate(new File("Object Repository\\SSL"));
//"src\\Script\\lib\\ThirdParty\\FirefoxProfile\\"));C:\\Biju\\NewFrameworkStrcuture\\Framework\\ABC_JSAF\\
seleniumServer = new SeleniumServer(rcc);
RemoteControlConfiguration a= seleniumServer.getConfiguration();
File uimap=new File("src\\Script\\lib\\user-extensions.js");
a.setUserExtensions(uimap);
//seleniumServer = new SeleniumServer();
}
//seleniumServer.start();
selenium.start();
selenium.windowMaximize();
selenium.windowFocus();
By this way, when am running the xml file, the tests are running in sequence(First Firefox and then the IE). But not in parallel.
Also i tried giving the #Test parameter like
#Test(dataProvider="CommonTestData",threadPoolSize = 3)
But i dont see any change in the seqence.
do any one got why this is happening?..
Appreciate for your help.
A J, Thanks for the reply.
I did changes in the XML suite and I made the dataprovider function as "parallel=true" and also added the Invokation function #Test parameter "InvoationCount=2",and configure the node and am able to launch 1 IE and 1 FF parallel.
But now the problem is, in one browser(Say IE), my test cases are executing perfectly.But in the other browser(FF) ,after launching the browser, I don't see any other action performing on it.Not even opening my URL. in the console I got error :
"FAILED CONFIGURATION: #BeforeClass Seleniumstart
("localhost", "5569", "*firefox", "http://www.google.com")
com.thoughtworks.selenium.SeleniumException: ERROR Server Exception: sessionId should not be
null; has this session been started yet?"
Any idea on this?..
If you are using dataprovider, you also need to mention whether it should be called in parallel. Your CommonTestData method should have parallel=true option.
For executing using the XML, you need to increase the thread count to more than 1 for parallel execution.
It looks like your Firefox XML config tries to send the test to a node on port 5569. But in your actual client node connection string you are assigning it to use port 5579. It also looks like your IE settings attempt to use 5579 but are started with 5556.