Selenium | Pallavi | 14th July

Discussion in 'Web App and Programming' started by Ravi T, Jul 9, 2018.

  1. Eric States

    Eric States Member

    Joined:
    Jun 25, 2018
    Messages:
    14
    Likes Received:
    1
    Thank you for clarifying. This has turned one non-working script into two working scripts. Is each row of the table in the Project Guidelines PDF to be its own script? Just so I know before I decide whether to make the "Share" tests be one script or four very similar ones- I'm thinking it's probably supposed to be four.
     
    #101
  2. Pallavi_68

    Pallavi_68 Well-Known Member

    Joined:
    Jul 9, 2018
    Messages:
    78
    Likes Received:
    0
    Thats a good observation Nygel. So for the timebeing do this, make this scenario work on Chrome, and create an excel sheet calling it as a bug sheet where you mention this deviation behaviour on FF browser and submit when you submit the project submission. hope this helps.
     
    #102
  3. Pallavi_68

    Pallavi_68 Well-Known Member

    Joined:
    Jul 9, 2018
    Messages:
    78
    Likes Received:
    0
    Eric, that will depend on the test scenario, but in this case it was two different test scripts. You need to use your experience and if you face a doubt please feel free to ask.
     
    #103
  4. Pallavi_68

    Pallavi_68 Well-Known Member

    Joined:
    Jul 9, 2018
    Messages:
    78
    Likes Received:
    0
    Looks great. I hope this is also one of the test scenarios for the Project as well. I hope you have already started working on it as well.
     
    #104
  5. Nygel De Castro

    Joined:
    Jun 19, 2018
    Messages:
    11
    Likes Received:
    0
    Thanks Pallavi,

    I will note my findings down. I am trying to ensure my scripts for the project runs fine on both browsers (chrome, firefox). I am using firefox as my main test browser because somehow chrome always leave a chromedriver.exe instance running even after I quit the script successfully but so far chrome executes all my project scripts properly.
     
    #105
  6. _34668

    _34668 Member

    Joined:
    Jul 13, 2018
    Messages:
    12
    Likes Received:
    0
    Hi Pallavi,
    Here is my assignment for buy product. I did couple of steps like back and forth like adding products first and then sign in.Sorry for that .Hope that is not a problem for logic.

    Thanks,
    Kavitha
     

    Attached Files:

    #106
  7. Pallavi_68

    Pallavi_68 Well-Known Member

    Joined:
    Jul 9, 2018
    Messages:
    78
    Likes Received:
    0
    good Nygel.
     
    #107
  8. Pallavi_68

    Pallavi_68 Well-Known Member

    Joined:
    Jul 9, 2018
    Messages:
    78
    Likes Received:
    0
    This is Okay. How many products have you bought in here? I see the while loop closes after searching product. Then you login and confirm order and then view order, so can you let me know how is this script working. Secondly assert / validate each logical action, like login, search, confirm order, etc.
     
    #108
  9. _34668

    _34668 Member

    Joined:
    Jul 13, 2018
    Messages:
    12
    Likes Received:
    0
    Hi pallavi,
    i added 4 products to cart. and then Bought the products in cart using cash on delivery. if i see order has been processed i am printing "order successful". Then went into review order/view page i compared with items in my text file to the view item page. It worked good. I see outputs one is "order successful" and also all the items i purchased ( 4 items) in console.
    Thanks,
    Kavitha
     
    #109
  10. Pallavi_68

    Pallavi_68 Well-Known Member

    Joined:
    Jul 9, 2018
    Messages:
    78
    Likes Received:
    0
    package Day7;

    import org.openqa.selenium.By;
    import org.openqa.selenium.Keys;
    import org.openqa.selenium.WebDriver;


    public class Login_Pom {
    private WebDriver driver;
    //Constructor of the class
    public Login_Pom(WebDriver driver) {
    this.driver = driver;
    }

    // The login page contains several HTML elements that will be represented as WebElements.
    // The locators for these elements should only be defined once.
    By myaccount = By.linkText("My Account");
    By usernameLocator = By.name("email_address");
    By passwordLocator = By.name("password");
    By loginButtonLocator = By.id("tdb1");

    // This will click on the MyAccount link
    public Login_Pom clickMyAccount() {
    driver.findElement(myaccount).click();
    // Return the current page object as this action doesn't navigate to a page represented by another PageObject
    return this;
    }


    // The login page allows the user to type their username into the username field
    public Login_Pom typeUsername(String username) {
    driver.findElement(usernameLocator).sendKeys(username);
    return this;
    }

    // The login page allows the user to type their password into the password field
    public Login_Pom typePassword(String password) {
    driver.findElement(passwordLocator).sendKeys(password);
    driver.findElement(passwordLocator).sendKeys(Keys.ESCAPE);
    return this;
    }

    // The login page allows the user to submit the login form
    public Login_Pom submitLogin() {
    driver.findElement(loginButtonLocator).submit();
    return this;
    }

    public boolean validateLogin(String srchTxt) {
    if (driver.getPageSource().contains(srchTxt)){
    return true;
    }else{
    return false;
    }
    }

    // Conceptually, the login page offers the user the service of being able to "log into"
    // the application using a user name and password.
    public Login_Pom loginAs(String username, String password) {
    // The PageObject methods that enter username, password & submit login have already defined and should not be repeated here.
    typeUsername(username);
    typePassword(password);
    return submitLogin();
    }
    }
     
    #110
  11. Pallavi_68

    Pallavi_68 Well-Known Member

    Joined:
    Jul 9, 2018
    Messages:
    78
    Likes Received:
    0
    package Day7;

    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;


    public class Logout_Pom {
    private WebDriver driver;

    public Logout_Pom(WebDriver driver) {
    this.driver = driver;
    }

    By logOff = By.linkText("Log Off");
    By continuelnk = By.linkText("Continue");

    public Logout_Pom clickLogOff() {
    // This is the only place that "knows" how to enter a username
    driver.findElement(logOff).click();
    return this;
    }

    public Logout_Pom clickContinue() {
    // This is the only place that "knows" how to enter a username
    driver.findElement(continuelnk).click();
    return this;
    }


    public Logout_Pom logOff() {
    clickLogOff();
    return clickContinue();
    }
    }
     
    #111
  12. Pallavi_68

    Pallavi_68 Well-Known Member

    Joined:
    Jul 9, 2018
    Messages:
    78
    Likes Received:
    0
    package Day7;

    import java.util.concurrent.TimeUnit;
    import org.junit.*;
    import org.junit.Assert;
    import org.openqa.selenium.*;
    import org.openqa.selenium.firefox.FirefoxDriver;


    public class useLogin {
    private WebDriver driver;
    private String baseUrl;

    @Before
    public void setUp() throws Exception {
    System.setProperty("webdriver.gecko.driver","resource\\geckodriver.exe"); driver = new FirefoxDriver();
    baseUrl = "http://ec2-52-14-27-1.us-east-2.compute.amazonaws.com/ethnicstore/";
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    }

    @Test
    public void test() throws Exception{
    driver.get(baseUrl);

    Login_Pom login = new Login_Pom(driver);
    Logout_Pom logout = new Logout_Pom(driver);

    login.clickMyAccount();
    login.loginAs("abc@demo.com", "demo@123");
    if( login.validateLogin("My Account Information")) {
    logout.logOff();
    }else {
    System.out.println("Invalid user credentials");
    }

    }

    @After
    public void cleanup(){
    driver.close();
    }
    }
     
    #112
  13. Pallavi_68

    Pallavi_68 Well-Known Member

    Joined:
    Jul 9, 2018
    Messages:
    78
    Likes Received:
    0
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.support.FindBy;
    import org.openqa.selenium.support.How;

    public class LoginPageFact {

    @FindBy(how=How.LINK_TEXT, using="My Account")
    public static WebElement myaccnt_link;

    @FindBy(how=How.NAME, using="email_address")
    public static WebElement username_txtbx;

    @FindBy(how=How.NAME, using="password")
    public static WebElement passwd_txtbx;

    @FindBy(how=How.ID, using="tdb1")
    public static WebElement signin_btn;
    }
     
    #113
  14. _33514

    _33514 Member

    Joined:
    Jun 29, 2018
    Messages:
    8
    Likes Received:
    0
    package session7;

    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.support.FindBy;
    import org.openqa.selenium.support.How;

    public class LogoutPageFact {

    @FindBy(how=How.LINK_TEXT, using="Log Off")
    public static WebElement logoff_link;

    @FindBy(how=How.LINK_TEXT, using="Continue")
    public static WebElement continue_link;

    }
     
    #114
  15. Pallavi_68

    Pallavi_68 Well-Known Member

    Joined:
    Jul 9, 2018
    Messages:
    78
    Likes Received:
    0
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.support.FindBy;
    import org.openqa.selenium.support.How;

    public class LogoutPageFact {

    @FindBy(how=How.LINK_TEXT, using="Log Off")
    public static WebElement logoff_link;

    @FindBy(how=How.LINK_TEXT, using="Continue")
    public static WebElement ctn_link;

    }
     
    #115
  16. Pallavi_68

    Pallavi_68 Well-Known Member

    Joined:
    Jul 9, 2018
    Messages:
    78
    Likes Received:
    0
    package Day7;

    import java.util.concurrent.TimeUnit;
    import org.junit.*;
    import org.openqa.selenium.*;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.support.PageFactory;


    public class CallLoginLogoutPF {
    private WebDriver driver;
    private String baseUrl;

    @Before
    public void beforeClass(){
    //setting the Chrome webdriver.
    System.setProperty("webdriver.chrome.driver","resource\\chromedriver.exe");//set the chrome driver
    driver = new ChromeDriver();
    baseUrl = "http://ec2-52-14-27-1.us-east-2.compute.amazonaws.com/ethnicstore/";
    //Global timeout
    driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
    }

    @Test
    public void test() throws Exception{
    driver.get(baseUrl);

    PageFactory.initElements(driver, LoginPageFact.class);
    PageFactory.initElements(driver, LogoutPageFact.class);

    LoginPageFact.myaccnt_link.click();
    LoginPageFact.username_txtbx.sendKeys("abc@demo.com");
    LoginPageFact.passwd_txtbx.sendKeys("demo@123");
    LoginPageFact.signin_btn.click();
    LogoutPageFact.logoff_link.click();
    LogoutPageFact.ctn_link.click();

    }

    @After
    public void cleanup(){
    driver.quit();
    }
    }
     
    #116
  17. Pallavi_68

    Pallavi_68 Well-Known Member

    Joined:
    Jul 9, 2018
    Messages:
    78
    Likes Received:
    0
  18. Pallavi_68

    Pallavi_68 Well-Known Member

    Joined:
    Jul 9, 2018
    Messages:
    78
    Likes Received:
    0
    Add the three jars from log4j folder to project-
    log4j-1.2-api-2.8.2
    log4j-api-2.8.2
    log4j-core-2.8.2
     
    #118
  19. Pallavi_68

    Pallavi_68 Well-Known Member

    Joined:
    Jul 9, 2018
    Messages:
    78
    Likes Received:
    0
    package Day7;

    import org.apache.log4j.Logger;

    public class Log4jExample {
    // Initialize Log4j logs
    private static Logger Log = Logger.getLogger(Log4jExample.class.getName()); //reflection.

    public static void info(String message) {
    Log.info(message);
    }

    public static void warn(String message) {
    Log.warn(message);
    }

    public static void error(String message) {
    Log.error(message);
    }

    public static void fatal(String message) {
    Log.fatal(message);
    }

    public static void debug(String message) {
    Log.debug(message);
    }
    }
     
    #119
  20. Pallavi_68

    Pallavi_68 Well-Known Member

    Joined:
    Jul 9, 2018
    Messages:
    78
    Likes Received:
    0
    package Day7;

    import org.apache.log4j.xml.DOMConfigurator;

    import Day7.Log4jExample;

    public class UseLogExample {

    public static void main(String args[]){
    DOMConfigurator.configure("log4j2.xml"); //contains meta information about log file and approach to logging
    Log4jExample.info("I am the info of the logs");
    Log4jExample.debug("I am the debug of logs");
    Log4jExample.warn("I am the warning of the logs");
    Log4jExample.error("I am the error of the logs");
    }
    }
     
    #120
  21. Pallavi_68

    Pallavi_68 Well-Known Member

    Joined:
    Jul 9, 2018
    Messages:
    78
    Likes Received:
    0
    TestNg Plugin -
    a. open Eclipse
    b. go to Help
    c. select Install New Software
    d. Type in url - http://beust.com/eclipse
     
    #121
  22. _34661

    _34661 Member

    Joined:
    Jul 13, 2018
    Messages:
    12
    Likes Received:
    1
    Hi Pallavi,

    My Machine is windows 10 operating system, Firefox Quantum 61.0.1 (64-bit) browser, and geckodriver 0.21.0.

    See below error message when I use to run my script in Firefox browser. script is not failing but seems like it is running in chrome browser.

    Console window: when script is run.
    1533433285121 geckodriver INFO geckodriver 0.21.0
    1533433285133 geckodriver INFO Listening on 127.0.0.1:23842
    1533433285335 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "-marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\ShahP\\AppData\\Local\\Temp\\rust_mozprofile.P0Ym9KqXo4ly"
    Unable to read VR Path Registry from C:\Users\ShahP\AppData\Local\openvr\openvrpaths.vrpath
    Unable to read VR Path Registry from C:\Users\ShahP\AppData\Local\openvr\openvrpaths.vrpath
    Unable to read VR Path Registry from C:\Users\ShahP\AppData\Local\openvr\openvrpaths.vrpath
    Unable to read VR Path Registry from C:\Users\ShahP\AppData\Local\openvr\openvrpaths.vrpath
    Unable to read VR Path Registry from C:\Users\ShahP\AppData\Local\openvr\openvrpaths.vrpath
    1533433287417 Marionette INFO Listening on port 52844
    1533433287484 Marionette WARN TLS certificate errors will be ignored for this session
    Aug 04, 2018 9:41:27 PM org.openqa.selenium.remote.ProtocolHandshake createSession
    INFO: Detected dialect: W3C
    No. of Rows in the WebTable: 3
    No. of Cols in the WebTable: 3
    Row 1 Column 1 Data- Turqoise Salwar
    $150.00
    Row 1 Column 2 Data- Embroided Silk Pavadai
    $100.00
    Row 1 Column 3 Data- Boys White Linen Kurta
    $50.00
    No. of Cols in the WebTable: 3
    Row 2 Column 1 Data- Boys Ethnic Wear Grey
    $150.00
    Row 2 Column 2 Data- Ishin Yellow Cotton
    $100.00
    Row 2 Column 3 Data- Ishin Purple Cotton
    $100.00
    No. of Cols in the WebTable: 3
    Row 3 Column 1 Data- Floral Cotton Sarees
    $89.00
    Row 3 Column 2 Data- Daily use Cotton Sarees
    $99.00
    Row 3 Column 3 Data- Synthetic Saree
    $150.00
    [Child 7548, Chrome_ChildThread] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346
    [Child 7548, Chrome_ChildThread] WARNING: pipe error: 1[Parent 8424, Gecko_IOThread] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346
    [Child 9596, Chrome_ChildThread] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346
    [Child 9596, Chrome_Child*** UTM:SVC TimerManager:registerTimer called after profile-before-change notification. Ignoring timer registration for id: telemetry_modules_ping
    [GPU 9808, Chrome_ChildThread] WARNING: pipe e
    ###!!! [Child][MessageChannel::SendAndWait] Error: Channel error: cannot send/recv
     
    #122
  23. Pallavi_68

    Pallavi_68 Well-Known Member

    Joined:
    Jul 9, 2018
    Messages:
    78
    Likes Received:
    0
    There is no Error Pinky See this output -

    No. of Rows in the WebTable: 3
    No. of Cols in the WebTable: 3
    Row 1 Column 1 Data- Turqoise Salwar
    $150.00
    Row 1 Column 2 Data- Embroided Silk Pavadai
    $100.00
    Row 1 Column 3 Data- Boys White Linen Kurta
    $50.00
    No. of Cols in the WebTable: 3
    Row 2 Column 1 Data- Boys Ethnic Wear Grey
    $150.00
    Row 2 Column 2 Data- Ishin Yellow Cotton
    $100.00
    Row 2 Column 3 Data- Ishin Purple Cotton
    $100.00
    No. of Cols in the WebTable: 3
    Row 3 Column 1 Data- Floral Cotton Sarees
    $89.00
    Row 3 Column 2 Data- Daily use Cotton Sarees
    $99.00
    Row 3 Column 3 Data- Synthetic Saree
    $150.00

    your script is working just fine.
     
    #123
  24. Pallavi_68

    Pallavi_68 Well-Known Member

    Joined:
    Jul 9, 2018
    Messages:
    78
    Likes Received:
    0
    The code, and notes for the 4th Aug session are attached, also uploaded on the google drive.
     

    Attached Files:

    #124
  25. Pallavi_68

    Pallavi_68 Well-Known Member

    Joined:
    Jul 9, 2018
    Messages:
    78
    Likes Received:
    0
    package Day8;

    import org.testng.annotations.Test;
    import org.testng.annotations.BeforeMethod;
    import org.testng.annotations.AfterMethod;
    import java.util.concurrent.TimeUnit;
    import org.openqa.selenium.*;
    import org.openqa.selenium.chrome.ChromeDriver;

    public class DemoLogin {

    private WebDriver driver;
    private String baseUrl;
    @BeforeMethod
    public void beforeMethod() {
    System.setProperty("webdriver.chrome.driver","resource\\chromedriver.exe");//set the chrome driver
    driver = new ChromeDriver();
    baseUrl = "http://ec2-52-14-27-1.us-east-2.compute.amazonaws.com/ethnicstore/";
    //an implicit wait given for each command to search and object and perform operation on it
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    }
    @Test
    public void testLogin() throws Exception {
    driver.get(baseUrl);
    driver.findElement(By.linkText("My Account")).click();
    driver.findElement(By.name("email_address")).clear();
    driver.findElement(By.name("email_address")).sendKeys("abc@demo.com");
    driver.findElement(By.name("password")).clear();
    driver.findElement(By.name("password")).sendKeys("demo@123");
    driver.findElement(By.id("tdb1")).sendKeys("KEYS.ESC");
    driver.findElement(By.id("tdb1")).click();
    Thread.sleep(3000);
    driver.findElement(By.linkText("Log Off")).click();
    Thread.sleep(2000);
    driver.findElement(By.linkText("Continue")).click();
    }
    @AfterMethod
    public void afterMethod() {

    driver.close();
    }

    }
     
    #125
  26. Pallavi_68

    Pallavi_68 Well-Known Member

    Joined:
    Jul 9, 2018
    Messages:
    78
    Likes Received:
    0
    public class PrimeNumberChecker {

    //a number is prime if its divisible by 1 and itself and no other number.
    public Boolean validate(int number) {
    for (int i = 2; i < (number / 2); i++) {
    if (number % i == 0) {
    return false; // means the number is not prime
    }
    }
    return true; // means the number is prime.
    }
    }
     
    #126
  27. Pallavi_68

    Pallavi_68 Well-Known Member

    Joined:
    Jul 9, 2018
    Messages:
    78
    Likes Received:
    0
    /*
    * Created by: Pallavi
    * Function: Example of DataProvider with Prime number class
    */
    package Day8;

    import org.testng.Assert;
    import org.testng.Reporter;
    import org.testng.annotations.BeforeMethod;
    import org.testng.annotations.DataProvider;
    import org.testng.annotations.Test;

    public class ParamTestWithDataProvider1 {
    private PrimeNumberChecker primeNumberChecker;

    @BeforeMethod
    public void initialize() {
    primeNumberChecker = new PrimeNumberChecker();
    }

    @DataProvider(name = "test1")
    public static Object[][] primeNumbers() {
    return new Object[][] { { 2, true }, { 6, false }, { 19, true },
    { 22, true }, { 23, false } };
    }

    // This test will run 5 times since we have 5 parameters defined
    @Test(dataProvider = "test1")
    public void testPrimeNumberChecker(Integer inputNumber, Boolean expectedResult) {
    System.out.println(inputNumber + " " + expectedResult);
    //Reporter.log(inputNumber + " " + expectedResult);
    Assert.assertEquals(expectedResult,primeNumberChecker.validate(inputNumber));
    }
    }
     
    #127
  28. Pallavi_68

    Pallavi_68 Well-Known Member

    Joined:
    Jul 9, 2018
    Messages:
    78
    Likes Received:
    0
    import java.util.concurrent.TimeUnit;
    import org.openqa.selenium.By;
    import org.openqa.selenium.Keys;
    import org.openqa.selenium.OutputType;
    import org.openqa.selenium.TakesScreenshot;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.testng.Assert;
    import org.testng.annotations.BeforeClass;
    import org.testng.annotations.DataProvider;
    import org.testng.annotations.Test;
    import org.testng.annotations.AfterClass;


    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileReader;

    import org.testng.Reporter;
    import org.apache.commons.io.FileUtils;



    public class LoginLogoutParameterizeWithScreenshot{
    private WebDriver driver;
    private String baseUrl;
    private boolean acceptNextAlert = true;
    private StringBuffer verificationErrors = new StringBuffer();

    @BeforeClass
    public void setUp() throws Exception {
    System.setProperty("webdriver.gecko.driver","resource\\geckodriver.exe");
    driver = new FirefoxDriver();
    baseUrl = "http://ec2-52-14-27-1.us-east-2.compute.amazonaws.com/ethnicstore/";
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    }

    //Fetch Data From Database
    @DataProvider(name = "LoginData")
    public static Object[][] loginData() throws Exception {

    Object[][] Login = new Object[2][2];
    FileReader readerObj;
    BufferedReader bufReader;
    readerObj = new FileReader("datasets\\login.txt"); //stream object
    bufReader = new BufferedReader(readerObj); //input stream
    String line=bufReader.readLine(); //start reading the file line by line.
    int i=0;

    while(line!=null){ //read file until end of line is encountered.
    String [] data =line.split(","); //breaks the string using , and returns an array of substring
    Login[0]=data[0];
    Login[1]=data[1];
    i=i+1;
    line=bufReader.readLine();
    }
    return Login;


    }

    @Test(dataProvider = "LoginData")
    public void testRecordedLogin(String user, String pwd) throws Exception {
    driver.get(baseUrl);
    driver.findElement(By.cssSelector("#tdb3 > span.ui-button-text")).click();
    driver.findElement(By.name("email_address")).sendKeys(user);
    driver.findElement(By.name("password")).sendKeys(pwd);
    driver.findElement(By.id("tdb1")).sendKeys(Keys.ESCAPE);
    driver.findElement(By.id("tdb1")).click();
    Thread.sleep(3000);
    if(driver.getPageSource().contains("My Account Information")){
    File scrnsht = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
    String fname="valid-" + user+ ".jpg";
    FileUtils.copyFile(scrnsht, new File(fname));
    driver.findElement(By.linkText("Log Off")).click();
    Thread.sleep(2000);
    driver.findElement(By.linkText("Continue")).click();
    Assert.assertTrue(true, "User is valid");
    Reporter.log("Valid User");
    }else{
    File scrnsht = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
    String fname="invalid-" + user+ ".jpg";
    FileUtils.copyFile(scrnsht, new File(fname));
    Assert.fail("User is Invalid");
    Reporter.log("InValid User");
    }

    }

    @AfterClass
    public void tearDown() throws Exception {
    driver.quit();

    }
    }
     
    #128
  29. Pallavi_68

    Pallavi_68 Well-Known Member

    Joined:
    Jul 9, 2018
    Messages:
    78
    Likes Received:
    0
    Please find the notes and code attached in here. also uploaded the same on the google drive. Thanks.
     

    Attached Files:

    #129
  30. _28926

    _28926 New Member
    Alumni

    Joined:
    Apr 11, 2018
    Messages:
    1
    Likes Received:
    0
    Hi Pallavi,

    Uploading Day1 assignment. Please let me know the feedback.


    Thanks,
    Divya
     

    Attached Files:

    #130
  31. Eric States

    Eric States Member

    Joined:
    Jun 25, 2018
    Messages:
    14
    Likes Received:
    1
    So far I'm having a good deal of trouble figuring out what I need to do to convert my existing scripts into POM and TestNG scripts... it's rather frustrating. I hope I catch on soon, since we're not supposed to be turning in scripts written the way we have been doing them up until now, and that's the only way I'm able to write things that aren't just a pile of errors, unfortunately.
    Feeling the time pressure, unfortunately. Cannot even manage to convert the login script to POM-

    POM is when there's one script assigning all used objects on a page to their own variables, then has methods using those variables to perform actions on the page, correct? And the TestNG script should just be making method calls to that?

    I think I'm missing how/whether to import and/or declare an instance of the POM script in the TestNG script.
     
    #131
  32. _34668

    _34668 Member

    Joined:
    Jul 13, 2018
    Messages:
    12
    Likes Received:
    0
    Hi Ravi,
    Can you please post the scenarios you mentioned for the project?

    Thanks,
    Kavitha
     
    #132
  33. Pallavi_68

    Pallavi_68 Well-Known Member

    Joined:
    Jul 9, 2018
    Messages:
    78
    Likes Received:
    0
    Looks fine to me Divya. Hope you have started working on the project too.
     
    #133
  34. Pallavi_68

    Pallavi_68 Well-Known Member

    Joined:
    Jul 9, 2018
    Messages:
    78
    Likes Received:
    0
    Eric, its not at all complicated. not to feel pressure, please keep both versions available. so that just in case we struggle with submitting POM and TestNG we can submit the other thing.


    A junit program can be converted into testng by simply replacing the import statements and changing the @Before annotation of junit to @BeforeMethod.


    We already have completed one POM implementation of project for login logout so you have 1/4th done. All you need to do is in the calling file replace it with testng imports and in the testng.xml file call that class.


    And Ravi has made it simpler to allow both hard coded and dynamic approach. so if you are not able to create POM for the scenario of register user and buy product leave them as it is , but i think you can convert them into testng. You already have automated buy product scenario if i remember it correctly.

    To summarize -

    a. Covert the junit files to testng, by just replacing imports and annotation.
    b. if possible create pom file for scenarios, we have already done login logout.

    this should be able to help you i believe.
     
    #134
  35. Eric States

    Eric States Member

    Joined:
    Jun 25, 2018
    Messages:
    14
    Likes Received:
    1
    Thank you.

    I think I just needed a day's break from thinking about it- I now think I know how I'll be structuring the tests, with each test as its own TestNG script, which calls methods from POM scripts to perform its steps, and with the XML file grouping these test scripts into functional areas. The details of how I will do this will require a good close look from me, and I'll come here if I still have any questions after that.

    For now, I went ahead and wrote my 5th functional area out in the JUnit style, just so I'd have the code there and tested to be working before copy-pasting and converting it with the others.
     
    #135
  36. Smita Kalita

    Smita Kalita Member

    Joined:
    Jul 31, 2018
    Messages:
    3
    Likes Received:
    0
    Hi Ravi,
    I am not able to see the recording for 5th Aug in simplilearn and can you please share all the details regarding project in mail as discussed.
     
    #136
  37. Pallavi_68

    Pallavi_68 Well-Known Member

    Joined:
    Jul 9, 2018
    Messages:
    78
    Likes Received:
    0
    great. keep it up.
     
    #137
  38. Pallavi_68

    Pallavi_68 Well-Known Member

    Joined:
    Jul 9, 2018
    Messages:
    78
    Likes Received:
    0
    Mail from Ravi was sent to you all to your respective email addresses. here's is the copy-


    Hi Testers,

    We have covered the WebDriver 3.0 with all the 7 locators to find any element on the webpage. Also, we have understood the Testing as well.

    Now it is the perfect time to work on your project. Use all the locators to work the below mentioned functional areas.
    1) SignUp or Create Account
    2) Login and change profile settings like name, age, DOB etc.
    3) Selecting item and adding to the Cart.
    4) Search activity for items.
    Now, you can go ahead with hard coded or dynamic approach.
    For Testing, as I have already informed that on the automation scripts itself you have to write test cases or on the click operation for buttons, you can write test cases to check whether the required field are filled or not or any wrong data is filled.
    => We will have quick project discussion again in the next session to check your project status and solving your query. However, please post all your queries and errors in the thread created for the batch in the community forum.
    Lets get this done before next week guys [​IMG]

    Best Regards,
    Ravi Tulsiani
    GTA - Software Development & Agile and Scrum
    Simplilearn
     
    #138
  39. Eric States

    Eric States Member

    Joined:
    Jun 25, 2018
    Messages:
    14
    Likes Received:
    1
    I don't seem to know how to import and call methods from callBrowser to open a page before testing, unfortunately.
    I tried adding the openBrowser() method to the start of a createUser script, but I'm not sure if this is how I should be doing it.
    All my tests are written, I'm just trying to figure out what a working conversion from JUnit to TestNG should look like.

    Also:

    createValidAccount createvalid = new createValidAccount();

    @Test (groups = { "createUser" })
    public void createUser1() {
    createvalid.openBrowser("FF" "http://ec2-52-14-27-1.us-east-2.compute.amazonaws.com/ethnicstore/");
    }

    Trying to narrow down what's wrong here, when I try to call the createValidAccount test to open with Firefox and to the specified URL. (createValidAccount uses the same opening method as CallBrowser from day 8 did, but with "driver.get(baseurl)" added to the end of it.)

    UPDATE: Figured it out- I needed a comma there between the two parameters for createValid.openBrowser().

    But now I am looking at this method call:

    createInvalid.invalidAccountCreation();

    ...and it's saying "unhandled exception type Exception", and suggesting I add a Throws declaration or surround it with Try/Catch. If I try "throws", the error message changes to "the left-hand side of an assignment must be a variable."
    Not sure what to do with that message.

    UPDATE again: Looks like I just had to add "throws Exception" at the createUser1() method these methods were being called from.
     
    #139
    Last edited: Aug 8, 2018
  40. Eric States

    Eric States Member

    Joined:
    Jun 25, 2018
    Messages:
    14
    Likes Received:
    1
    Apologies for posting like crazy today- I've figured out how to get a somewhat-untidy but still working group of tests partially together in an "EthnicFinalGroups" script, but realized I am drawing a blank on how the XML should look.

    Should the groups and tests be formatted like this:

    <groups>
    <run>
    <include name="Group1"/>
    <include name="Group2"/>
    </run>
    </groups>
    <test name="Group1Test1">
    <test name="Group1Test2">
    <classes>
    <class name="ClassCalledByGroup1Tests"/>
    </classes>

    ... or should groups and tests be organized differently in the XML file?
     
    #140
  41. Smita Kalita

    Smita Kalita Member

    Joined:
    Jul 31, 2018
    Messages:
    3
    Likes Received:
    0
    Hi Pallavi,
    I was trying to combine all the concept e.g. POM,tesNG,screenshot for login logout scenario but I am getting error as ...
    Cannot inject @Test annotated Method [Validlogin] with [class java.lang.String, class java.lang.String].

    While doing separately all the concept it is working fine.Can you please help checking the code. PFA the code in notepad.
     

    Attached Files:

    #141
  42. Pallavi_68

    Pallavi_68 Well-Known Member

    Joined:
    Jul 9, 2018
    Messages:
    78
    Likes Received:
    0
    Eric, if you have a look at the LoginLogout POM created, the driver instance was created in the calling class, which was then passed to the POM class objects, so please use that.
    In the testng xml file it should be a simple file with the suite and 5 classes, where each class represents the calling code. No need to make any groups etc. Keep it simple.

    hope this helps.
     
    #142
  43. Pallavi_68

    Pallavi_68 Well-Known Member

    Joined:
    Jul 9, 2018
    Messages:
    78
    Likes Received:
    0

    Smita, your test method is taking input arguments, - public void Validlogin(String user, String pwd) throws Exception {

    but you are not passing them in any manner like either using @PArameters or @DataProvider annotation, so either use that or remove these input arguments.

    hope this helps.
     
    #143
  44. Pallavi_68

    Pallavi_68 Well-Known Member

    Joined:
    Jul 9, 2018
    Messages:
    78
    Likes Received:
    0
    All, please note that as per the email sent by Ravi for project submission guidelines, both hardcoded and dynamic approach of project submission is acceptable. So incase you are finding issue with POM, or picking data from external file, please do not use them.

    i hope by now you all should have comfortably available working junit scripts of the 5 functional areas for project submission.

    Converting a junit script to testng, requires only changing the annotation and import files. And then create one testng suite file which calls the 5 functional classes where each represents your scenario. This should be great for submission.

    you can also have some scenarios with pom, parameter, screenshot, assertion and some with hardcoded information , this is acceptable.
    just have all your files using one unit test framework either junit or testng and working.

    if your work is done, please go ahead and submit the project so that Ravi can start evaluating.

    If anyone is facing any trouble, please do let me know by posting on community.
     
    #144
  45. Eric States

    Eric States Member

    Joined:
    Jun 25, 2018
    Messages:
    14
    Likes Received:
    1
    Thank you for your reply. The XML was pretty simple to do after all, then.
    I did what you said and converted the JUnit files to TestNG, and they work.

    However, I had not been creating the WebDriver instance in the class that calls all the other classes- so I will try and rewrite it so they don't all have their own "openBrowser()" method, instead letting the class that's calling the other five classes do that.

    Am I understanding this correctly?

    I have an XML file that looks like:
    <?xml version="1.0" encoding="UTF-8"?>
    <suite name="EthnicStoreFinal" parallel="none">
    <test name="EthnicStoreTest">
    <groups>
    <run>
    <include name="Account Creation"/>
    <include name="Login and Account"/>
    <include name="Search Tests"/>
    <include name="Making Purchases"/>
    </run>
    </groups>
    <classes>
    <class name="EthnicStoreFinal.EthnicFinalGroups"/>
    </classes>
    </test> <!-- Test -->
    </suite> <!-- Suite -->

    and the "EthnicFinalGroups" class has a method for each test performed.
    Each of its test methods calls one other class's methods to perform test steps.
    (And these classes it's calling are the ones I converted from JUnit to TestNG.)

    Is this the correct structure for the suite?
     
    #145
  46. Pallavi_68

    Pallavi_68 Well-Known Member

    Joined:
    Jul 9, 2018
    Messages:
    78
    Likes Received:
    0
    Eric

    This is also correct. But you can make it simple also, where each class is a test, and the suite directly calls the set. so what i am suggesting is, this

    suite name="EthnicStoreFinal" parallel="none">
    <test name="EthnicStoreTest">

    <classes>
    <class name="accountcreation"/>
    <class name="loginlogout"/>
    <class name="searchproduct"/>
    ..
    ..
    </classes>
    </test> <!-- Test -->
    </suite> <!-- Suite -->

    your every test can have their own open browser method , which is basically our @BeforeMethod where we setup the driver and in the @Test annotation we say driver.get(url), and then you move forward with either direct code or calling pom classes as you feel like it.

    if what you have done works this is also fine with submission, rather your's is a level higher, you are moving towards framework design. but if things get complicated resort to simplicity due to time constraint.

    let me know if this helps and if you have any more queries.
     
    #146
  47. Eric States

    Eric States Member

    Joined:
    Jun 25, 2018
    Messages:
    14
    Likes Received:
    1
    Thanks again. I think my project may be ready to submit- but I'll take another look at it just to be sure.
    I've kept each of the classes with its own openBrowser() method, and have added a group for a fifth functional area, since I'm not sure whether we're to turn in four functional areas or five, having heard both at one time or another.

    My tests cover creating a new account (invalid/missing post code and valid/including post code), logging in (invalid username & password/supposed to fail, valid name & password, edit account information, and log out), running a search (typing a search and verifying the number of results, checking the Advanced Search page has a Search Help link which, if clicked, creates a pop-up message with certain text in its title bar), adding to cart (adding an item from each of 3 categories to the cart, verifying the max quantity one item can have is 99, verifying the item can be removed from the cart, and that the order confirmation page appears when successfully placed) and the fifth area, writing a review (sub-50 character review & checking for error message, and over-50 character review submitting correctly).

    I think I covered everything with these. Was there anything I might have missed?
     
    #147
  48. _32393

    _32393 Member

    Joined:
    Jun 15, 2018
    Messages:
    2
    Likes Received:
    0
    I am not able to write the code to select radio button on account creation page. Can you please help.
     
    #148
    Last edited: Aug 11, 2018 at 1:59 AM
  49. Eric States

    Eric States Member

    Joined:
    Jun 25, 2018
    Messages:
    14
    Likes Received:
    1
    At least for clicking the "Male" radio button, I found that just using findElement "by name" and adding ".click" at the end will select the first radio button. For selecting the "Female" radio button, there was definitely something else to add. (It's still early morning for me, so I'll go to look that up after breakfast.)
     
    #149
  50. _32239

    _32239 Member

    Joined:
    Jun 14, 2018
    Messages:
    9
    Likes Received:
    0
    Hi Pallavi ,


    due to Sudden emergency , i was not able to attend the last week session and dont think that i would be able to finish the project by tomorrow . Could you let me know as what to do ?

    regards
    Prashanth
     
    #150

Share This Page