I have a create-react-app small project and I am trying to fetch from an yaml downloaded from SwaggerHubfile and I can't figure it out.
The structure of the project is as in the image:
I am trying to acces something that looks like this:
paths:
/users/jobs/list:
So far I tried this:
function getData () {
fetch("http://localhost/3000/data.json")
.then(data => data.json())
.then(resp => console.log(resp));
}
getData();
but it doesn't work. What can I do to fetch data from an yaml file? Or can I fetch straight from SwaggerHub by using just the url?
Related
I have a simple test I want to create in cypress that would require a test where using a settings file I would create 1 test that executes for each entry in the settings file. The file would contain user/pwd/url/elementID and be used to login for each user at a custom URL, and validate that a specific elementID is displayed, logout, and do it again - iterating through the settings file until each is tested.
I want to do something like:
forEach(URL,uname,pwd,elementID) do
cy.request(URL)
cy.get('input:uname').btn.click
cy.get('input:pwd').btn.click
cy.get(data-cy=elementID).should(be present)
cy.get(btn.logout).btn.click
I highly doubt the above code is correct - but hopefully you get the idea. Main goal is to create a simple and quick script that will quickly iterate through an array to smoke test the functionality.
You can still iterate over your test data and create a test case out of each:
[
{
url,
uname,
pwd,
elementID,
}
].forEach(testData => {
it(`Test ${testData.uname} on ${testData.url}`, () => {
// your test code
});
});
Of course the array:
[
{
url,
uname,
pwd,
elementID,
}
]
does not need to be there in the same file, you can have it somewhere separate and import it into your spec file.
Caveat: You can only visit URLs from the same origin in one test! This code will only work if all URLs you want to test are from the same origin (i.e. same
Save your data in json format and put them in Cypress folder "fixtures"
[
{"user":"username1","pwd":"pwuser1","url":"url1","elementID":"#element_name1"},
{"user":"username2","pwd":"pwuser2","url":"url2","elementID":"#element_name2"}
]
(Don't forget the # in front of the element_name id)
Then this is your smoke_test.spec.js
//fetch the parameters from the file and save them as constant "login"
const login_data = require('../fixtures/login_data.json')
//Now you can fetch the parameters using "login_data"
describe('smoke test', () => {
it('loop through login list', () => {
//we call each entry "param" and loop through the lines of the json file
cy.get(login_data).each((param) => {
cy.visit(param.url)
cy.get('#id_of_username_field').type(param.user)
cy.get('#id_of_pw_field').type(param.pwd)
//The next line is only if you have a login button
cy.get('#id_of_login_button').click()
cy.get(param.elementID).should('be.visible')
cy.get('#id_of_logout_button)
})
})
})
I'd like to use a GraphQL code snippet in an '.mdx' file:
---
title: Releasing A GitHub Action
date: "2021-03-22T12:35:16"
slug: /blog/releasing-a-github-action
description: "After using other people's GitHub Actions, I thought I'd give one a shot."
---
this is text in the .mdx file
/```graphql
mutation UpdateAllEnvironmentVariablesForSite(
$id: UUID!
$buildEnvironmentVariables: [TagInput!]!
$previewEnvironmentVariables: [TagInput!]!
) {
updateBuildEnvironmentVariablesForSite: updateEnvironmentVariablesForSite(
id: $id
environmentVariables: $buildEnvironmentVariables
runnerType: BUILDS
) {
success
message
}
updatePreviewEnvironmentVariablesForSite: updateEnvironmentVariablesForSite(
id: $id
environmentVariables: $previewEnvironmentVariables
runnerType: PREVIEW
) {
success
message
}
}
/```
Continuing to write .mdx
When I develop this, it looks fine. When I build it in Gatsby Cloud, I get the error
Encountered unknown language 'graphql'. If 'graphql' is an alias for a supported language, use the 'languageAliases' plugin option to map it to the canonical language name.
How do I get around this?
As you can see from the MDX+Gatsby docs:
Note: For now, this only works if the .mdx file exporting the query is
placed in src/pages. Exporting GraphQL queries from .mdx files that
are used for programmatic page creation in gatsby-node.js via
actions.createPage is not currently supported.
A sample working query in a .mdx file looks like:
import { graphql } from "gatsby"
# My Awesome Page
Here's a paragraph, followed by a paragraph with data!
<p>{props.data.site.siteMetadata.description}</p>
export const pageQuery = graphql`
query {
site {
siteMetadata {
description
title
}
}
}
`
In your case, I guess that your snippet won't work even outside the .mdx file in a gatsby build because you are not exporting the query or using a page-query approach. Try adapting your GraphQL query to the "common" way to see how it behaves.
Has anyone used excel to store test data while runing cypress tests? I am trying to make this work, but since I cant access the file system with browserify I cant read excel test data file. Anyone got this working? DO you have any links/code on how to get it working?
Thanks.
I realised that normal excel processing packages wont work with cypress and typescript, since u r using browserfiy. browserify will prevent you from performing file read/write operations.
as a workaround, i only read the excel file prior to browserifying it (in the plugins/index.js), and convert it into a json file and save it in the fixtures folder.
then in the support/index.js in a beforeAll hook i read the json file as a fixture and save it to an aliased variable. Now I can parse data from the aliased variable and use it where required in cypress context throughout the test. this is what worked for me.
Here is an instruction how to use excel as source for cypress tests https://medium.com/#you54f/dynamically-generate-data-in-cypress-from-csv-xlsx-7805961eff55
First you need to convert your xlsx file to json with Xlsx
import { writeFileSync } from "fs";
import * as XLSX from "xlsx";
try {
const workBook = XLSX.readFile("./testData/testData.xlsx");
const jsonData = XLSX.utils.sheet_to_json(workBook.Sheets.testData);
writeFileSync(
"./cypress/fixtures/testData.json",
JSON.stringify(jsonData, null, 4),
"utf-8"
);
} catch (e) {
throw Error(e);
}
Then import json file and loop over each row and use the data in the way you want. In this example it tries to log in to a system.
import { login } from "../support/pageObjects/login.page";
const testData = require("../fixtures/testData.json");
describe("Dynamically Generated Tests", () => {
testData.forEach((testDataRow: any) => {
const data = {
username: testDataRow.username,
password: testDataRow.password
};
context(`Generating a test for ${data.username}`, () => {
it("should fail to login for the specified details", () => {
login.visit();
login.username.type(data.username);
login.password.type(`${data.password}{enter}`);
login.errorMsg.contains("Your username is invalid!");
login.logOutButton.should("not.exist");
});
});
});
});
Is there a way to copy a file from anywhere within the source app folder to the documents directory of a device? I've been looking at the file-system plugin documentation but couldn't find anything on this topic.
Well looking through the cookbook docs, it seems you can create a reference to the devices documents folder like this:
var documents = fs.knownFolders.documents();
You can then get the file from your app with something like this(?). Where path is a reference to the file bundled in your app:
var myFile = fs.File.fromPath(path);
So you could then do something like:
// Writing text to the file.
myFile.readText()
.then(function (content) {
// Successfully read the file's content.
documents.writeText(content)
.then(function () {
// Succeeded writing to the file.
}, function (error) {
// Failed to write to the file.
});
}, function (error) {
// Failed to read from the file.
});
I build a highstock using AngularJs,
This is the code currently look like http://jsfiddle.net/j06ivy/r88yszk0/
My question is how can I returns JSON data (http link) instead of put these data below in javascript code?
$scope.chartConfig.series.push({
id: 1,
data: [
[1147651200000, 23.15],
[1147737600000, 23.01],
[1147824000000, 22.73],
[1147910400000, 22.83],
[1147996800000, 22.56],
[1148256000000, 22.88],
[1148342400000, 22.79],
[1148428800000, 23.50],
[1148515200000, 23.74],
[1148601600000, 23.72],
[1148947200000, 23.15],
[1149033600000, 22.65]
]
}, {
id: 2,
data: [
[1147651200000, 25.15],
[1147737600000, 25.01],
[1147824000000, 25.73],
[1147910400000, 25.83],
[1147996800000, 25.56],
[1148256000000, 25.88],
[1148342400000, 25.79],
[1148428800000, 25.50],
[1148515200000, 26.74],
[1148601600000, 26.72],
[1148947200000, 26.15],
[1149033600000, 26.65]
]
}
);
I try to build on my webserver
http://52.74.94.173/ivy-demo-project/highstock-json.html
I think if something wrong in here?
$scope.chartConfig.series.push({
data: jsonData
});
you can use the $http service, here are the docs: $http
place your data in a json file, then you can access you file locally like so
$http.get("../relativePathTolocalJSON/mydata.json");
your file needs to be in a legal JSON format
Your fiddle doesn't work because of several js errors - at least $http is not injected, missing parenthesis and your json file is not available from a domain other than yours.
Check this one and make sure that your json file is available and contains an array with two data series for the chart.
$http.get('http://j06ivy.tw/public/chart-data.json').success(function (jsonData) {
$scope.chartConfig.series.push({
data: jsonData
});
});