22
33import com .browserstack .TestRunner ;
44import com .browserstack .local .Local ;
5- import com .browserstack .pageobjects .SearchPage ;
5+ import com .browserstack .pageobjects .HomePage ;
66import com .browserstack .util .Utility ;
77import io .cucumber .java .After ;
88import io .cucumber .java .Before ;
2222import static org .junit .Assert .assertEquals ;
2323import static org .junit .Assert .assertTrue ;
2424
25- public class SearchSteps {
25+ public class StackDemoSteps {
2626 private WebDriver driver ;
27- private SearchPage searchPage ;
27+ private HomePage homePage ;
2828 private Local l ;
2929
3030 @ Before
@@ -36,13 +36,13 @@ public void setUp(Scenario scenario) throws Exception {
3636 caps .setCapability ("name" , scenario .getName ());
3737 if (caps .getCapability ("browserstack.local" )!=null && caps .getCapability ("browserstack.local" ).toString ().equals ("true" )) {
3838 l = new Local ();
39- Map <String , String > options = new HashMap <String , String >();
39+ Map <String , String > options = new HashMap <>();
4040 options .put ("key" , caps .getCapability ("browserstack.key" ).toString ());
4141 l .start (options );
4242 }
4343
4444 driver = new RemoteWebDriver (new URL (URL ), caps );
45- searchPage = new SearchPage (driver );
45+ homePage = new HomePage (driver );
4646 }
4747
4848 @ Given ("^I am on the website '(.+)'$" )
@@ -51,20 +51,21 @@ public void I_am_on_the_website(String url) throws Throwable {
5151 Thread .sleep (2000 );
5252 }
5353
54- @ When ("^I submit the search term '(.+)'$ " )
55- public void I_submit_the_search_term ( String searchTerm ) throws Throwable {
56- searchPage . enterSearchTerm ( searchTerm );
57- searchPage . submitSearch ();
54+ @ When ("^I select a product and click on 'Add to cart' button " )
55+ public void I_select_a_product_and_add_to_cart ( ) throws Throwable {
56+ homePage . selectFirstProductName ( );
57+ homePage . clickAddToCartButton ();
5858 Thread .sleep (2000 );
5959 }
6060
61- @ Then ("the page title should be '(.+)'$" )
62- public void I_should_see_pagetitle (String expectedTitle ) throws Throwable {
63- assertEquals (expectedTitle , driver .getTitle ());
61+ @ Then ("the product should be added to cart" )
62+ public void product_should_be_added_to_cart () {
63+ homePage .waitForCartToOpen ();
64+ assertEquals (homePage .getSelectedProductName (), homePage .getProductCartText ());
6465 }
6566
6667 @ Then ("the page should contain '(.+)'$" )
67- public void page_should_contain (String expectedTitle ) throws Throwable {
68+ public void page_should_contain (String expectedTitle ) {
6869 assertTrue (driver .getPageSource ().contains (expectedTitle ));
6970 }
7071
@@ -79,4 +80,4 @@ public void teardown(Scenario scenario) throws Exception {
7980 driver .quit ();
8081 if (l != null ) l .stop ();
8182 }
82- }
83+ }
0 commit comments