Sunday, July 14, 2019

Perform Adjust Location Inventory using Selenium Java

Perform Adjust Location Inventory using Selenium Java

Steps perform below to Adjust Location Inventory:
1. Login into IBM Sterling
2. Using IE Driver
3. Click Favorite link from Dashboard (Home page)
4. Favorite link internally search by ItemID (XRXXFL2207) in search panel
5. Get the auto Searched page
6. Click 4000-01 location from Search result
7. Select 1st record checkbox to Adjust inventory
8. Click AdjustLocationInventory button
9. Input ADJUSTMENT as ReasonCode
10. Select operation as Increase Inventory
11. Enter Quantity to increase as 10
12. Save the details
13. Close the poup window

----------------------------------------------------
InventoryAdjustment.java
----------------------------------------------------
package javaselenium;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import javaselenium.CustomRobot;

public class InventoryAdjustment {

public static void main(String[] args) throws AWTException {
   
    Robot robot = new Robot();
   
    //Creating a driver object referencing WebDriver interface
        WebDriver driver;
        
        //Setting the webdriver.ie.driver property to its executable's location
        System.setProperty("webdriver.ie.driver", "C:\\Driver\\IEDriverServer.exe");

        //Instantiating driver object
        driver = new InternetExplorerDriver();
        
        //Using get() method to open a webpage
        driver.get("http://localhost:7001/smcfs/console/login.jsp");
        
        //Maximizes the browser window
    driver.manage().window().maximize() ;
        
        // Set value to Username
        driver.findElement(By.name("UserId")).sendKeys("testuser");

        // Set value to Password
        driver.findElement(By.name("Password")).sendKeys("testuser");
        driver.manage().timeouts().implicitlyWait(5,TimeUnit.SECONDS);
        
        // Submit the Form
        driver.findElement(By.name("btnLogin")).submit(); 
               
        driver.findElement(By.linkText("Search-by-XRXXFL2207")).click();
       
        //Click Location 4000-01 from Search result
        driver.findElement(By.linkText("4000-01")).click();

        //Select checkbox from search result
        driver.findElement(By.xpath("//*[@name='chkEntityKey' and @type='checkbox' and @yHiddenInputName2='ItemKey_1']")).click();
       
        // Click AdjustLocationInventory button
        driver.findElement(By.id("scbutton2")).click();
       
        //Custom Robot instantiation logic     
        CustomRobot.typewrite("\t\t\tADJUSTMENT\t\t");
        CustomRobot.Press(KeyEvent.VK_DOWN, KeyEvent.VK_TAB);
        CustomRobot.typewrite("10");
        CustomRobot.typewrite("\t\t\t\t\t\t\t\n");
        robot.delay(3000);       
        CustomRobot.typewrite("\t\t\n");
    }

}

----------------------------------------------------
CustomRobot.java
----------------------------------------------------
package javaselenium;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;

