automated-tests

Mocking response for GraphQL query resolver from ServiceObject to prevent API calls in the UnitTests

Mocking response for GraphQL query resolver from ServiceObject to prevent API calls in the UnitTests Question: Let’s assume that I have the following service object: class Foo(object): def bar(self): return [‘foo’, ‘bar’] And this is the schema: import Foo class Query(graphene.ObjectType): bar = graphene.List(lambda: graphene.String) def resolve_bar(self, info): return Foo().bar() I am trying to test …

Total answers: 2

parametrize and running a single test in pytest

parametrize and running a single test in pytest Question: How can I run a single test out of a set configured with parametrize? Let’s say I have the following test method: @pytest.mark.parametrize(PARAMETERS_LIST, PARAMETERS_VALUES) def test_my_feature(self, param1, param2, param3): “”” test doc “”” if param1 == ‘value’: assert True else: print ‘not value’ assert False I …

Total answers: 3

IF ELSE in robot framework with variables assignment

IF ELSE in robot framework with variables assignment Question: I need to execute some keywords conditionally in robot framework, but I dont know how to do it, it does not work. I tried many options, but I guess I have the “IF-ELSE” statement completely wrong.. Choose Particular Filter ${FILTER} And Uncheck All Values ${bool}= is …

Total answers: 5

Py.test: parametrize test cases from classes

Py.test: parametrize test cases from classes Question: I’m currently following this py.test example and it works out when I do not use classes, however when I introduce test cases into classes I am failing. The smallest case I managed to write is the following: import unittest import pytest class FixtureTestCase(unittest.TestCase): @pytest.mark.parametrize(“test_input,expected”, [ (“3+5”, 8), (“2+4”, …

Total answers: 4

Pytest – no tests ran

Pytest – no tests ran Question: I’m using pytest and selenium. When I try run my test script: import pytest from selenium import webdriver from pages import * from locators import * from selenium.webdriver.common.by import By import time class RegisterNewInstructor: def setup_class(cls): cls.driver = webdriver.Firefox() cls.driver.get(“http://mytest.com”) def test_01_clickBecomeTopButtom(self): page = HomePage(self.driver) page.click_become_top_button() self.assertTrue(page.check_instructor_form_page_loaded()) def teardown_class(cls): …

Total answers: 5

Django Test framework with file based Email backend server

Django Test framework with file based Email backend server Question: I have formulated test cases in Django framework. Use Case: I am using API that register user by sending them an Email and when they click on the link provided in the Email their account get activated. In my settings.py I am using EMAIL_FILE_PATH =’django.core.mail.backends.filebased.EmailBackend’ …

Total answers: 3

How to skip the rest of tests in the class if one has failed?

How to skip the rest of tests in the class if one has failed? Question: I’m creating the test cases for web-tests using Jenkins, Python, Selenium2(webdriver) and Py.test frameworks. So far I’m organizing my tests in the following structure: each Class is the Test Case and each test_ method is a Test Step. This setup …

Total answers: 9

Selenium waitForElement

Selenium waitForElement Question: How do I write the function for Selenium to wait for a table with just a class identifier in Python? I’m having a devil of a time learning to use Selenium’s Python webdriver functions. Asked By: Breedly || Source Answers: I have made good experiences using: time.sleep(seconds) webdriver.Firefox.implicitly_wait(seconds) The first one is …

Total answers: 14

Get HTML source of WebElement in Selenium WebDriver using Python

Get HTML source of WebElement in Selenium WebDriver using Python Question: I’m using the Python bindings to run Selenium WebDriver: from selenium import webdriver wd = webdriver.Firefox() I know I can grab a webelement like so: elem = wd.find_element_by_css_selector(‘#my-id’) And I know I can get the full page source with… wd.page_source But is there a …

Total answers: 19

Invoking Pylint programmatically

Invoking Pylint programmatically Question: I’d like to invoke the Pylint checker, limited to the error signalling part, as part of my unit testing. So I checked the Pylint executable script, got to the pylint.lint.Run helper class and there I got lost in a quite long __init__ function, ending with a call to sys.exit(). Anybody ever …

Total answers: 10