Fueling Curiosity, One Insight at a Time
At Codemancers, we believe every day is an opportunity to grow. This section is where our team shares bite-sized discoveries, technical breakthroughs and fascinating nuggets of wisdom we've stumbled upon in our work.
Aug 3, 2023
JSON serialization in API responses omits fields with
We need to be mindful while handling the missing data. On the backend, use
undefined value to follow the JSON specification. According to the JSON standard, properties with undefined values are not allowed in JSON objects, these are the allowed JSON values: object, array, number, string, true, false, or null.We need to be mindful while handling the missing data. On the backend, use
null or defaults for missing data. On the frontend, ensure data is present before accessing it.Ashwani Kumar Jha
Senior System Analyst
Aug 2, 2023
Image Sprites
• Technique to reduce server requests for loading multiple images.
• Combine several small images into a single, larger image called a sprite sheet.
• Instead of loading multiple individual images separately, we can load a single sprite sheet.
• We can refer to individual images within the sprite sheet using CSS background positioning.
• Technique to reduce server requests for loading multiple images.
• Combine several small images into a single, larger image called a sprite sheet.
• Instead of loading multiple individual images separately, we can load a single sprite sheet.
• We can refer to individual images within the sprite sheet using CSS background positioning.
// let's say we want to show logos of our client
.logo {
background-image: url('client-logos-sprite.png');
background-repeat: no-repeat;
}
.client1 {
background-position: 0 0;
}
.client2 {
background-position: -100px 0;
}Ashwani Kumar Jha
Senior System Analyst
Jul 31, 2023
How to fetch and test those API endpoints which is accessible after login into the applications.
1. Launch the browser navigate to the login page using playwright
2. Enter the login credentials and submit the form to login.
3. After successful login, use playwright API to access the API endpoints.
4. Make API requests and assert the response to validate the functionality
Example of fetching API after login :
Thanks
1. Launch the browser navigate to the login page using playwright
2. Enter the login credentials and submit the form to login.
3. After successful login, use playwright API to access the API endpoints.
4. Make API requests and assert the response to validate the functionality
Example of fetching API after login :
// implementation of login test
const apiEndpointURL = "https://example.com/api/endpoint";
const apiResponse = await page.evaluate(async (url) => {
const response = await fetch(url);
return await response.json()
}, apiEndpointURL)
console.log(apiResponse)Thanks
Rishav Raj
System Analyst
Jul 26, 2023
Monkey patching in Ruby is dynamic modification of class. It means overwriting existing methods at runtime
eg:
eg:
class String
def reverse
'Reverse op blocked'
end
end
'Hello'.reverse
>> 'Reverse op blocked'Sujay
Jul 24, 2023
how to automate the OTP for cypress test
There is a package called
Package link :https://github.com/levz0r/gmail-tester
If you get the able to get the mail then you are good to go to extract OTP from the mail body after extracting otp from the mail you will able to automate the gmail OTP.
Thanks
There is a package called
gmail-tester which help use to retrieve mail from the gmail, its have lots of option like from, to, subject, mail_body etcPackage link :https://github.com/levz0r/gmail-tester
If you get the able to get the mail then you are good to go to extract OTP from the mail body after extracting otp from the mail you will able to automate the gmail OTP.
Thanks
Rishav Raj
System Analyst
Jul 20, 2023
Error Monitoring in Bugsnag works similar to Sentry and the commonly used method is
FYI: Sentry has a broader approval by developers.
EG:
bugsnag.notify() . It also takes an error object and captures it as an event. And we can set it up for different environments by using ENV (similar to sentry) or manually configure it as well.FYI: Sentry has a broader approval by developers.
EG:
try {
// Some code here
} catch (error) {
bugsnag.notify(
new Error(`Error ${error} while sending Standup popup`)
);
}Syed Sibtain
System Analyst
Jul 20, 2023
In Sentry we have two methods available,
1.
2.
captureException() and captureMessage().1.
captureException() method is used to explicitly report errors and exceptions. We can pass an Error object to captureException() to capture it as an event in Sentry.2.
captureMessage() method is used to capture a simple message for debugging purposes. Typically, messages captured with captureMessage() are not emitted as events. We can additionally add severity level to this. Available levels are "fatal", "error", "warning", "log", "info", and "debug".Syed Sibtain
System Analyst
Jul 14, 2023
Local storage does not work right off the bat when we render a web page within an App. App Dev will have to ensure that DOM storage is enable for it to work.
Vaibhav Yadav
Senior System Analyst
Jul 6, 2023
Mocking useSWR directly in test cases is a little complicated and even not recommended at some places.
So the ideal way to do it is using a library Mock Service Worker. Here are the steps that helped me solve this.
1. Create a mock server using setupServer from msw/node:
2. Start the server and after we run the test, close the server.
3. To ensure clean and isolated tests, reset the request handlers.
Now our API connections are taken care of and we can render components and run the test cases.
Resources: https://mswjs.io/
So the ideal way to do it is using a library Mock Service Worker. Here are the steps that helped me solve this.
1. Create a mock server using setupServer from msw/node:
const server = setupServer(
rest.get(`/api/channels/C04UPJ9243E/members`, (req, res, ctx) => {
return res(
ctx.json({
members: [{ name: "Sibtain", image: "abcd.jsp", id: 123 }],
})
);
})
);2. Start the server and after we run the test, close the server.
beforeAll(() => server.listen());
afterAll(() => server.close());3. To ensure clean and isolated tests, reset the request handlers.
afterEach(() => server.resetHandlers());Now our API connections are taken care of and we can render components and run the test cases.
test('render stuff, () => {
}Resources: https://mswjs.io/
Syed Sibtain
System Analyst
Jun 29, 2023
While writing Cypress test we generally create a
To retrieve the value of our environment variable, we use the
That's all we need to do locally to use the env vars in our Cypress test.
Now for CI, we can save these environment variables as Github action secrets.
To make these environment variables accessible from Github action secrets to our test, we need to keep a few things in mind.
• Add a value of
• We need to add
Happy testing!
cypress.env.json file to store the environment variables.
{
"BASE_URL": "https://company.dev.com/",
"USER_EMAIL": "ashwani@example.com",
"USER_PASSWORD": "Test@12345",
}To retrieve the value of our environment variable, we use the
Cypress.env method in the test file.
const baseUrl = Cypress.env('BASE_URL');That's all we need to do locally to use the env vars in our Cypress test.
Now for CI, we can save these environment variables as Github action secrets.
To make these environment variables accessible from Github action secrets to our test, we need to keep a few things in mind.
• Add a value of
empty string to the env vars and expose the cypress.env.json file.
{
"BASE_URL": "",
"USER_EMAIL": "",
"USER_PASSWORD": "",
}• We need to add
CYPRESS_ prefix to the env vars in the yml file.
env:
CYPRESS_BASE_URL: ${{ secrets.BASE_URL }}
CYPRESS_USER_EMAIL: ${{ secrets.USER_EMAIL }}
CYPRESS_USER_PASSWORD: ${{ secrets.USER_PASSWORD }}Happy testing!
Ashwani Kumar Jha
Senior System Analyst
Showing 43 to 45 of 82 results
Ready to Build Something Amazing?
Codemancers can bring your vision to life and help you achieve your goals
- Address
2nd Floor, Zee Plaza,
No. 1678, 27th Main Rd,
Sector 2, HSR Layout,
Bengaluru, Karnataka 560102 - Contact
hello@codemancers.com
+91-9731601276