estoy por mi cuenta intentado realizar un framework con cucumber en Selenium de un carrito de la compra de Amazon.
Test_Steps
package stepDefinition;
import managers.PageObjectManager;
import PageObjects.CartPage;
import PageObjects.HomePage;
import PageObjects.ProductListingPage;
import io.cucumber.java.en.And;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class Test_Steps {
private static WebElement Nombregrafica;
private static WebElement movil;
private String mov11;
private String mov21;
private String graficanm;
private String graficanm2;
WebDriver driver;
HomePage homePage;
ProductListingPage productListingPage;
CartPage cartPage;
PageObjectManager pageObjectManager;
@Given("User is on Home Page")
public void user_is_on_Home_Page() {
System.setProperty("webdriver.chrome.driver", ".//target//Drivers//chromedriver.exe");
// Creamos una nueva instancia de Google Chrome
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize() ;
// Guardamos la página web en una variable para poder llamarla y abrirla
homePage = pageObjectManager.getHomePage();
homePage.navigateTo_HomePage();
}
@When("User search product")
public void user_search_product() {
// Ahora en el motor de busqueda escribimos lo que queremos buscar
homePage = pageObjectManager.getHomePage();
homePage.txtboxsearch1();
// Ahora presionamos en la busqueda anteriorimente realizada
productListingPage = pageObjectManager.getProductListingPage();
productListingPage.searchproduct();
Nombregrafica = driver.findElement(By.linkText("Gigabyte Technology GeForce RTX 2060 OC GV-N2060OC-6GD - Tarjeta grafica, Negro"));
graficanm = Nombregrafica.getText();
productListingPage.clickfirstproduct();
}
@And("User add product to shopping cart and move to Home Page")
public void user_add_product_to_shopping_cart_and_move_to_Home_Page() {
// Añadimos a la Cesta
ProductListingPage productListingPage = new ProductListingPage(driver);
productListingPage.clickadd_cart1();
// Volvemos a la pagina principal
homePage = pageObjectManager.getHomePage();
homePage.navigateTo_HomePage();
}
@When("User search another product")
public void user_search_another_product() {
// Segunda Busqueda
// Ahora en el motor de busqueda escribimos lo que queremos buscar
homePage = pageObjectManager.getHomePage();
homePage.txtboxsearch2();
// Ahora presionamos en la busqueda anteriorimente realizada
productListingPage =pageObjectManager.getProductListingPage();
productListingPage.searchproduct();
movil = driver.findElement(By.linkText("AMD YD2600BBAFBOX, Procesador RYZEN5 2600 Socket AM4 3.9Ghz Max Boost, 3,4Ghz Base+19MB"));
mov11 =movil.getText();
productListingPage.clicksecondproduct();
}
@And("User add product to shopping cart")
public void user_add_product_to_shopping_cart() {
// Añadimos a la cesta
productListingPage = pageObjectManager.getProductListingPage();
productListingPage.clickONadd_cart2();
}
@Then("User checks that the products have been added to the shopping cart")
public void user_checks_that_the_products_have_been_added_to_the_shopping_cart() {
// Observamos la cesta de que efectivamente se ha añadido los productos
cartPage = pageObjectManager.getCartPage();
cartPage.clickcheckcart();
// Comprobamos que los productos son correctos
WebElement mov2 = driver.findElement(By.linkText("AMD YD2600BBAFBOX, Procesador RYZEN5 2600 Socket AM4 3.9Ghz Max Boost, 3,4Ghz Base+19MB"));
mov21= mov2.getText();
WebElement grafica2 = driver.findElement(By.linkText("Gigabyte Technology GeForce RTX 2060 OC GV-N2060OC-6GD - Tarjeta grafica, Negro"));
graficanm2 = grafica2.getText();
Assert.assertEquals(mov11,mov21);
Assert.assertEquals(graficanm,graficanm2);
}
}
Y este es mi PageObjectManager
package managers;
import PageObjects.CartPage;
import PageObjects.HomePage;
import PageObjects.ProductListingPage;
import org.openqa.selenium.WebDriver;
public class PageObjectManager {
WebDriver driver;
private HomePage homePage;
private ProductListingPage productListingPage;
private CartPage cartPage;
public PageObjectManager(WebDriver driver){
this.driver = driver;
}
public HomePage getHomePage() {
return (homePage == null) ? homePage= new HomePage(driver): homePage;
}
public ProductListingPage getProductListingPage() {
return (productListingPage == null) ? productListingPage= new ProductListingPage(driver) :productListingPage;
}
public CartPage getCartPage(){
return (cartPage == null) ? cartPage = new CartPage(driver) : cartPage;
}
}
Cuando intento correr el Test me da este error,
"C:\Program Files\Java\jdk1.8.0_231\bin\java.exe" -ea -DnodeNamesHandler=AsText -Didea.test.cyclic.buffer.size=1048576 "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.3\lib\idea_rt.jar=61737:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.3\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.3\lib\idea_rt.jar;C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.3\plugins\junit\lib\junit5-rt.jar;C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.3\plugins\junit\lib\junit-rt.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_231\jre\lib\rt.jar;C:\Users\Usuario\IdeaProjects\SeleniumCucumberV.1\target\test-classes;C:\Users\Usuario\IdeaProjects\SeleniumCucumberV.1\target\classes;C:\Users\Usuario\.m2\repository\org\seleniumhq\selenium\selenium-java\3.141.59\selenium-java-3.141.59.jar;C:\Users\Usuario\.m2\repository\org\seleniumhq\selenium\selenium-api\3.141.59\selenium-api-3.141.59.jar;C:\Users\Usuario\.m2\repository\org\seleniumhq\selenium\selenium-chrome-driver\3.141.59\selenium-chrome-driver-3.141.59.jar;C:\Users\Usuario\.m2\repository\org\seleniumhq\selenium\selenium-edge-driver\3.141.59\selenium-edge-driver-3.141.59.jar;C:\Users\Usuario\.m2\repository\org\seleniumhq\selenium\selenium-firefox-driver\3.141.59\selenium-firefox-driver-3.141.59.jar;C:\Users\Usuario\.m2\repository\org\seleniumhq\selenium\selenium-ie-driver\3.141.59\selenium-ie-driver-3.141.59.jar;C:\Users\Usuario\.m2\repository\org\seleniumhq\selenium\selenium-opera-driver\3.141.59\selenium-opera-driver-3.141.59.jar;C:\Users\Usuario\.m2\repository\org\seleniumhq\selenium\selenium-remote-driver\3.141.59\selenium-remote-driver-3.141.59.jar;C:\Users\Usuario\.m2\repository\org\seleniumhq\selenium\selenium-safari-driver\3.141.59\selenium-safari-driver-3.141.59.jar;C:\Users\Usuario\.m2\repository\net\bytebuddy\byte-buddy\1.8.15\byte-buddy-1.8.15.jar;C:\Users\Usuario\.m2\repository\org\apache\commons\commons-exec\1.3\commons-exec-1.3.jar;C:\Users\Usuario\.m2\repository\com\google\guava\guava\25.0-jre\guava-25.0-jre.jar;C:\Users\Usuario\.m2\repository\com\google\code\findbugs\jsr305\1.3.9\jsr305-1.3.9.jar;C:\Users\Usuario\.m2\repository\org\checkerframework\checker-compat-qual\2.0.0\checker-compat-qual-2.0.0.jar;C:\Users\Usuario\.m2\repository\com\google\errorprone\error_prone_annotations\2.1.3\error_prone_annotations-2.1.3.jar;C:\Users\Usuario\.m2\repository\com\google\j2objc\j2objc-annotations\1.1\j2objc-annotations-1.1.jar;C:\Users\Usuario\.m2\repository\org\codehaus\mojo\animal-sniffer-annotations\1.14\animal-sniffer-annotations-1.14.jar;C:\Users\Usuario\.m2\repository\com\squareup\okhttp3\okhttp\3.11.0\okhttp-3.11.0.jar;C:\Users\Usuario\.m2\repository\com\squareup\okio\okio\1.14.0\okio-1.14.0.jar;C:\Users\Usuario\.m2\repository\org\seleniumhq\selenium\selenium-support\3.141.59\selenium-support-3.141.59.jar;C:\Users\Usuario\.m2\repository\junit\junit\4.12\junit-4.12.jar;C:\Users\Usuario\.m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;C:\Users\Usuario\.m2\repository\io\cucumber\cucumber-java\4.7.2\cucumber-java-4.7.2.jar;C:\Users\Usuario\.m2\repository\io\cucumber\cucumber-core\4.7.2\cucumber-core-4.7.2.jar;C:\Users\Usuario\.m2\repository\io\cucumber\gherkin\5.1.0\gherkin-5.1.0.jar;C:\Users\Usuario\.m2\repository\io\cucumber\tag-expressions\1.1.1\tag-expressions-1.1.1.jar;C:\Users\Usuario\.m2\repository\io\cucumber\cucumber-expressions\7.0.2\cucumber-expressions-7.0.2.jar;C:\Users\Usuario\.m2\repository\io\cucumber\datatable\1.1.14\datatable-1.1.14.jar;C:\Users\Usuario\.m2\repository\io\cucumber\datatable-dependencies\1.1.14\datatable-dependencies-1.1.14.jar;C:\Users\Usuario\.m2\repository\org\apiguardian\apiguardian-api\1.1.0\apiguardian-api-1.1.0.jar;C:\Users\Usuario\.m2\repository\info\cukes\cucumber-java\1.2.5\cucumber-java-1.2.5.jar;C:\Users\Usuario\.m2\repository\info\cukes\cucumber-core\1.2.5\cucumber-core-1.2.5.jar;C:\Users\Usuario\.m2\repository\info\cukes\cucumber-html\0.2.3\cucumber-html-0.2.3.jar;C:\Users\Usuario\.m2\repository\io\cucumber\cucumber-junit\4.7.2\cucumber-junit-4.7.2.jar;C:\Users\Usuario\.m2\repository\info\cukes\cucumber-jvm-deps\1.0.5\cucumber-jvm-deps-1.0.5.jar;C:\Users\Usuario\.m2\repository\info\cukes\gherkin\2.12.2\gherkin-2.12.2.jar;C:\Users\Usuario\.m2\repository\org\picocontainer\picocontainer\2.15\picocontainer-2.15.jar" com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit4 cucumbertest.TestRunner
Starting ChromeDriver 78.0.3904.70 (edb9c9f3de0247fd912a77b7f6cae7447f6d3ad5-refs/branch-heads/3904@{#800}) on port 46576
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to
prevent access by malicious code.
[1576923269.778][WARNING]: This version of ChromeDriver has not been
tested with Chrome version 79.
[1576923271.784][WARNING]: Timed out connecting to Chrome, retrying...
dic 21, 2019 11:14:33 AM org.openqa.selenium.remote.ProtocolHandshake
createSession
INFORMACIÓN: Detected dialect: W3C
[1576923275.832][WARNING]: Timed out connecting to Chrome, retrying...
java.lang.NullPointerException
at stepDefinition.Test_Steps.user_is_on_Home_Page(Test_Steps.java:37)
at ✽.User is on Home Page(file:src/test/resources/carrito.feature:5)
Process finished with exit code -1
Este es mi
HomePage
package PageObjects;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
import org.openqa.selenium.support.PageFactory;
public class HomePage{
WebDriver driver;
public HomePage(WebDriver driver) {
this.driver = driver;
PageFactory.initElements(driver, this);
}
@FindBy (how = How.ID,using = "twotabsearchtextbox")
private WebElement txtboxsearch;
public void txtboxsearch1() {
txtboxsearch.sendKeys("Gigabyte 2060 RTX");
}
public void txtboxsearch2(){
txtboxsearch.sendKeys("Ryzen 5 2600");
}
public void navigateTo_HomePage() {
driver.get("https://www.amazon.es/");
}
package PageObjects;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
import org.openqa.selenium.support.PageFactory;
public class HomePage{
WebDriver driver;
public HomePage(WebDriver driver) {
this.driver = driver;
PageFactory.initElements(driver, this);
}
@FindBy (how = How.ID,using = "twotabsearchtextbox")
private WebElement txtboxsearch;
public void txtboxsearch1() {
txtboxsearch.sendKeys("Gigabyte 2060 RTX");
}
public void txtboxsearch2(){
txtboxsearch.sendKeys("Ryzen 5 2600");
}
public void navigateTo_HomePage() {
driver.get("https://www.amazon.es/");
}
}
Y este mi testRunner
package cucumbertest;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;
import io.cucumber.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(
features = "src/test/resources"
,glue ={"stepDefinition"}
)
public class TestRunner {
}
Si no implemento el PageObjectManager, no me da error, por eso supongo que le problema esta en la relación entre uno y otro.
El error me da siempre el mismo, este caso me da desde que empiezo intentando llevarlo a Amazon.
Soy nuevo en esto y me estoy buscando yo solo la vida con tutos y demás, así que perdón de antemano por cualquier error que pueda cometer. Gracias :)