public class CustomRobot {

public static void Press(int... keycode) throws AWTException {
Press(keycode, 0, keycode.length);
}
private static void Press(int[] keyCodes, int offset, int length) throws AWTException {
Robot robot = new Robot();
if (length == 0) {
            return;
        }

        robot.keyPress(keyCodes[offset]);
        Press(keyCodes, offset + 1, length - 1);
        robot.keyRelease(keyCodes[offset]);
    }
public static void typewrite(CharSequence characters) throws AWTException {
        int length = characters.length();
        for (int i = 0; i < length; i++) {
            char character = characters.charAt(i);
            typewrite(character);
        }
    }
public static void typewrite(char character) throws AWTException {
        switch (character) {
        case 'a': Press(KeyEvent.VK_A); break;
        case 'b': Press(KeyEvent.VK_B); break;
        case 'c': Press(KeyEvent.VK_C); break;
        case 'd': Press(KeyEvent.VK_D); break;
        case 'e': Press(KeyEvent.VK_E); break;
        case 'f': Press(KeyEvent.VK_F); break;
        case 'g': Press(KeyEvent.VK_G); break;
        case 'h': Press(KeyEvent.VK_H); break;
        case 'i': Press(KeyEvent.VK_I); break;
        case 'j': Press(KeyEvent.VK_J); break;
        case 'k': Press(KeyEvent.VK_K); break;
        case 'l': Press(KeyEvent.VK_L); break;
        case 'm': Press(KeyEvent.VK_M); break;
        case 'n': Press(KeyEvent.VK_N); break;
        case 'o': Press(KeyEvent.VK_O); break;
        case 'p': Press(KeyEvent.VK_P); break;
        case 'q': Press(KeyEvent.VK_Q); break;
        case 'r': Press(KeyEvent.VK_R); break;
        case 's': Press(KeyEvent.VK_S); break;
        case 't': Press(KeyEvent.VK_T); break;
        case 'u': Press(KeyEvent.VK_U); break;
        case 'v': Press(KeyEvent.VK_V); break;
        case 'w': Press(KeyEvent.VK_W); break;
        case 'x': Press(KeyEvent.VK_X); break;
        case 'y': Press(KeyEvent.VK_Y); break;
        case 'z': Press(KeyEvent.VK_Z); break;
        case 'A': Press(KeyEvent.VK_SHIFT, KeyEvent.VK_A); break;
        case 'B': Press(KeyEvent.VK_SHIFT, KeyEvent.VK_B); break;
        case 'C': Press(KeyEvent.VK_SHIFT, KeyEvent.VK_C); break;
        case 'D': Press(KeyEvent.VK_SHIFT, KeyEvent.VK_D); break;
        case 'E': Press(KeyEvent.VK_SHIFT, KeyEvent.VK_E); break;
        case 'F': Press(KeyEvent.VK_SHIFT, KeyEvent.VK_F); break;
        case 'G': Press(KeyEvent.VK_SHIFT, KeyEvent.VK_G); break;
        case 'H': Press(KeyEvent.VK_SHIFT, KeyEvent.VK_H); break;
        case 'I': Press(KeyEvent.VK_SHIFT, KeyEvent.VK_I); break;
        case 'J': Press(KeyEvent.VK_SHIFT, KeyEvent.VK_J); break;
        case 'K': Press(KeyEvent.VK_SHIFT, KeyEvent.VK_K); break;
        case 'L': Press(KeyEvent.VK_SHIFT, KeyEvent.VK_L); break;
        case 'M': Press(KeyEvent.VK_SHIFT, KeyEvent.VK_M); break;
        case 'N': Press(KeyEvent.VK_SHIFT, KeyEvent.VK_N); break;
        case 'O': Press(KeyEvent.VK_SHIFT, KeyEvent.VK_O); break;
        case 'P': Press(KeyEvent.VK_SHIFT, KeyEvent.VK_P); break;
        case 'Q': Press(KeyEvent.VK_SHIFT, KeyEvent.VK_Q); break;
        case 'R': Press(KeyEvent.VK_SHIFT, KeyEvent.VK_R); break;
        case 'S': Press(KeyEvent.VK_SHIFT, KeyEvent.VK_S); break;
        case 'T': Press(KeyEvent.VK_SHIFT, KeyEvent.VK_T); break;
        case 'U': Press(KeyEvent.VK_SHIFT, KeyEvent.VK_U); break;
        case 'V': Press(KeyEvent.VK_SHIFT, KeyEvent.VK_V); break;
        case 'W': Press(KeyEvent.VK_SHIFT, KeyEvent.VK_W); break;
        case 'X': Press(KeyEvent.VK_SHIFT, KeyEvent.VK_X); break;
        case 'Y': Press(KeyEvent.VK_SHIFT, KeyEvent.VK_Y); break;
        case 'Z': Press(KeyEvent.VK_SHIFT, KeyEvent.VK_Z); break;
        case '`': Press(KeyEvent.VK_BACK_QUOTE); break;
        case '0': Press(KeyEvent.VK_0); break;
        case '1': Press(KeyEvent.VK_1); break;
        case '2': Press(KeyEvent.VK_2); break;
        case '3': Press(KeyEvent.VK_3); break;
        case '4': Press(KeyEvent.VK_4); break;
        case '5': Press(KeyEvent.VK_5); break;
        case '6': Press(KeyEvent.VK_6); break;
        case '7': Press(KeyEvent.VK_7); break;
        case '8': Press(KeyEvent.VK_8); break;
        case '9': Press(KeyEvent.VK_9); break;
        case '-': Press(KeyEvent.VK_MINUS); break;
        case '=': Press(KeyEvent.VK_EQUALS); break;
        case '~': Press(KeyEvent.VK_SHIFT, KeyEvent.VK_BACK_QUOTE); break;
        case '!': Press(KeyEvent.VK_EXCLAMATION_MARK); break;
        case '@': Press(KeyEvent.VK_AT); break;
        case '#': Press(KeyEvent.VK_NUMBER_SIGN); break;
        case '$': Press(KeyEvent.VK_DOLLAR); break;
        case '%': Press(KeyEvent.VK_SHIFT, KeyEvent.VK_5); break;
        case '^': Press(KeyEvent.VK_CIRCUMFLEX); break;
        case '&': Press(KeyEvent.VK_AMPERSAND); break;
        case '*': Press(KeyEvent.VK_ASTERISK); break;
        case '(': Press(KeyEvent.VK_LEFT_PARENTHESIS); break;
        case ')': Press(KeyEvent.VK_RIGHT_PARENTHESIS); break;
        case '_': Press(KeyEvent.VK_UNDERSCORE); break;
        case '+': Press(KeyEvent.VK_PLUS); break;
        case '\t': Press(KeyEvent.VK_TAB); break;
        case '\n': Press(KeyEvent.VK_ENTER); break;
        case '[': Press(KeyEvent.VK_OPEN_BRACKET); break;
        case ']': Press(KeyEvent.VK_CLOSE_BRACKET); break;
        case '\\': Press(KeyEvent.VK_BACK_SLASH); break;
        case '{': Press(KeyEvent.VK_SHIFT, KeyEvent.VK_OPEN_BRACKET); break;
        case '}': Press(KeyEvent.VK_SHIFT, KeyEvent.VK_CLOSE_BRACKET); break;
        case '|': Press(KeyEvent.VK_SHIFT, KeyEvent.VK_BACK_SLASH); break;
        case ';': Press(KeyEvent.VK_SEMICOLON); break;
        case ':': Press(KeyEvent.VK_COLON); break;
        case '\'': Press(KeyEvent.VK_QUOTE); break;
        case '"': Press(KeyEvent.VK_QUOTEDBL); break;
        case ',': Press(KeyEvent.VK_COMMA); break;
        case '<': Press(KeyEvent.VK_SHIFT, KeyEvent.VK_COMMA); break;
        case '.': Press(KeyEvent.VK_PERIOD); break;
        case '>': Press(KeyEvent.VK_SHIFT, KeyEvent.VK_PERIOD); break;
        case '/': Press(KeyEvent.VK_SLASH); break;
        case '?': Press(KeyEvent.VK_SHIFT, KeyEvent.VK_SLASH); break;
        case ' ': Press(KeyEvent.VK_SPACE); break;
        default:
            throw new IllegalArgumentException("Cannot type character " + character);
        }
    }
 
}

No comments:

Post a Comment

Popular Posts