I am using karma to test a controller in my angular app, the app it self works as expected but unit test throws error: unexpected request: GET views/home.html
as I got the problem is by ui-router and $httpBackend. so one approach was caching by ‘karma-preprocessor’ but what I have done is:
var MenuController, scope, $httpBackend;
// Initialize the controller and a mock scope
beforeEach(inject(function($controller, _$httpBackend_, $rootScope, menuService) {
// place here mocked dependencies
$httpBackend = _$httpBackend_;
$httpBackend.whenGET("views/header.html").respond(200,'');
$httpBackend.expectGET("http://localhost:3000/dishes").respond([{ ....
but the GET error shows for every template in my views folder.
NOW is there any way to ignore all templates and any other unexpected GET requests?
You can create a regular expression that matches all the templates requests:
httpBackend.whenGET(/views\/.*\.html/).respond(200, {}); or only
httpBackend.whenGET(/views\//).respond(200, {})
Related
I am using Mockk as my mocking framework when testing my Spring Boot Data repository interfaces.
Actually I am doing the following
every { itemRepository.saveAll(listOf(any(), any())) } returns listOf<Item>(mockk())
which should mock the following behaviour
val loot: List<Item> = itemGenerator.generateLoot(lootTable)
itemRepository.saveAll(loot)
The error message I receive is the following:
Failed matching mocking signature for
SignedCall(retValue=, isRetValueMock=true, retType=class kotlin.collections.Iterable, self=ItemRepository(#28), method=saveAll(Iterable), args=[[com.barbarus.gameserver.item.Item#ea00de, com.barbarus.gameserver.item.Item#23ca36d]], invocationStr=ItemRepository(#28).saveAll([com.barbarus.gameserver.item.Item#ea00de, com.barbarus.gameserver.item.Item#23ca36d]))
left matchers: [any(), any()]
The error message says left matchers: [any(), any()] pointing out that I somehow am not defining the expected arguments right.
I could fully define the items by real implementations in my test logic but I'd like to stick with mockk() just to keep the test code slim and fast.
However I kinda am not able to define the List<Item> with two elements using listOf(any(),any()) here. I tried other API of Mockk without any luck.
Any idea what to use in this case?
You should type the any() when you are passing into saveAll().
For instance:
import com.barbarus.gameserver.item.Item
...
every { itemRepository.saveAll(any<List<Item>>() } returns listOf<Item>(mockk())
Solution from another post
I'm trying to get pull data from http://43.248.49.97/indexEn
Normally on the browser there is a first request to the url above returns error 412, the second one is to a JS file and the third one is also to the url above and returns ok (200).
When using selenium the third request returns error 400 - Bad request instead.
I'm using Python. Any ideas on why this is happening?]
Thanks
I had the same problem with you but I found a solution which perfectly solves my problem.
Maybe your program fails because you are detected as a robot using selenium.
So here is the method to solve it or hide your identity(window.navigator.webdriver) by using JavaScript:
With CDP(Chrome Devtools-Protocol), you run the code before the frame is loaded by the JS file(detector). Therefore, use these codes to remove the "webdriver True" property:
Object.defineProperty(navigator, 'webdriver', {
get: () => undefined
})
key codes:
from selenium.webdriver import Chrome
driver = Chrome('D://chromedriver.exe')
driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
"source": """
Object.defineProperty(navigator, 'webdriver', {
get: () => undefined
})
"""
})
driver.get('http://pythonlearner.com')
However, if you upgrade your Chrome to 88 right now. The method mentioned above will be useless. Fortunately, we still have a solution (add this code)
chrome_options.add_argument("--disable-blink-features=AutomationControlled")
These codes should help you pass the JS file so that you can obtain the data. At least I successfully run my program.
I am using ChromeDriver 104.0.5112.79.0 and the solution with chrome_options.add_argument("--disable-blink-features=AutomationControlled") works for me!
I am trying to implement a fixture with multiple tests where all depend on each other
Therefore I want to clean the Database and perform login only one time from the Fixture.before Method
So it will look like this:
fixture `testProject`.page(baseUrl)
.before(async t => {
await loginPM.login()
await base.clearDB()
})
.beforeEach(async t => {
// some steps before each test
})
test 1
test 2
test 3
This scenario throws the following exception:
Error in fixture.before hook - Cannot implicitly resolve the test run in the context of which the test controller action should be executed. Use test function's 't' argument instead
Any ideas why testcafe not support calling functions from a Fixture.before Method
The fixture.before hook runs between tests and doesn't have access to the tested page. Please refer to the following help topic for details on its use: Fixture.before Method. If you need to execute test actions (click, typeText, etc) once per fixture before you start all tests, see this module: testcafe-once-hook module. Here is an example of how to use it: https://github.com/AlexKamaev/testcafe-once-hook-example.
We are looking at requiring the Kubernetes extension as a dependency for one of our extensions, so we are guaranteed that the kubectl CLI is installed ahead of time. That said, it doesn't seem to be enough to "activate" an extension in a test (though it seems to work at runtime) to bring the dependency into play.
If I have a test like this:
let extension = vscode.extensions.getExtension(extensionId);
if (extension !== null && extension !== undefined) {
extension.activate().then(() => {
assert.ok(true);
done();
});
}
And it returns this:
rejected promise not handled within 1 second: Error: Unknown dependency 'ms-kubernetes-tools.vscode-kubernetes-tools'
stack trace: Error: Unknown dependency 'ms-kubernetes-tools.vscode-kubernetes-tools'
at p._handleActivateRequest (/home/travis/build/camel-tooling/vscode-camelk/.vscode-test/vscode-1.37.1/VSCode-linux-x64/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:496:149)
at p._activateExtensions (/home/travis/build/camel-tooling/vscode-camelk/.vscode-test/vscode-1.37.1/VSCode-linux-x64/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:496:607)
at p.activateByEvent (/home/travis/build/camel-tooling/vscode-camelk/.vscode-test/vscode-1.37.1/VSCode-linux-x64/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:494:635)
at I._activateByEvent (/home/travis/build/camel-tooling/vscode-camelk/.vscode-test/vscode-1.37.1/VSCode-linux-x64/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:760:680)
at I._handleEagerExtensions (/home/travis/build/camel-tooling/vscode-camelk/.vscode-test/vscode-1.37.1/VSCode-linux-x64/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:764:710)
at define._startExtensionHost._readyToStartExtensionHost.wait.then.then (/home/travis/build/camel-tooling/vscode-camelk/.vscode-test/vscode-1.37.1/VSCode-linux-x64/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:768:386)
Is there a way to test that the dependent extension is pulled in correctly? Can we trigger an installation of the dependent extension prior to testing activate? Can we mock this somehow?
Thanks.
I'm running tests with protractor, but it seems impossible to access the JS 'window' object. I even tried adding a tag in my html file that would contain something like
var a = window.location;
and then try expect(a) but I couldn't make it work, I always get undefined references...
How should I process to access variables that are in the browser scope ?
Assuming you are using a recent version of Protractor, let's say >= 1.1.0, hopefully >= 1.3.1
Attempting to access Browser side JS code directly from Protractor won't work because Protractor runs in NodeJS and every Browser side code is executed through Selenium JsonWireProtocol.
Without further detail, a working example:
browser.get('https://angularjs.org/');
One-liner promise that, as of today, resolves to '1.3.0-rc.3'
browser.executeScript('return window.angular.version.full;');
You can use it directly in an expect statement given Protractor's expect resolves promises for you:
expect(browser.executeScript('return window.angular.version.full;')).
toEqual('1.3.0-rc.3');
Longer example passing a function instead of a string plus without expect resolving the promise for you. i.e. for more control and for doing some fancy thing with the result.
browser.driver.executeScript(function() {
return window.angular.version.full;
}).then(function(result) {
console.log('NodeJS-side console log result: ' + result);
//=> NodeJS-side console log result: 1.3.0-rc.3
});