Using RobotFramework APIs for creating the testcases in Python - python

I have Automation Repository coded in Python. Now i want to use some of the RobotFramework features like, html for logs and output, xml creation. Will it be possible to use somehow the Robot features in my existing testcases written in Python Unittest library without re-writing these. Please let me know, if its the wrong way to approach this

Yes #rjha,
You can use your testcases written in python. Generally in robot framework we will import the libraries which are written in Python. Using the same concept we can use your testcases which are written in Python.
Here I'm using RED Editor in Eclipse, according to my experience to use modules which are created should be imported to your red.xml file and each method name would be your keyword and when you completed running execution from testsuite file, log.html and report.html will be generated which you want for results generation.
For Better testcase execution results import "Logging" module where you can use log.info, log.warn etc., in your testcases which will be displayed in generated html reports
enter image description here

Related

Analyze Python source code using Python and Inspector

I'm developing a static analyzer tool in Python that analyzes Python code for a given .py file and extract the body of classes, methods, etc in order to analyze code metrics (methods size, inheritance, and so on).
I identified the library "Inspect" that seems to suit me. However, I noticed that all the examples provided in the official documentation and external website only use this library by passing concrete instances of objects or functions that they want to analyze; however, I would like to analyze the source code without creating concrete instances of them, to avoid possible compiler errors due to missing library or other factors.
There is possible alternative methods or libraries that I can try to do it?

Using prolog without the pl file

My python application works well and uses swi_prolog's consult, asserts, and query functions along with a pl file. However, when I call the code via web (I get access error at consult when trying to open the pl file).
So, I thought of using the prolog without the pl file consultation. I just want to embed the pl file content into prolog in a way so that I can use it in a similar way and I can continue with the query steps. Is there anyone who can guide me in doing this?
Thanks in advance,
Ferda
The SWI-Prolog manual has a chapter on deploying applications. In particular, it allows you to create so-called saved states of your program. This mechanism allows you to create a stand-alone package from your application, either from inside the application or from the command line.

Can Python's selenium library play a test case saved as HTML

