lundi 30 juillet 2018

Selenium Webdriver Function Continuity

So i have the following java code with a selenium webdrive code. The code works as intended untill the AddItems function. It does not work, I can't make it continue the work from the Login function. I've tried calling both function in the main, i've tried calling one AddItems into Login. I don't understand how i should link the two process so one continuies the other. I've tried what i've seen here: https://www.youtube.com/watch?v=ph3NJm4Z7m4&t=4472s , at 1:02:44 ish .

Please help me understand how can the function use the same "test" and continue the function.

package TestEmagShoppingCart;

import java.util.concurrent.TimeUnit;

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

public class ShoppingCart {

    WebDriver test;

    public void Login() throws InterruptedException

    {
        System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
        WebDriver test = new ChromeDriver();
        test.get("http://www.emag.ro");
        test.manage().window().maximize();
        //test.manage().deleteAllCookies();
        //test.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        //test.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);

        String title = test.getTitle();
        System.out.println("Titlul paginii este: "+ title);

        test.findElement(By.xpath("/html/body/div[3]/nav[1]/div/div/div[3]/div/div[2]/a/span")).click();
        test.findElement(By.id("email")).sendKeys("anghelalex1994@gmail.com");
        Thread.sleep(1000);
        test.findElement(By.xpath("/html/body/form/div[4]/div/button")).click();
        Thread.sleep(1000);
        test.findElement(By.id("password")).sendKeys("alex21");
        test.findElement(By.xpath("/html/body/form/div[4]/div/button")).click();
        //test.findElement(By.xpath("/html[1]/body[1]/div[3]/div[1]/div[1]/div[1]/ul[1]/li[5]/a[1]")).click();
        //AddItems();
    }

    public void AddItems()
    {

        test.findElement(By.xpath("/html[1]/body[1]/div[3]/div[1]/div[1]/div[1]/ul[1]/li[5]/a[1]")).click();
    }

    public static void main(String[] args) throws InterruptedException {

        ShoppingCart cart = new ShoppingCart();
        cart.Login();
        cart.AddItems();

    }

}

Aucun commentaire:

Enregistrer un commentaire