Hot answers tagged python
14
While it's not updated as regularly as it once was, Grig Gheorgiu's Python Testing Tools Taxonomy is considered by Pythonista's to be an excellent reference point for tools. It covers testing tools for the following uses.
Unit Testing Tools
Mock Testing Tools
Fuzz Testing Tools
Web Testing Tools
Acceptance/Business Logic Testing Tools
GUI Testing Tools
...
8
I think using selenium.webdriver.support.ui.Select is the cleanest way:
from selenium import webdriver
from selenium.webdriver.support.ui import Select, WebDriverWait
b = webdriver.Firefox()
# navigate to the page
select = Select(b.find_element_by_id(....))
print select.options
print [o.text for o in select.options] # these are string-s
...
7
I'm going with my favorite response here: it depends.
Sometimes the decision is made because that's the language the tool supports. Sometimes the language is a flavor of the language used by the development team - this often happens where there's an expectation that the development team will be writing at least some of the test automation code. Sometimes ...
7
Yes, you're on the right path (though I have a caveat or two).
More generally than "raise the right exception": The tactic is to make sure that no matter how SVN responds to your app's commands, your app responds as you wish.
For me, the biggest challenges when mocking third-party code is to characterize:
All the ways my code uses the third-party code
...
6
Burp Suite would be worth checking out if you're fuzz testing web applications. As the name implies, it's actually a suite of different web security testing tools - I used it for the first time on Monday in a pen testing workshop and it seems like a tremendously useful tool. Burp Intruder is the tool used for fuzzing attacks - and here's a video tutorial ...
4
I had only one experience of automation testing for Qt apps on Linux. The tool I used is Squish, and it supports Java, Web and Mobile testing as well. The test scripts are written in python. Just FYI. It's a commercial product, you need to buy the license.
4
The easiest way that I have found was to do something along the lines of:
el = driver.find_element_by_id('id_of_select')
for option in el.find_elements_by_tag_name('option'):
if option.text == 'The Options I Am Looking For':
option.click() # select() in earlier versions of webdriver
This may have some runtime issues if there are a large number ...
3
Nose supports parametric/generative tests, http://readthedocs.org/docs/nose/en/latest/writing_tests.html#test-generators
For example:
def checker(combination):
# do something to verify the combination
assert 'A' in combination
def test_generator():
options = ['A', 'B', 'C']
for o in options:
yield checker, o
for p in ...
3
There are times when using the Page Object Pattern makes a lot of sense and times where it doesn't make as much sense. If you have a web application where it is basically one single dynamic page then it makes less sense, however you can still use "page" objects that are really more like "section" objects for common pieces, for example if you have a Left ...
3
How do I write a script to be executed by Hudson to automatically restart test environment machines?
I think what you are looking for is the SSH plugin for Hudson:
http://wiki.hudson-ci.org/display/HUDSON/SSH+plugin
It let you run a shellscript before and/or after your build.
That's the best fit, in my opinion. But you can execute a shellscript on the Hudson server using the Post Build task plugin:
...
2
The simplest option is to just mark the line as ignored by your coverage tests. You know more than coverage.py does, you can just excuse the line from the measurements:
if __name__ == '__main__': # pragma: no cover
return main(sys.argv)
You can also use some tricks with coverage.py to get it to measure code in launched subprocesses. This sounds ...
2
I haven't used it myself (although I plan to on my side-project when I get it to private alpha stage) but I think Hexawise would be able to do some of this. You can tweak the phasing parameters (2 pairwise, 3 pairwise, I think it goes up to 6) and it will generate values in certain ranges. This should be pretty close to what you're looking to do. You can ...
2
Similar to Will's answer, but finds the <select> by its element name, and clicks based on the <option> text.
from selenium import webdriver
b = webdriver.Firefox()
b.find_element_by_xpath("//select[@name='element_name']/option[text()='option_text']").click()
2
As it happens, that isn't (as far as I can tell) the official documentation,
which is here: http://selenium.googlecode.com/svn/trunk/docs/api/py/index.html
(And which does have the full API reference.)
2
I wonder if it would be faster to use Xpaths to search specifically for cells in the row of interest, rather than fetching all rows and then manipulating the one row you are interested in. I am not fluent in Python, so I will illustrate my suggestion in pseudo-code:
for i in 1..51
condition_xpath = "//table/tr[" + i + "]/td[1]"
column1 = ...
2
Use XPATH. Install a tool like FirePath to help yourself debug this, but you'll probably want something like:
select_finder = "//tr[contains(text(), 'Mahmoud')]//a"
driver.find_element_by_xpath(select_finder).click()
where the XPATH reads something like "find a table row which contains the text "Mahmoud", then find a hyperlink inside that row"
1
If you aspire to upskill people who may not be full time developers, it may not be enough to target a single language, no matter how popular it is. A full time developer worth their salt should be able to translate any popular language to their own favorite language, but someone with less development experience may need more help getting started. If it ...
1
I haven't used the Python bindings, but as far as I know they should be equivalent to the Java ones.
If I were you I would try to find the Python equivalents of findElements() and isDisplayed() that are available in the Java bindings.
For example, I would do something similar to this:
// ...
myElementList = driver.findElements(By.Id("fancybox-close"))
if ...
1
Yes, there is another way. I call it “workarounds”
Ingredients:
1. In the separate file, define all bug numbers as contestants
cont int BUG_48484 = 48484
cont int BUG_5555 = 5555
2. Create a dictionary/hash with bug names and descriptions
MyBugList = (
*# Commented: BUG_48484 => “Application crashes”,*
BUG_5555 => “The Large Hadron Collider ...
1
I wrote a javascript snippet as follows after reading replies from the webdriver google group:
wd.execute_script("document.getElementById('allImages').value = '../uploads/b31f8a31-9d4e-49a6-b613-fb902de6a823.jpg';")
Answer from the webdriver google group:
Using the "execute_script" method is the recommended approach in this
case.
No, none in ...
1
I am not yet familiar with the python syntax, but this is what you can do:
Return all elements with the given xpath:
self.browser.find_elements_by_xpath("//input[@name='arr[]']")
Note that it is find_elements_by_xpath (plural)
Loop through the list to check all checkbox
1
Does this help ? (ops, after the trouble, I realized your issue is with Chrome) but this is working fine on Firefox 9.0.1 on Windows 7
String configFile = "/apps/configs/logins.cfg";
// server, port, userid, password defaults
String userid = "willey@customer.com";
String password = "willeyCoy0tt3";
String server = ...
1
Did you try using selenose? (this is the online document) I think this library might be the one fit you. It has something like this in setup.cfg:
[nosetests]
with-selenium-driver = true
selenium-driver = firefox
[selenium-driver:firefox]
webdriver = firefox
[selenium-driver:chrome]
webdriver = chrome
so, you can use ...
1
I suggest doing a Google search for "Python unit testing framework". A good unit testing framework will provide a way to log test results.
Alternatively, you could do a Google search for "python logging package", which would reveal APIs for generic, non-test-specific logging. If you have further questions about Python logging packages, I suggest posting ...
1
The Actions API has worked fine for me in Firefox . However, mouseover doesn't quiet work in other browsers including IE.
This is a known issue.
http://code.google.com/p/selenium/issues/detail?id=2067
I use java and have done hovers succesfully in Firefox using the code that's similar to Frank's. In addition to Frank's code, I disable the native events and ...
1
I have run into this problem multiple times, people love their dynamic rollout menus. The best way I've found to handle these (this is in java) is by using jQuery (If it's enabled on the site you are testing).
Just google jQuery and find some tutorials on adding CSS to an element. Then I used Chrome to work out a jQuery line that added the correct styles ...
1
I had similar problem.
Can you navigate from one menu to its submenu using keyboard arrows?
If you have that option:
Firefox driver = new FirefoxDriver();
(...)
By locator = By.xpath("...");
Locatable hoverItem = (Locatable) driver.findElement(locator);
Mouse mouse = ((HasInputDevices) driver).getMouse();
mouse.mouseMove(hoverItem.getCoordinates());
...
1
Are you using Remote Desktop? If you minimize or close Remote Desktop, it will send a message to Windows indicating nobody is using the computer and therefor the desktop no longer needs to be visible. That might be why your Selenium test can't find the element.
The solution there is to use VNC.
1
I am having the same problem. Tried a similar code outside the proxy and it ran without problems.
I found googling that you need to open Fiddler (http://www.fiddler2.com) before running the coded and then browsers stay and can get to the line driver.get(some url) - I couldn't previously -. But then, when getting an URL, a display is shown for Proxy ...
1
squish 4.2 using Qt will record my menu bar interactions, so you may have already done this by now but you can try the latest squish. A problem that I have is bringing the focus back to the AUT once I run the test so that I can test menu bar functionality. Squish hooks into Qt just fine but the problem is the application does not actually have focus when you ...
Only top voted, non community-wiki answers of a minimum length are eligible