I'd like to be able to write a Django LiveServerTestCase which runs a Selenium test that has been saved as HTML using the Selenium IDE. The code might look something like this:
from django.test import LiveServerTestCase
from selenium.webdriver.firefox.webdriver import WebDriver
class TestUserStories(LiveServerTestCase):
#classmethod
def setUpClass(cls):
cls.selenium = WebDriver()
super(MySeleniumTests, cls).setUpClass()
def test_registration(self):
# Note - 'run_html_test' doesn't exist
self.selenium.run_html_test('selenium/registration.html')
This would allow our QA team (who don't speak python) to write tests using the Firefox Selenium IDE and save them as HTML. Is this possible?
As far as I can tell, HTML is the best format to save the tests in as it allows them to be edited in the IDE later on - exporting to python doesn't allow this and also generates python that needs converting to work with the Django LiveServerTestCase.
I started a project myself to build this sort of shim: to wrap existing HTML-based Selenium tests with Python, without having to convert the existing tests. It was for the same reason you state: a (client) testing team wanted to write HTML Selenium tests, but we wanted to run them using Selenium RC. Here's the link:
https://github.com/jpstacey/PySelenese
However, we mothballed the specific sub-project it was built for, so it hasn't had any attention for a long time.
With regards to your specific request, writing a standalone LiveServerTestCase isn't optimal, because you then lose Selenium's idea of having many test cases within a suite, and a suite index.html to define it. PySelenese instead wraps the whole test suite and runs all test cases within it, in the order that the Selenium IDE would run it; but I admit that the code to do that isn't currently very pretty and could be more Pythonic.
But this in theory could do what you want, so feel free to try it out, fork the github project, make your own changes etc. The PySelenese layer currently has limited support for many Selenium commands, but that's fairly extensible.
(Explicit disclaimer: PySelenese started as my own personal Github project.)

Selenium+python Reporting

I am doing some R&D on selenium+python. I wrote some test cases in python using selenium webdriver and unittest module. I want to know how can I create report of the test cases. Is there inbuilt solution available in selenium or I need to code to generate file.
Or is there any other web testing framework with javascript support available in python which have reporting functionality.
I am basically new to python as well as selenium. Just trying to explore.
To start building test reports on top of Selenium+Python, I would leverage the python unittest module. You will get a basic sample in Selenium documentation here.
Then HTMLTestRunner module combined with unittest provides basic but robust HTML reports.
Use HTMLTestRunner
Go to below URL :
http://tungwaiyip.info/software/HTMLTestRunner.html
Click on HTMLTestRunner.py
Copy all code
Create a file in your project with name HTMLTestRunner.py and dump the code
Now import that file in your script using import keyword
In main method call HTMLTestRunner
Example code:
from selenium import webdriver
import unittest
import HTMLTestRunner
class LoginTest(unittest.TestCase):
def setUp(self):
print driverpath
self.driver = webdriver.Chrome(driverpath + "chromedriver.exe")
self.driver.get("http://google.com/")
def testPythonScript(self):
driver=self.driver
driver.maximize_window()
driver.implicitly_wait(60)
driver.get_screenshot_as_file(screenshotpath + "testPngFunction.png")
driver.find_element_by_xpath("(//a[contains(#href,'contact-us')])[1]").click()
driver.find_element_by_name("name").send_keys("shubham")
driver.find_element_by_id("contactemail").send_keys("shubham.xyz#abc.com")
driver.find_element_by_css_selector("#contact_form > div:nth-child(3) > div:nth-child(3) > input").send_keys(
"389198318312")
driver.find_element_by_name("company").send_keys("myname")
driver.get_screenshot_as_file(screenshotpath + "ConatctUs.png")
print driver.title
assert "Hello" in driver.title
print "execution ends"
def testPythonFailScript(self):
driver=self.driver
driver.find_element_by_name("notExist").send_keys("done")
def tearDown(self):
driver = self.driver
driver.quit();
if __name__ == "__main__":
HTMLTestRunner.main()
Now open terminal and fire below command
python scriptFileName.py > TestReport.HTML
Note: scriptFileName is a python file name and TestReport is html report name. you can name it as you want
My experience has been that any sufficiently useful test framework will end up needing a customized logging solution. You are going to end up wanting domain specific and context relevant information, and the pre-baked solutions never really fit the bill by virtue of being specifically designed to be generic and broadly applicable. If you are already using Python, I'd suggest looking in to the logging module and learning how to write Handlers and Formatters. It's actually pretty straight forward, and you will end up getting better results than trying to shoehorn the logging you need in to some selenium-centric module.
Consider using the robot framework. It has a plugin for selenium, and robot produces very nice logs and reports. With robot you don't directly write your tests in python (though, I suppose you can). Instead, robot is a keyword-based testing system built on top of python.
Robot Framework is a functional test framework that makes it possible for its users to:
Write tests in easily understood language
Organize what tests are run for specific purposes
Generate both high level and detailed test results
RF results file
RF log file
HTML page
In my specific application I use the Nose unittest extension for writing and running test suites.
On top of that I use an html-reporting plugin that produces nice reports from my test cycles.

python nose framework: A plugin to display results in a human friendly format

Any format which is targeted for humans (.html, .doc, whatever) would be good. I cannot find any plugin that provides it
All I found was XUNIT or XML output..
I don't know of a stand-alone visualization tool, but Hudson can graph your test and coverage results. If there's a failure, it will list the problems on a web page with hyperlinks to each individual test result.
This blog post explains the setup: http://heisel.org/blog/2009/11/21/django-hudson/. There's a screenshot at the bottom that shows what's possible. It's geared toward django, but the idea is applicable to any python app.
A continuous integration server gives you many benefits beyond just graphing your test results. Hudson can automatically checkout your code after a subversion commit, run all your tests, email you if there's a failure, etc..
http://hudson-ci.org/
Nose has an html output module! (the --cover-html option). See here : http://somethingaboutorange.com/mrl/projects/nose/0.11.1/plugins/cover.html
nosetest provide a way to dump result to xunit-xml format. use options below -
--with-xunit --xunit-file <file.xml>
once you have results, you can use xslt to convert your runs to xhtml.
I tried https://github.com/mungayree/nosetest-xunit-xslt
it displays result of your runs.

Categories

Resources