Commit 48c876a5 authored by Arsam Ali's avatar Arsam Ali

code is updated according to daraz web app

parent 0e288b34
package Upskills_Training.AccessModifiers;
public class DarazLoginPage {
// Private variables to store username and password
private String username;
private String password;
// Constructor to initialize the DarazLoginPage with username and password
public DarazLoginPage(String username, String password) {
this.username = username;
this.password = password;
}
// Public method to perform login
public boolean login() {
return validateCredentials();
}
// Private method to validate the credentials
private boolean validateCredentials() {
// Placeholder logic for demonstration purposes
return "correctUsername".equals(username) && "correctPassword".equals(password);
}
public static void main(String[] args) {
// Create an instance of DarazLoginPage
DarazLoginPage loginPage = new DarazLoginPage("correctUsername", "correctPassword");
// Attempt to login
if(loginPage.login())
{
System.out.println("password is correct");
}
else
{
System.out.println("password is failed");
}
// Change username and password
loginPage.username = "Arsam";
loginPage.password = "123";
if (loginPage.login())
{
System.out.println("password is correct");
}
else
{
System.out.println("password is failed");
}
}
}
package Upskills_Training.Class;
import java.util.Scanner;
public class DarazResetPasswordPage extends UserAccount implements Resettable {
private String resetToken;
public DarazResetPasswordPage(String userEmail)
{
super(userEmail);
}
@Override
public void resetPassword()
{
generateResetToken();
sendResetTokenByEmail();
promptUserForNewPassword();
updatePasswordInDatabase();
notifyUserOfSuccess();
}
private void generateResetToken() {
resetToken = "123456"; // In reality, use a secure token generator
System.out.println("Reset token generated: " + resetToken);
}
private void sendResetTokenByEmail() {
System.out.println("Reset token sent to: " + getUserEmail());
}
private void promptUserForNewPassword() {
System.out.println("Please enter your new password.");
}
private void updatePasswordInDatabase() {
System.out.println("Password updated in the database.");
}
private void notifyUserOfSuccess() {
System.out.println("Your password has been successfully reset.");
}
public static void main(String[] args) {
DarazResetPasswordPage darazResetPasswordPage = new DarazResetPasswordPage("abc@gmail.com");
darazResetPasswordPage.resetPassword();
}
}
package Upskills_Training.Class;
public interface Resettable {
void resetPassword();
}
package Upskills_Training.Class;
public class UserAccount {
private String userEmail;
public UserAccount(String userEmail)
{
this.userEmail = userEmail;
}
public String getUserEmail() {
return userEmail;
}
public void setUserEmail(String userEmail) {
this.userEmail = userEmail;
}
}
package Upskills_Training.Contructors;
public class ChatBoxDarazWeb {
private boolean isLoggedIn;
private String chatBoxContent;
public ChatBoxDarazWeb()
{
isLoggedIn = false; //set by default log out
this.chatBoxContent = "";
}
public ChatBoxDarazWeb(boolean isLoggedIn)
{
this.isLoggedIn = isLoggedIn;
this.chatBoxContent = isLoggedIn? " Welcome to Daraz Customer Care!" : ""; // Populate chat box if logged in
}
public void userLogin()
{
this.isLoggedIn = true;
this.chatBoxContent = "Welcome to Daraz Customer Care!";
}
public void userLogout()
{
this.isLoggedIn = false;
this.chatBoxContent = "user logout to start the chat you have to login again";
}
public String getChatBoxContent()
{
return this.chatBoxContent;
}
public static void main(String[] args) {
// Using Default Constructor
ChatBoxDarazWeb chatBoxDarazWeb = new ChatBoxDarazWeb();
System.out.println("Chat Box Content (Before Login): " + chatBoxDarazWeb.getChatBoxContent());
//After Login
chatBoxDarazWeb.userLogin();
System.out.println("Chat Box Content (After Login): " + chatBoxDarazWeb.getChatBoxContent());
//After Logout
chatBoxDarazWeb.userLogout();
System.out.println("Chat Box Content (After Logout): " + chatBoxDarazWeb.getChatBoxContent());
}
}
package Upskills_Training.DataTypes;
import java.util.ArrayList;
import java.util.List;
public class AddToCart {
//instance variable
private List<String> cart;
public AddToCart()
{
this.cart = new ArrayList<String>(); // Initialize the cart as an empty list
}
public void addToCartItems(String item)
{
cart.add(item);
System.out.println("Items are added to cart " + cart);
}
public void viewCartItems()
{
System.out.println("cart items are follows");
for (String cartItems: cart) {
System.out.println(cartItems);
}
}
public static void main(String[] args) {
AddToCart addToCart = new AddToCart();
addToCart.addToCartItems("mac");
addToCart.addToCartItems("hp");
addToCart.addToCartItems("dell");
addToCart.addToCartItems("iphone");
addToCart.viewCartItems();
}
}
package Upskills_Training.DataTypes;
public class Categories {
// @Test(groups = "smoke")
// public void test1() {
// // Test code
// }
//
// @Test(groups = "regression")
// public void test2() {
// // Test code
// }
//
// @Test(groups = {"smoke", "regression"})
// public void test3() {
// // Test code
// }
}
package Upskills_Training.Methods;
public class DarazWebPage {
public static void main(String[] args) throws InterruptedException {
DarazWebPage darazWebPage = new DarazWebPage();
darazWebPage.followUsOnSocialMedia();
}
public void followUsOnSocialMedia() throws InterruptedException {
clickOFacebook();
clickOInstagram();
Thread.sleep(2000);
System.out.println("Now you are following our Facebook and Instagram page");
}
public void clickOFacebook()
{
System.out.println("you have click on facebook ad started following");
}
public void clickOInstagram()
{
System.out.println("you have click on Instagram ad started following");
}
}
package Upskills_Training.Syntax;
import java.util.Scanner;
public class CaseSensitivity {
public static void main(String[] args) {
//=====================================================
//Daraz Login Page
// LOGIN BUTTON
//DashboardLoginButton
//=====================================================
//EMAIL & PASSWORD FIELDS
//LoginPageEmailOrNumber
//LoginPagePassword
//ResetYourPassword
//=====================================================
//FOOTER
//FooterCustomerCare
}
}
package Upskills_Training.Syntax;
public class ClassNames {
//If you are naming any class then it should be a noun and so should be named as per the goal
//Mobile
//Student
//Cat
//
//Interface Names "able should be placed with every interface"
//Readable
//Runnable
}
package Upskills_Training.Syntax;
public class Comments {
// Click on the login button
//driver.findElement(By.id("loginButton")).click();
//
// driver.findElement(By.id("submitButton")).click(); // Temporarily disable the submit button click
//Test Case Comments
/*
* Test Case: Verify login functionality with valid credentials
* Steps:
* 1. Enter valid username
* 2. Enter valid password
* 3. Click on the login button
* Expected Result: User should be logged in successfully
*/
// Define the format for date of birth (DOB) in MM/DD/YYYY format
// String dobFormat = "MM/dd/yyyy";
}
package Upskills_Training.Syntax;
public class FileNames {
//In Java, the java file name should be always the same as a public class name
// Descriptive Nouns:
//
// These class names clearly describe the object they represent.
// Customer
// Order
// Product
// FileHandler
// NetworkManager
//2. Compound Nouns:
// Use camelCase (first word lowercase, subsequent words uppercase) for compound nouns.
// WebServer
// EmailClient
// DatabaseConnection
// UserInterfaceController
// ShoppingCart
}
package Upskills_Training.Syntax;
public class Keywords {
//PUBLIC
// public class AutomationTestClass {
// public void performAutomation() {
// // Method code
// }
// }
//PRIVATE
// public class AutomationTestClass {
// private String username;
//
// private void setUsername(String username) {
// this.username = username;
// }
// }
//STATIC
// public class AutomationTestClass {
// public static void printMessage() {
// System.out.println("Hello, world!");
// }
// }
//INHERITANCE
// public class SubTestClass extends AutomationTestClass {
// // Subclass methods and variables
// }
// INHERIT WITH INTERFACE
// public class ImplementTestClass implements AutomationInterface {
// // Implementations for methods in AutomationInterface
// }
//RETURN
// public int add(int a, int b) {
// return a + b;
// }
}
package Upskills_Training.Syntax;
public class MainMethods {
// public static void main(String[] args) {
// MainMethods mainMethod = new MainMethods();
// mainMethod.runAutomation();
// }
//
// public void runAutomation() {
// System.out.println("Automation script starting...");
// }
// }
}
package Upskills_Training.Syntax;
public class MethodsName {
//Now if we do look closer a method is supposed to do something that it does contains in its body henceforth it should be a verb
//1. Verbs Describing Actions:
// Method names should clearly describe the action they perform on the object.
// calculateArea()
// openFile()
// sendData()
//2. Descriptive Phrases (For Complex Actions):
// For methods with complex functionalities, consider using a descriptive phrase.
// processOrderPayment()
// generateCustomerReport()
// connectToRemoteDatabase()
}
package Upskills_Training.Variables;
public class ExplanationOfEach {
public static void main (String [] args) {
// for (initialization; condition; update) {
// // Outer loop code
// for (initialization; condition; update) { //nested loop
// // Inner loop code
// }
// }
// int[] numericValues = {1, 2, 3, 4, 5, 6};
// for (int number:numericValues) {
// System.out.println(number);
// }
// String name = "Arsam";
//
// for (char ch:name.toCharArray()) {
//
// System.out.println(ch);
//
// }
}
}
package Upskills_Training.Variables;
public class HideButton {
private boolean isPasswordVisible; // To track the state of the password visibility
private String password; // To store the user's password
private static final String HIDE_ICON = "hide_icon.png";
private static final String SHOW_ICON = "show_icon.png";
public HideButton(String password)
{
this.password = password;
this.isPasswordVisible = false; // Initially, the password is hidden
this.isPasswordVisible = true; // the password is now visible set
}
public void toggleButtonVisibility()
{
isPasswordVisible = !isPasswordVisible;
if(isPasswordVisible)
{
System.out.println("password is now visible " + password);
System.out.println("displaying icon " + SHOW_ICON);
}
else
{
System.out.println("password is now hide ");
System.out.println("displaying icon " + HIDE_ICON);
}
}
public static void main(String[] args) {
HideButton hideButton = new HideButton("abc123");
hideButton.toggleButtonVisibility();
}
}
package Upskills_Training.Variables;
public class TypesOfVariables {
public static void main(String[] args) {
//String,int,Float,double,char,boolean
// int myNum = 5;
// float myFloatNum = 5.99f;
// char myLetter = 'D';
// boolean myBool = true;
// String myText = "Hello";
//String
String laptop = "Macbook-pro";
System.out.println(laptop);
//int
int myNumber = 200;
myNumber = 100;
System.out.println(myNumber);
//Float
float myNumberFloat = 2.3f;
System.out.println(myNumberFloat);
//char
char character = 'A';
System.out.println(character);
//boolean
boolean checkStatus = true;
System.out.println(checkStatus);
}
}
package Upskills_Training.Variables;
public class ValuesAssignments {
public static void main(String[] args) {
int num;
String name;
// Assigning values
num = 10;
name = "Java Up skills";
System.out.println("num is assigned: " + num);
System.out.println("name is assigned: " + name);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment