Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 97771

Using result from Test 1 to start Test 2

$
0
0

I want to run 2 tests:

  1. Step 1 - open google, Step 2 - type in a search item, Step 3 - print out first entry

  2. Step 1 - user URL from Step 3 in Test 1, Step 2 - click url, Step 3 - verify a tag line

I cannot figure out how to use the URL from Test 1 to start my second Test

package test;

import cucumber.annotation.en.Given;
import cucumber.annotation.en.Then;
import cucumber.annotation.en.When;
import cucumber.annotation.en.And;
import gherkin.formatter.model.Scenario;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

import static org.junit.Assert.*;

import java.util.Collection;
import java.util.List;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.TimeUnit;
//import org.openqa.selenium.support.ui.ExpectedCondition;
//import org.openqa.selenium.support.ui.WebDriverWait;


public class MyTest {

private WebDriver driver;
private Object ExpectedConditions;
private Object MyTestHomePage;

@Given("I have a opened google in a web browser")
public void MyTest() {
    System.setProperty("webdriver.gecko.driver", "Driver/geckodriver.exe");
    driver = new FirefoxDriver();
    driver.get("https://www.google.co.uk/");
}

@When("I enter MyTest in search box")
public void TruNarrative_search() {
    WebElement searchButton = driver.findElement(By.name("q"));
    searchButton.sendKeys("mysearchitem");
    searchButton.sendKeys(Keys.RETURN);
}

@Then("I can identify MyTest as first entry")
public void MyTest_result() {
    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    List<WebElement> findElements = driver.findElements(By.cssSelector("MycssSelector"));
    for (WebElement webElement : findElements) {
        System.out.println(webElement.getAttribute("href"));
    }
}

public class MyTest2 {
    @Given("I have found the MyTest webpage via google")
    public void TMyTest_found() {
        driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        driver.findElement(By.cssSelector("MycssSelector"));
    }


    @When("I click on the link")
    public void MyTest_click() {
        driver.findElement(By.cssSelector("mycssSelector")).click();
    }

    @Then("I can identify the strap line “Blah Blah Blah.” Is found on the page")
    public void TruNarrative_tag() {
        WebElement tagLine = driver.findElement(By.cssSelector("h4.bigger[text()='Blah Blah Blah.']"));
        if (tagLine.isDisplayed()) {
            System.out.println("Element found");
        } else {
            System.out.println("Element not found");
        }


    }
}
}

Viewing all articles
Browse latest Browse all 97771

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>