Monday, February 27, 2023

response to excel in jmeter

import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.*;

// Get the response data
String responseData = new String(data);

// Create a new Excel workbook
Workbook workbook = new XSSFWorkbook();

// Create a new sheet
Sheet sheet = workbook.createSheet("Sheet1");

// Create a new row
Row row = sheet.createRow(0);

// Create a new cell
Cell cell = row.createCell(0);

// Set the cell value to the response data
cell.setCellValue(responseData);

// Write the workbook to a file
FileOutputStream outputStream = new FileOutputStream("output.xlsx");
workbook.write(outputStream);
outputStream.close();

Wednesday, February 22, 2023

Python Script for Awake

 import pyautogui as gui

import time
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager


class Test:
url = r'https://gpconnect.qa.stonex.com'
url1 = r'https://www.google.com/'
username = r"murali.gandham437"
password = r"Welcometostonex2029!"

from selenium import webdriver

import pytest
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(ChromeDriverManager().install())
driver.implicitly_wait(20)

driver.implicitly_wait(10)
driver.maximize_window()
driver.get(url1)
for i in range(1000):
# gui.typewrite('Chrome', interval=0.1)
gui.press('enter')
gui.press('Backspace')
gui.click()
print('pressed entered')
gui.moveTo(400, 500)
time.sleep(10)
gui.moveTo(1000, 500)
gui.moveTo(600, 500)
gui.moveTo(400, 900)
time.sleep(10)
gui.click(100, 200)

Tuesday, February 14, 2023

Extends Reports using c# in BDD Framework

 using TechTalk.SpecFlow;

using AventStack.ExtentReports;

using AventStack.ExtentReports.Reporter;

using AventStack.ExtentReports.Gherkin.Model;

using NUnit.Framework;

using Utilities.Browser_Factory;


//[assembly: Parallelizable(ParallelScope.Fixtures)]


namespace TeamNameTestScripts.Hooks

{

    [Binding]

    public sealed class Hooks:DriverFactory

    {

        static string configTheme = "standard";

        static string configReportPath = @$"C:\AutomationResults\ExtentReport.html";

        public static string folderName = "";

        private DriverHelper _driverHelper;

        public Hooks(DriverHelper driverHelper)

        {

            _driverHelper = driverHelper;

        }


        [ThreadStatic]

        private static ExtentTest feature;

        [ThreadStatic]

        private static ExtentTest scenario;

        private static ExtentReports extentReport;

        private static readonly string base64ImageType = "base64";


        [BeforeTestRun]

        public static void InitializeReport()

        {

            //Initialize Extent report before test starts

            string workingDirectory = Environment.CurrentDirectory;

            string projectDirectory = Directory.GetParent(workingDirectory).Parent.Parent.FullName;

            folderName = "Reports" + DateTime.Now.ToString("_MM_dd_yyyy_hh_mm_tt");

            string reportPath = projectDirectory + @"\Reports\" + folderName + @"\test.html";

            //Initialize Extent report before test starts

            ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter(configReportPath);


            switch (configTheme.ToLower())

            {

                case "dark":

                    htmlReporter.Config.Theme = AventStack.ExtentReports.Reporter.Configuration.Theme.Dark;

                    break;

                case "standard":

                default:

                    htmlReporter.Config.Theme = AventStack.ExtentReports.Reporter.Configuration.Theme.Standard;

                    break;

            }


            //Attach report to reporter

            extentReport = new ExtentReports();

            extentReport.AttachReporter(htmlReporter);

        }


        [AfterTestRun]

        public static void TearDownReport()

        {

            extentReport.Flush();

        }


        [BeforeFeature]

        public static void BeforeFeature(FeatureContext featureContext)

        {

            feature = extentReport.CreateTest<Feature>(featureContext.FeatureInfo.Title);

        }


        [BeforeScenario]

        public void InitializeScenario(FeatureContext featureContext, ScenarioContext scenarioContext)

        {⁸

            _driverHelper.driver = CreateDriver();

            ScenarioContext.Current["Driver"] = _driverHelper.driver;

            _driverHelper.driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);

            _driverHelper.driver.Manage().Window.Maximize();

            scenario = feature.CreateNode<Scenario>(scenarioContext.ScenarioInfo.Title);

        }


        [AfterScenario]

        public void CleanUp(ScenarioContext scenarioContext)

        {

            //to check if we missed to implement any step

            string resultOfImplementation = scenarioContext.ScenarioExecutionStatus.ToString();


            //Pending Status

            if (resultOfImplementation == "UndefinedStep")

            {

                // Log.StepNotDefined();

            }

        }


        [AfterStep]

        public void InsertReportingSteps(ScenarioContext scenarioContext)

