简体   繁体   English

使用TestNG和Excel的Selenium WebDriver

[英]Selenium WebDriver using TestNG and Excel

Hello i really need help with Selenium WebDriver using TestNG and Excel 您好,我真的需要使用TestNG和Excel的Selenium WebDriver的帮助

i try to get data from excel to open browser and navigate URL. 我尝试从Excel获取数据以打开浏览器并浏览URL。 its work successfully and terminal and testng report showing test pass but its not open browser or doing anything its just run its self and show report 它的工作成功,并且终端和testng报告显示测试通过,但未打开浏览器或执行任何操作,只是运行自身并显示报告

Config File 配置文件

public void openBrowser(String browser){
        try {
            if (browser.equals("Mozilla")) {
                driver = new FirefoxDriver();
            } else if(browser.equals("IE")){
                driver = new InternetExplorerDriver();
            } else if(browser.equals("Chrome")){
                System.setProperty("webdriver.chrome.driver", "\\Applications\\Google Chrome.app\\Contents\\MacOS\\Google Chrome ");
                driver = new ChromeDriver();
            }
        } catch (Exception e) {

        }
    }


    public void navigate(String baseUrl){
        try {
            driver.manage().window().maximize();
            driver.manage().deleteAllCookies();
            driver.navigate().to(baseUrl);
        } catch (Exception e) {

        }
    }

And Test Execute File 并测试执行文件

public class NewTest {
    public String exPath = Config.filePath;
    public String exName = Config.fileName;
    public String exWrSheet = "Logiin Functional Test";
    public Config config;

    @BeforeTest
    public void openBrowser() {
        config = new Config();
        Excel.setExcelFile(exPath+exName, exWrSheet);
        String browser = Excel.getCellData(1, 2);
        config.openBrowser(browser);
    }

    @BeforeMethod
    public void navigate() {
        config = new Config();
        Excel.setExcelFile(exPath+exName, exWrSheet);
        String baseUrl = Excel.getCellData(2, 2);
        config.navigate(baseUrl);
    }

    @Test
    public void test() {
        System.out.println("Test");
    }

    @AfterTest
    public void closeBroser() {
        //Config.tearDown();
    }

I don't have quite enough rep to make a comment, which I would prefer here, but if you aren't getting any sort of exception, I'd suspect the value you're getting for the browser variable is not matching anything in your if-then-else in openBrowser and then falling through. 我没有足够的代表来发表评论,在这里我希望这样做,但是如果您没有任何异常,我怀疑您为浏览器变量获取的值与以下内容不匹配您的if-then-else,然后进入openBrowser。 Step through the code with a debugger or just add: 使用调试器单步执行代码或添加:

String browser = Excel.getCellData(1, 2);
System.out.println("Browser value from Excel =" + browser);
config.openBrowser(browser);

to see what you're reading from the file. 以查看您从文件中读取的内容。

1 - TestNg is always pass because you are using "void" method and you catch "all" exception 1-TestNg始终通过,因为您使用的是“ void”方法,并且捕获了“ all”异常

2 - No browser opened because in openBrowser(String browser), NullPointException throws and you already catch it. 2-没有打开浏览器,因为在openBrowser(String browser)中,NullPointException引发并且您已经捕获了它。

-> you need to init an instance of WebDriver and pass it through your test. ->您需要初始化WebDriver的实例并通过测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM