waitForElement Not JSON Response, when trying to access button element - appium

First of all, I'm quite new to NativeScript and e2e testing, but I'm trying to get some simple tests to run on my demo application. I did the whole setup where I installed everything and an e2e (default) folder + files were created.
I have this demo app layout where I basically have one button:
<ActionBar title="My App" class="action-bar">
</ActionBar>
<GridLayout class="page">
<StackLayout>
<Button automationText="testButton" text="Button"></Button>
</StackLayout>
</GridLayout>
These are my tests:
import { AppiumDriver, createDriver, SearchOptions } from "nativescript-dev-appium";
import { assert } from "chai";
describe("sample scenario", () => {
const defaultWaitTime = 5000;
let driver: AppiumDriver;
before(async () => {
driver = await createDriver();
});
after(async () => {
await driver.quit();
console.log("Quit driver!");
});
afterEach(async function () {
if (this.currentTest.state === "failed") {
// await driver.logTestArtifacts(this.currentTest.title);
}
});
it("should find an element by text", async () => {
const btn = await driver.findElementByText("Button");
assert.isTrue(btn.exists());
});
it("should find an element by automation text", async () => {
const btn = await driver.findElementByAutomationText("testButton");
assert.isTrue(btn.exists());
});
});
I had to comment this line, otherwise, my tests wouldn't finish (I had to manually stop them with ctrl C):
// await driver.logTestArtifacts(this.currentTest.title);
I am running it with:
$ npm build ios
$ npm run e2e -- --runType sim.iPhone6
I am able to run stupid tests, assertTrue(true), but when I am trying to access an element, the button, things go wrong:
should find an element by text:
[waitForElementByXPath("//*[#label='Button' or #value='Button' or #hint='Button']",5000)] [elements("xpath","//*[#label='Button' or #value='Button' or #hint='Button']")] Not JSON response
Error: [elements("xpath","//*[#label='Button' or #value='Button' or #hint='Button']")] Not JSON response
at exports.newError (node_modules/wd/lib/utils.js:151:13)
And:
should find an element by automation text:
[waitForElementByAccessibilityId("testButton",5000)] [elements("accessibility id","testButton")] Not JSON response
Error: [elements("accessibility id","testButton")] Not JSON response
at exports.newError (node_modules/wd/lib/utils.js:151:13)
I also tried to see if the driver was just empty or something like that, but isIOS and isAndroid work fine.
I don't know if this has something do to with it but when killing the driver this error also pops up:
Error: [quit()] Unexpected data in simpleCallback.
If anybody could help that would be great! Thanks!

There seems to be a similar issue logged in at the {N} Appium Github repo, the problem seems to be the environment setup, at least in their case it was not installing carthage.
Did you go through the setup process here, made sure you have everything in place?

Related

can we use the toHaveScreenshot() and toMatchSnaphot() out side the test

Can we use the toHaveScreenshot() and toMatchSnaphot() outside the test without using config file only simple install NPM i playwright in package.json
I have already one snapshot I want to compare snapshot using toHaveScreenshot() method but I am confused we can use outside the test context?
const { chromium } =require( "playwright");
const example = async () => {
const browser = await chromium.launch({ headless: false });
const page = await browser.newPage();
await page.goto("https://zversal.com/");
await page.toHaveScreenshot("zeversal.png", {
fullPage: false,
maxDiffPixelRatio: 0.24,
});
};
example();
Console reports error:
toHaveScreenshot() must be called during the test
I don't think this is possible. Afaik, toHaveScreenshot() is part of the #playwright/test package.
If I'm looking at the Page API docs there's no toHaveScreenshot() listed. I'd say it's only available in combination with Playwright Test and it's provided expect method.
await expect(page).toHaveScreenshot();
As similarly noted by stefan judis in his answer, toHaveScreenshot is an assertion matchers method provided by expect which comes from the Playwright Test library and is made to be used inside tests.
While that assertion can’t be used, you can still take screenshots using Playwright, and then compare them manually or with another tool.
I don't know if it's possible to use it outside of testing, but you can create a PlaywrightDevPage helper class to encapsulate common operations on the page.
Simple Usage =>
// models/PlaywrightDevPage.js
class PlaywrightDevPage {
/**
* #param {import('playwright').Page} page
*/
constructor(page) {
this.page = page;
this.getStartedLink = page.locator('a', { hasText: 'Get started' });
this.gettingStartedHeader = page.locator('h1', { hasText: 'Installation' });
this.pomLink = page.locator('li', { hasText: 'Playwright Test' }).locator('a', { hasText: 'Page Object Model' });
this.tocList = page.locator('article div.markdown ul > li > a');
}
async getStarted() {
await this.getStartedLink.first().click();
await expect(this.gettingStartedHeader).toBeVisible();
}
async pageObjectModel() {
await this.getStarted();
await this.pomLink.click();
}
}
module.exports = { PlaywrightDevPage };
More Info => PlaywrightDevPage

Playwright : How to run the same test on multiple url in the same browser on different tabs and in parallel

I'm looking to run the same test for serverals url (~20) and I want to be the quickest as possible.
I would like to run my 20 tests in parallel in one browser and in a new tab (page) for each but I can't achieve it.
Here my code that open a new browser for each test :
const urlList: string[] = [
'url1',
'url2',
...
];
test.describe.parallel("Same test for multiple url", async () => {
let context;
test.beforeAll(async ({ browser }) => {
context = await browser.newContext();
});
for (const url of urlList) {
test(`${url}`, async () => {
let page = await context.newPage();
await page.goto(url);
});
}
});
This is expected. https://playwright.dev/docs/test-parallel
Every worker starts it own browser.
If you put console.log("Log Before all"): in "Before All" you will see that it will be printed 20 times, in terminal. Even maybe you will expect to execute it only once.
So you must renounce something. You will have parallel execution or you will have one browser. Think that new browsers will not border you. :-)

Debugging Worker thread in electron

I'm testing out worker_thread on an electron application. I'm currently using version 11.0.2.
The code is simple and is working and returning the sample data but I cant seem to step into the code.
Main Process:
import { Worker, isMainThread, workerData } from 'worker_threads';
config.ipcMain.on('entries:search', (evt: any, opts: any) => {
if (isMainThread) {
const pathWorker = path.join(__dirname, '../data/entries_worker.js');
const worker = new Worker(pathWorker, {
workerData: opts.value,
});
worker.on('message', (data) => {
debugger;
const d = 1;
});
worker.on('error', (data) => {
debugger;
const d = 1;
});
worker.on('exit', (data) => {
debugger;
const d = 1;
});
}
});
The worker file code:
import { workerData, parentPort } from 'worker_threads';
debugger;
parentPort.postMessage({ status: 'Done' });
I'm using Visual Studio Code and I do put breakpoints and event the debugger statement but it never seems to break into the worker file.
The message event does receive the response from the script { status: 'Done' } and the exit event returns 0.
Any ideas on how I can stop at the breakpoint in the worker file entries_worker.js?
Update
Found the following link about how it's not available right now. I'm not 100% sure if it has changed
ndb allow debugger worker thread. run in develop env like this:
"electron-dev": "ndb electron ."
When you use worker thread, you can found it easy:
You can also add breakpoints debug your code:

Spectron not visible html element

I am new with spectron and I spend a lot of time with simple example test.
I have an electron app which has loader at the beginning, and after some time it presents simple view. I want to check if header is equal "Welcome"
This is my test code:
const {Application} = require('spectron')
const chaiAsPromised = require('chai-as-promised');
describe('Application set up', function () {
this.timeout(20000)
let app;
beforeEach(async () => {
app = await new Application({
path: path-to-my-exe-electron-app
});
chaiAsPromised.transferPromiseness = app.transferPromiseness;
return app.start();
});
afterEach(async () => {
if (app && app.isRunning()) {
await app.stop();
}
});
it('example', async () => {
return app.client.waitUntilWindowLoaded()
.waitForVisible('h2', 15000)
.getText('h2')
.then(text => expect(text).toEqual('Welcome'));
})
})
And in result i got error: Error: element ("h2") still not visible after 15000ms
What do I do wrong? I spend some hours searching other spectron ways to achieve my goal, I tried adopt many solution but with no result.

My spectron app.client doesn't contains all the methods

I'm trying to test my electron app using spectron and mocha, here is my file 'first.js' containing my tests:
const assert = require('assert');
const path = require('path');
const {Application} = require('spectron');
const electronPath = require('electron');
describe('GULP Tests', function () {
this.timeout(30000)
const app = new Application({
path: electronPath,
args: [path.join(__dirname, '..', 'main.js')]
});
//Start the electron app before each test
before(() => {
return app.start();
});
//Stop the electron app after completion of each test
after(() => {
if (app && app.isRunning()) {
return app.stop();
}
});
it('Is window opened', async () => {
const count = await app.client.getWindowCount();
return assert.equal(count, 1);
});
it('Clicks on the project creation button', async () => {
await app.client.waitUntilWindowLoaded();
const title = await app.client.
console.log(title);
return assert.equal(title, 'Welcome to GULP, !');
});
});
My first test is passing, but for the second one i'd like to do a click on an element, but my app.client does not contain a .click methods, and also no getText or getHTML. I've tried to import browser from webdriverio but it was the same problem, I get an error when testing saying me that those methods doesn't exists. I've red the spectron documentation and they're using .click and .getText methods regularly, why I don't get them ? I've imported spectron as it's said in the documentation to.
Thanks.
I have struggled with the same issue for a while. After much trial and error i changed my async methods to normal functions.
it('Clicks on the project creation button', function() {
app.client.waitUntilWindowLoaded();
const title = await app.client.
console.log(title);
return assert.equal(title, 'Welcome to GULP, !');
});
Strange but it worked for me. hopefully it helps.

Resources