I have 1 file with selenium tests, with baseURL in it. So now i need to find a way to launch this tests from console with URL as a parametr.
I have one local, developer and production server, so i want to run this tests without hardcode baseURL in it.
Is anyone one have some idea for this?
Waiting for your answers :3
Yes, you can create one Environment file any format would do (.xml, .xlsx, .properties etc).
Then you just mention environment specific details and parse the file. Its better if you use .xml format. In this way you can create node like configuration with parent being the environment name. In this way you can add any number of configuration for different servers.
Something like:-
XML Format:-
<environments>
<environment id="local">
<parameter>
<name>host</name>
<value>LocalURL</value>
</parameter>
</environment>
<environment id="development">
<parameter>
<name>host</name>
<value>DevelopmentURL</value>
</parameter>
</environment>
<environment id="production">
<parameter>
<name>host</name>
<value>ProductionURL</value>
</parameter>
</environment>
</environments>
Properties File Format:-
localUrl = http://local.com
developmentUrl = http://development.com
productionUrl = http://production.com
Any format you can use and write a code to parse it.
Related
this is my first post so sorry if there exists answer for a problem I 've got, but I think it is very specific.
My teammates created a very simple testing environment which tests functions in cpp project and it produces report of launched testcases to txt file which looks like this:
0 testcase1 PASS
1 testcase2 PASS
2 testcase2 FAIL
and so on
My task is to prepare an xml file from this txt and put it to Jenkins to generate pretty charts with test run.
Currently I try to parse this txt to JUnitXml file generated by Python lxml library.
Xml file from this txt looks like this:
xml
When I put it to Jenkins it produces me only result of tests which were run, in this case all tests were launched.
What am I missing in my XML file?
Do I need any external library to our test environment which would produce better xml with information about passed, failed testcases?
Cheers.
Here is what you should find in your xml report according to your report :
<testsuite skip="0" failures="1" errors="0" tests="3" name="Name of the tests">
<testcase name="testcase1" classname="This is a name to identify in which class is located the test"/>
<testcase name="testcase2" classname="This is another(or not) name to identify in which class is located the test"/>
<testcase name="testcase3" classname="This is another(or not) name to identify in which class is located the test">
<failure message="Any message of the failing output" type="You can specify the kind of error">
<![CDATA[ "Here you can put a complete stacktrace or
any log message associated with your failure" ]]>
</failure>
</testcase>
</testsuite>
You can find the description (Schema) of the JUnit XML format here
I have an xml file that I need to parse without harcoding the attributes given:
<test_machines name="Mac1">
<ip_address>192.168.0.0</ip_address>
<operating_system type="OS X" version="10.10.5">OS X version=10.10.5</operating_system>
<path_to>path</path_to>
</test_maschines>
I was able to parse the file but hadrcoded the names of nodes like ip_machines and also hardcoding the attribute names like type="OS X".
I need to find a way to parse the file without doing any of that stuff.
How do I achieve this?
Thans to all in advance!
Python has both builtin functions and very powerful third party libraries like lxml with same API to parse xml files and much more. Check them out by clicking on the links.
I'd would like to create an output file (an .CSV file, as an example)on which store all the outcomes got from a testcase set execution, where I can specify things, besides the outcome itself, such us testcase title, description, execution date/time, testcase duration, etc...
title, description, start datetime, duration (s), outcome
TC#1, My testcase #1, 2016/12/01 11:50:01, 64, BLOCKED
TC#2, My testcase #2, 2016/12/01 11:52:23, 70, PASSED
TC#3, My testcase #3, 2016/12/01 11:53:45, 90, FAILED
...
Has anyone done this before?
Any feedback about it would be appreciated.
Regards
You can run with the -r option to the run task, i.e. pysys.py run -r (to see a list of all options use pysys.py run -h). The -r option allows you to record the output of the tests, based on the writers defined in the pysysproject.xml file. This file that comes with the example projects has the below defined;
<writers>
<writer classname="XMLResultsWriter" module="pysys.writer" file="testsummary-%Y%m%d%H%M%S.xml">
<!--
Set properties on the XML test output writer class. The available properties that
can be set are the stylesheet location, whether to use file URLs in all references
to resources on the local disk, and the directory to write the output file (defaults
to the current working directory). Note that Mozilla Firefox requires the stylesheet
to be located next to the XML file when loading the file, and all references to local
resources must be as file URLs. Internet Explorer and Chrome can load the stylesheet
from any location on the local disk, but cannot load resources when referenced by a
file URL.
<property name="outputDir" value="${rootdir}"/>
<property name="stylesheet" value="./pysys-log.xsl"/>
<property name="useFileURL" value="true"/>
-->
</writer>
<!--
Add in the test results writer if straight text output is required
<writer classname="TextResultsWriter" module="pysys.writer" file="testsummary-%Y%m%d%H%M%S.log">
<property name="outputDir" value="${rootdir}"/>
</writer>
-->
<!--
Add in the JUnit results writer if output in the Apache Ant JUnit XML format is required. Use the
outputDir property to define the output directory for the JUnit test summary files (the writer will
produce one file per test into this output directory). If not specified this defaults to the current
working directory.
<writer classname="JUnitXMLResultsWriter" module="pysys.writer">
<property name="outputDir" value="${rootdir}/target/pysys-reports"/>
</writer>
-->
</writers>
So in the example above your test output would be in xml. You can have multiple writers, i.e. uncomment the TestResultsWriter and you will have both xml and log output summarizing the test results. I don't have a CSV output writer at the moment, though you can write your own one and configure your pysysproject.xml file to point to that (also please put in a feature request if you want me to add to the core package). Have a look at the implementations in the pysys.writer package as examples.
I am in a project in which I have the task to convert a text file to xml file.
But the restriction is, the file names should be same. I use element tree
module of python for this but while writing to the tree I use tree.write()
method in which I have to explicitly define / hardcode the xml filename
myself.
I want to know is there any procedure to automatically create the .xml file
with same name as the text file
the sh module provides great flexibility and may help you for what you want to do if I understand the question correctly. I have shown an example in the following:
import sh
name = "filename.xml"
new_name = name[-3] + "txt"
sh.touch(new_name)
from there you can open the created file and write directly to it.
I have this xml model.
link text
So I have to add some node (see the text commented) to this file.
How I can do it?
I have writed this partial code but it doesn't work:
xmldoc=minidom.parse(directory)
child = xmldoc.createElement("map")
for node in xmldoc.getElementsByTagName("Environment"):
node.appendChild(child)
Thanks in advance.
I downloaded your sample xml file and your code works fine. Your problem is most likely with the line: xmldoc=minidom.parse(directory), should this not be the path to the file you are trying to parse not to a directory? The parse() function parses an XML file it does not automatically parse all the XML files in a given directory.
If you change your code to something like below this should work fine:
xmldoc=minidom.parse("directory/model_template.xml")
child = xmldoc.createElement("map")
for node in xmldoc.getElementsByTagName("Environment"):
node.appendChild(child)
If you then execute the statement: print xmldoc.toxml() you will see that the map element has indeed been added to the Environment element: <Environment><map/></Environment>.