        {

            string stepType = scenarioContext.StepContext.StepInfo.StepDefinitionType.ToString();

            string stepInfo = scenarioContext.StepContext.StepInfo.Text;



            //to check if we missed to implement steps inside method

            string resultOfImplementation = scenarioContext.ScenarioExecutionStatus.ToString();



            if (scenarioContext.TestError == null && resultOfImplementation == "OK")

            {

                if (stepType == "Given")

                    scenario.CreateNode<Given>(stepInfo);

                else if (stepType == "When")

                    scenario.CreateNode<When>(stepInfo);

                else if (stepType == "Then")

                    scenario.CreateNode<Then>(stepInfo);

                else if (stepType == "And")

                    scenario.CreateNode<And>(stepInfo);

                else if (stepType == "But")

                    scenario.CreateNode<And>(stepInfo);

            }

            else if (scenarioContext.TestError != null)

            {

                Exception? innerException = scenarioContext.TestError.InnerException;

                string? testError = scenarioContext.TestError.Message;


                if (stepType == "Given")

                    scenario.CreateNode<Given>(stepInfo).Fail(innerException, MediaEntityBuilder.CreateScreenCaptureFromBase64String(base64ImageType).Build());

                else if (stepType == "When")

                    scenario.CreateNode<When>(stepInfo).Fail(innerException, MediaEntityBuilder.CreateScreenCaptureFromBase64String(base64ImageType).Build());

                else if (stepType == "Then")

                    scenario.CreateNode<Then>(stepInfo).Fail(testError, MediaEntityBuilder.CreateScreenCaptureFromBase64String(base64ImageType).Build());

                else if (stepType == "And")

                    scenario.CreateNode<Then>(stepInfo).Fail(testError, MediaEntityBuilder.CreateScreenCaptureFromBase64String(base64ImageType).Build());

                else if (stepType == "But")

                    scenario.CreateNode<Then>(stepInfo).Fail(testError, MediaEntityBuilder.CreateScreenCaptureFromBase64String(base64ImageType).Build());


            }

            else if (resultOfImplementation == "StepDefinitionPending")

            {

                string errorMessage = "Step Definition is not implemented!";


                if (stepType == "Given")

                    scenario.CreateNode<Given>(stepInfo).Fail(errorMessage, MediaEntityBuilder.CreateScreenCaptureFromBase64String(base64ImageType).Build());

                else if (stepType == "When")

                    scenario.CreateNode<When>(stepInfo).Fail(errorMessage, MediaEntityBuilder.CreateScreenCaptureFromBase64String(base64ImageType).Build());

                else if (stepType == "Then")

                    scenario.CreateNode<Then>(stepInfo).Fail(errorMessage, MediaEntityBuilder.CreateScreenCaptureFromBase64String(base64ImageType).Build());

                else if (stepType == "But")

                    scenario.CreateNode<Then>(stepInfo).Fail(errorMessage, MediaEntityBuilder.CreateScreenCaptureFromBase64String(base64ImageType).Build());


            }


        }


    }

}


Thursday, February 9, 2023

sample code posting snap in Instagram

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

# set up the driver
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=options)

# navigate to the Instagram website
driver.get("https://www.instagram.com/")

# log in to your account
username_input = driver.find_element_by_name("username")
username_input.send_keys("your_username")
password_input = driver.find_element_by_name("password")
password_input.send_keys("your_password")
password_input.send_keys(Keys.RETURN)

# click the camera icon to create a new post
camera_icon = driver.find_element_by_xpath("//span[@data-icon='new-post']")
camera_icon.click()

# select the photo you want to upload
photo_input = driver.find_element_by_xpath("//input[@type='file']")
photo_input.send_keys("path_to_your_photo")

# add a caption to your post
caption_input = driver.find_element_by_xpath("//textarea[@aria-label='Write a caption…']")
caption_input.send_keys("your_caption")

# share the post
share_button = driver.find_element_by_xpath("//button[text()='Share']")
share_button.click()

# close the driver
driver.quit()

Friday, February 3, 2023

Page changing example in c#

public class LoginPage
{
    private IWebDriver driver;
    private By usernameLocator = By.Id("username");
    private By passwordLocator = By.Id("password");
    private By loginButtonLocator = By.Id("login");

    public LoginPage(IWebDriver driver)
    {
        this.driver = driver;
    }

    public void EnterUsername(string username)
    {
        driver.FindElement(usernameLocator).SendKeys(username);
    }

    public void EnterPassword(string password)
    {
        driver.FindElement(passwordLocator).SendKeys(password);
    }

    public DashboardPage ClickLoginButton()
    {
        driver.FindElement(loginButtonLocator).Click();
        return new DashboardPage(driver);
    }
}

public class DashboardPage
{
    private IWebDriver driver;
    private By welcomeMessageLocator = By.Id("welcome-message");

    public DashboardPage(IWebDriver driver)
    {
        this.driver = driver;
    }

    public string GetWelcomeMessage()
    {
        return driver.FindElement(welcomeMessageLocator).Text;
    }
}

public class LoginTests
{
    private IWebDriver driver;

    [SetUp]
    public void SetUp()
    {
        driver = new ChromeDriver();
        driver.Manage().Window.Maximize();
    }

    [Test]
    public void TestSuccessfulLogin()
    {
        LoginPage loginPage = new LoginPage(driver);
        DashboardPage dashboardPage = loginPage.EnterUsername("admin")
                                               .EnterPassword("password")
                                               .ClickLoginButton();
        string welcomeMessage = dashboardPage.GetWelcomeMessage();
        Assert.AreEqual("Welcome, admin!", welcomeMessage);
    }

    [TearDown]
    public void TearDown()
    {
        driver.Quit();
    }
}