There's my code:
require 'builder'
def initXML(builder)
builder.instruct!
builder.results(:result => 'result'){}
end
def writeXML(builder,name,hello)
builder.test(:name => name){
builder.hello hello
}
end
builder = Builder::XmlMarkup.new(:target=> STDOUT, :indent=>4)
initXML(builder)
writeXML(builder,'name1','hello1')
writeXML(builder,'name2','hello2')
Executing that I get this XML:
<?xml version="1.0" encoding="UTF-8"?>
<results result="result">
</results>
<test name="name1">
<hello>hello1</hello>
</test>
<test name="name2">
<hello>hello2</hello>
</test>
But I want the </results> end tag at the end of file. There's a way to write inside the <results> node? Or move the </results> to the end of file? Is better to use Nokogiri? Or is better to generate my XML manually? I'm trying to use that with Watir unit testing, there's something can I use to do that to write my results on a XML file?
(Update)That's the XML I want:
<?xml version="1.0" encoding="UTF-8"?>
<results result="result">
<test name="name1">
<hello>hello1</hello>
</test>
<test name="name2">
<hello>hello2</hello>
</test>
</results>
Thanks.
It's writing precisely what you're telling it to.
Pass a block into initXML (which would be init_xml in idiomatic Ruby, IMO) and execute it. But I wouldn't call it init_xml, because what you're actually doing is wrapping XML content.
I'm not sure what you're trying to accomplish; this is easily done using normal builder semantics. If you want to return XML nodes from a method consider passing the current node to a method, perhaps. Without knowing precisely what you're trying to do, it's difficult to advise.
Related
I am running a TestNG.xml
I have created a maven project for my automation selenium script and added all the required dependencies to pom.xml. If I run the suite defined in the Testng.xml file using TestNG.run() command TestNG test result console is blank.
And please do share if there is any other way to run the testNG.xml from main() method so that I can get each test case status in testNG console
Please refer the code that I have used
TestNG testng = new TestNG();
List<String> suites = Lists.newArrayList();
suites.add(currdir+"/tempTestNG.xml");//path of xml..
testng.setTestSuites(suites);
testng.run();
Please refer the testNG.xml file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<parameter name="ExecutionType" value="Regression"/>
<listeners>
<listener class-name="config.TestListener"/>
</listeners>
<test name="Test">
<classes>
<class name="testsuits.VerificationOfWiki">
<methods>
<include name="VerifyMainpagetextonWiki"/>
<include name="VerifyRandomArticletextonWiki"/>
</methods>
</class>
</classes>
</test>
</suite>
I am trying to find xmls which are not having valid data and not process them. For example , below is a correct xml with all the data available which needs to be processes
(Loop Xpath used to read the data from xml files- Invoicing/Invoice/Serials/SerialNumber):
<?xml version='1.0' encoding='UTF-8'?>
<Invoicing>
<Invoice>
<VendorName>Contec</VendorName>
<InvoicePeriod>May</InvoicePeriod>
<InvoiceDt>2019-05-11</InvoiceDt>
<InvoiceNo>20190511</InvoiceNo>
<Serials>
<SerialNumber>
<TestLoc>HNMA01</TestLoc>
<EISSerial>PKQPLPXJC</EISSerial>
<ComcastModel>PX022ANC</ComcastModel>
<RMANo />
<ReceiptDt>05/09/2019</ReceiptDt>
<RepairDt>05/11/2019</RepairDt>
<Parts>
<Part>
<PartType>Cosmetic</PartType>
<PartId>SERVICEBUFFING</PartId>
<PartDescr>BUFF SERVC</PartDescr>
<ActionCd>RA003</ActionCd>
<FSC>FS005</FSC>
</Part>
</Parts>
</SerialNumber>
</Serials>
</Invoice>
</Invoicing>
I also get XML which are in below format,
<?xml version="1.0" encoding="UTF-8"?>
<Invoicing>
<Invoice>
<VendorName>Contec</VendorName>
<InvoicePeriod>May</InvoicePeriod>
<InvoiceDt>2017-05-01</InvoiceDt>
<InvoiceNo>20170501</InvoiceNo>
<Serials></Serials>
</Invoice>
</Invoicing>
The above xml , even though being valid is not correct..I want to identify the xmls which are in the second format without the complete data and move them into a error folder.
Thanks,
Kavin
Solution to this question is as follows :
I was able to achieve what i wanted with the solution provided by #EdMorton.
grep -L '<SerialNumber>' *.xml
But i wanted to get this done using a xml parser.
count=$(xmllint --xpath "count(//SerialNumber)" "$xml")
When the count is zero i have implemented my logic.
Thanks for all the help.
Iam using Selenium Cucumber Maven framework with Junit. I need to run the feature file in different browsers in parallel(at the same time).
Does this work if we pass browsernames like this ?
mvn test "-Dbrowser=chrome" , "-Dbrowser=firefox" through command line ?
If not please help me with a solution.
I have been asking this doubt for 2 weeks and Iam not getting any reply. It would be really great if you guys help me with a solution. Thanks in advance .
You can have a look at this post and this github project:
Basically, you can use gherkin with qaf to do something like this:
<suite name="run test in parallel Suite" parallel="tests" verbose="1" configfailurepolicy="continue" thread-count="2">
<test name="Tests in FF">
<parameter name="driver.name" value="firefoxDriver" />
<classes>
<class name="com.qmetry.qaf.automation.step.client.gherkin.GherkinScenarioFactory" />
</classes>
</test>
<test name="Tests in Chrome">
<parameter name="driver.name" value="chromeDriver"/>
<classes>
<class name="com.qmetry.qaf.automation.step.client.gherkin.GherkinScenarioFactory" />
</classes>
</test>
</suite>
Community NOTE : Since the referenced SO post does not have an accepted or upvoted answer, I could not mark this as duplicate.
In my current build.gradle, i am using below target to run a specific group through command line
test {
jvmArgs "-DisParallel=true"
useTestNG(){
suites testngxml
includeGroups System.properties['groups']
}
}
Now i want to pass multiple groups with comma separated gradlew clean test -Dgroups='group1,group2'
any help please
Why not manage this at the TestNG Suite xml file instead of trying to manage this at the Gradle build file level ?
You can make use of a BeanShell within your TestNG suite xml file, that has the ability to read the group name as a JVM argument and then parse it and run tests accordingly ?
Below is an example which accepts a group name as a JVM argument and then dynamically lets tests run if and only if they belong to the group name that was passed. You can enhance this by adding your split logic and then leveraging the same containsKey() logic.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="false">
<test name="Test">
<method-selectors>
<method-selector>
<script language="beanshell">
<![CDATA[whatGroup = System.getProperty("groups");
groups.containsKey(whatGroup);
]]>
</script>
</method-selector>
</method-selectors>
<classes>
<class name="organized.chaos.GroupsPlayGround" />
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
For more information you can refer to the following :
TestNG Documentation
My Blog post
I have a testng.xml like this :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite verbose="0" name="Selenium Parallel Aim Suite" parallel="tests" >
<test name="FB login and Screen capture" parallel="true">
<classes>
<class name="com.jm.webdriver.JTest1"/>
</classes>
</test>
<test name="Google Search" parallel="true">
<classes>
<class name="com.jm.webdriver.JTest2"/>
</classes>
</test>
</suite>
I want to launch these two test cases on say three machines 1. Windows, 2 linux 3. Mac parallelly, How to do so ?
It should be parallel = "true" for suite tag and parallel property is not required for test tags. If you are looking for grid setup then refer the seleniumhq.org documentation.