I get the below exception while trying to execute testng.xml using chromedriver
Exception in thread "main" com.beust.jcommander.ParameterException: Unknown option: -protocol
I have chromedriver.exe in my local and works fine for non-testng tests. Has someone faced a similar issue.
This is nowhere related to the Chromedriver. It is the issue with the parameter named protocol` that you are not passing to the test method through the testng.xml file. For ex.
#Parameter("protocol")
#Test
void sampleTest(String protocol){
//your code
}
Expected testng.xml file
<suite name="Sample Suite">
<test name="Sample Test">
<parameter name="protocol" value="expectedvalue">
</test> <!-- test -->
</suite>
Some time to avoid this situation, we use #Optional attribute
#Parameter("protocol")
#Test
void sampleTest(#Optional("http")String protocol){
//your code
}
Related
So basically I am wondering how could I run a specific test case (a method) instead of running a whole class.
I am running tests using a combination of Selenium/Maven/TestNG. My current testing setup looks something like this:
simplified command to run tests:
mvn test -DtestSuiteName="test"
contents of test.xml used in the command above:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Selenium Testng Template">
<test name="TestSuiteTest">
<classes>
<class name="listeners.Test_Listener"/>
<class name="tests.example_test_suite_name"/>
</classes>
</test>
</suite>
What the Listener does is basically set up the enviroment for the tests, it starts a pre-configured WebDriver instance and closes it after all the tests are run. It looks something like this:
#Listeners(Listener_Helper)
class Test_Listener implements IExecutionListener {
#BeforeSuite
void openBrowser(){
prepareEnviroment()
}
#AfterSuite
void closeBrowser(){
cleanUp()
}
Now to the contents of a example test file. It consists of a class that is somewhat of a test suite, and it that contains several methods, which are somewhat of a test case.
class example_test_suite_name {
#Test(priority=1)
void test_name_one() {
//test instructions
}
#Test(priority=2)
void test_name_two() {
//test instructions
}
To summarize, It's not a problem to launch a test suite - a class, but how do I launch a single test case - one method of a class?
Let's say I only wanted to start "test_name_one" but not other methods that class contains. Unfortunately I couldn't find anything related to that on the web.
Any hint regarding this matter would be highly appreciated
You can specify test method more in xml file
<groups>
<run>
<include name="setName"></include>
</run>
</groups>
<classes>
<class name="com.journaldev.xml.TestNGXMLTest">
</class>
</classes>
Above test suite will only execute methods in setName group, so only test_setName method will be executed.
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.
I'm working in a big project, i want to run eature cucumber in parallel in different browser
I have the featuren the step definition ? the webdriverfactory and the shared preferences.
I have this method in webfactory and it works and i write the testng.xml
public WebDriver driver;
public static WebDriver get() {
WebDriver driver = null ;
System.setProperty("webdriver.chrome.driver","D:\\Drive\\chromedriver_win32\\chromedriver.exe");
driver= new ChromeDriver();
return(driver);
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="SuiteSopraHR" parallel="tests">
<test name="testie">
<!-- <parameter name="myBrowser" value="ie" /> -->
<classes>
<class name="com.driver.WebDriverFactory"/>
</classes>
</test> <!-- Test -->
<test name="testchrome">
<!-- <parameter name="myBrowser" value="chrome" /> -->
<classes>
<class name="com.driver.WebDriverFactory"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
I don't know how to change the other method because it didn't has any parameter to pass and it return a web driver.
when I have changed all the other method in other classes have a problem with it
any suggestion please.
and is the cucumber-jvm can run feature in parallel in different browser ??? or in console ???
You can indeed run Cucumber features and scenarios in parallel using Courgette-JVM
When you run your tests, you can set a System property that would target the browser you wish to use in parallel.
Another useful library to manage your driver binaries is WebDriver Binary Downloader
You can then specify the browser to use at runtime using:
System.setProperty("browser", "chrome");
or
VM option -Dbrowser="chrome"
private WebDriver driver;
public void createDriver() {
final String browser = System.getProperty("browser", "chrome").toLowerCase();
switch (browser) {
case "chrome":
WebDriverBinaryDownloader.create().downloadLatestBinaryAndConfigure(BrowserType.CHROME);
driver = new ChromeDriver();
case "firefox":
WebDriverBinaryDownloader.create().downloadLatestBinaryAndConfigure(BrowserType.FIREFOX);
driver = new FirefoxDriver();
default:
throw new RuntimeException("Invalid browser specified!");
}
}
We are using QAF-Gherkin-client, where you can configure it using one or more xml test nodes. You can run scenarios in parallel as well. You don't need to write any code for driver management or other functional testing common needs.
<suite name="AUT Test Automation" verbose="0" parallel="methods">
<test name="Tests on chrome">
<parameter name="driver.name" value="chromeDriver"/>
<classes>
<class name="com.qmetry.qaf.automation.step.client.gherkin.GherkinScenarioFactory" />
</classes>
</test>
<test name="Tests FF">
<parameter name="driver.name" value="firefoxDriver"/>
<classes>
<class name="com.qmetry.qaf.automation.step.client.gherkin.GherkinScenarioFactory" />
</classes>
</test>
</suite>
I think, you need to add switch construction in your method and parameter - type of browser from testng.xml.
Also, as I know, parallel execution will work only with a non-static Driver.
I am beginner in selenium webdriver. so for parallel execution normally we do changes in xml file like parallel="methods" thread-count="3" and my doubt is:
Is the parallel execution possible without selenium grid?
or only testNG is enough?
Yes, you may run UI tests in parallel without grid, or using only selenium grid node directly, without hub. Each thread in TestNG will open additional browser window, but you will get unpredictable issues in case when you application will manage all connections from you host as one user session.
Yes, using #Parameters ("browser") of TestNg..sample code as below...
#Parameters ("browser")
public void test(String browserName) {
if(browserName.equalsIgnoreCase("firefox")){
driver = new FirefoxDriver();
} else if (browserName.equalsIgnoreCase("chrome")){
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir")+"\\chromedriver.exe" );
driver = new ChromeDriver();
}
}
write your test after that in your testng.xml use parallel option also mention the parameter value.. sample code as below..
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite789787" parallel="tests">
<test name="FFTest98798">
<parameter name="browser" value="firefox"/>
<classes>
<class name ="crossbrowsertest.VerifyTitle" >
</class>
</classes>
</test> <!-- Test -->
<test name="ChromeTest8999">
<parameter name="browser" value="chrome"/>
<classes>
<class name ="crossbrowsertest.VerifyTitle" >
</class>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
hope this helps
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.