URL未通过跨浏览器测试代码selenium传递

时间:2016-03-23 05:44:30

标签: java selenium testng

我正在尝试编写用于在两个浏览器和Chrome浏览器上进行测试的代码,两个浏览器都已打开但是URL没有被传递。
需要帮助才能进一步开展工作,谢谢。

WebDriver driver;

    @BeforeTest
    @Parameters("browser")

    public void setup(String browser) throws Exception {

        if (browser.equalsIgnoreCase("firefox")) {

            driver = new FirefoxDriver();

            driver.manage().window().maximize();

        } else if (browser.equalsIgnoreCase("chrome")) {

            System.setProperty("webdriver.chrome.driver", "E:\\disha.shah/myWork/eclipse/chromedriver.exe");
            driver = new ChromeDriver();

            driver.manage().window().maximize();


        } else {
            throw new Exception("Browser is not correct");

        }

        // driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    }

    @Test
    @Parameters({ "username", "password" })
    public void login(String username, String password) throws InterruptedException {

        driver.get("url goes here");
        driver.findElement(By.id("UserName")).sendKeys(username);
        driver.findElement(By.id("Password")).sendKeys(password);
        driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        driver.findElement(By.id("btnLogin")).sendKeys(Keys.RETURN);
    }
}

这是XML文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="Sample Test Suite" verbose="3" thread-count="2"
    parallel="methods">
    <test name="ChromeTest">

        <parameter name="browser" value="Chrome" />
        <classes>
            <class name="testngDemo.Login">
                <methods>
                    <include name="setup"></include>
                </methods>
            </class>
        </classes>

    </test>

    <test name="FirefoxTest">
        <parameter name="browser" value="Firefox" />
        <classes>
            <class name="testngDemo.Login">
                <methods>
                    <include name="setup"></include>
                </methods>
            </class>
        </classes>
    </test>

    <test name="Login Test">
        <parameter name="username" value="dishashah" />
        <parameter name="password" value="disha1234" />
        <classes>
            <class name="testngDemo.Login">
                <methods>
                    <include name="login"></include>

                </methods>
            </class>
        </classes>
    </test>
</suite>

1 个答案:

答案 0 :(得分:0)

问题在于testng.xml文件。我对上面的testng.xml文件做了一些更改。 see the updated xml here