I’m trying to automate the process of liking YouTube Shorts videos on my channel using Cypress. So basically, my goal is to simulate a process that will look like this:
-
Open the first video (
https://www.youtube.com/shorts/iWFYaOdsoO0
). Play it for at least 10 seconds. Click on the like button. Click on the Next video button.
-
Open the next video. Play it for at least 10 seconds. Click on the like button. Click on the Next video button.
-
Repeat the process.
Obviously, this will require logging in with a YouTube account. I believe I can do that the beforeEach section*.*
Here’s what I’ve done so far:
describe('Automate Liking YouTube Shorts Videos', () => {
// Function to like a video
const likeVideo = () => {
// Wait for the like button to be visible and click it
cy.get('div.yt-spec-touch-feedback-shape__fill').first().click({ force: true });
};
// Function to click the next video button
const goToNextVideo = () => {
cy.get('button[class*="yt-spec-button-shape-next--icon-button"]').first().click({ force: true });
};
it('Likes shorts videos on my channel', () => {
// Visit the shorts section of the channel
cy.visit('https://www.youtube.com/shorts/iWFYaOdsoO0');
// Wait for the shorts to load and click on the first video
cy.get('a#thumbnail.yt-simple-endpoint.inline-block.style-scope.ytd-thumbnail').eq(0).click({ force: true });
// Loop to like and go to the next video
for (let i = 0; i < 10; i++) { // Adjust the number of videos to like
likeVideo();
cy.wait(10000); // Wait for 2 seconds before going to the next video
goToNextVideo();
cy.wait(10000); // Wait for 2 seconds for the next video to load
}
});
});
This code opens the first video page, trying to click on the like button, but never manage to do it for some reason.