2

I'm new to QA testing.

I was practicing automating test case in TestNg, but can't seem to get the cross browsers to work. The test keeps failing.

It worked when it was just one browser. Any suggestions or correcting this will be much appreciated!

Here's what I did:

package mkaprojecttest.mkaprojecttest;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterMethod;
import atu.testrecorder.exceptions.ATUTestRecorderException;
import org.testng.annotations.Parameters;

public class loginNewToursTest {    
EdgeDriver driver;
ChromeDriver driver2;
@test
public void loginNewTours_Test() throws  
InterruptedException, ATUTestRecorderException
{
driver.get("newtours.demoaut.com");
Thread.sleep(3000);      
  driver.findElementByName("userName").sendKeys("testinglogin1");
  Thread.sleep(4000);     
  driver.findElementByName("password").sendKeys("nopass");
  Thread.sleep(4000);
  driver.findElementByName("login").click();
  Thread.sleep(4000);
    }
@BeforeMethod
@Parameters("browser")
public void setup(String browser) throws Exception

{
  if(browser.equalsIgnoreCase("Edge"))
  {  
      System.setProperty("webdriver.Edge.driver2", "none");
      driver = new EdgeDriver();
  }
  else if(browser.equalsIgnoreCase("Chrome"))
  {       
      System.setProperty("webdriver.chrome.driver",  
      "C:\\Users\\thaq2\\Desktop\\chromedriver.exe");
      driver2 = new ChromeDriver();
  
  }
  else{
      throw new Exception("browser is not correct");
  }
}
@AfterMethod
public void afterMethod() {
  driver.close();
  driver.quit();
  }
}

XML:

**

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite">
<parameter name="browser" value="Edge"/>
<parameter name="browser" value="Chrome"/>
  <test thread-count="5" name="Test">
    <classes>
      <class name="mkaprojecttest.mkaprojecttest.loginNewToursTest"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

1 Answer 1

1

Your edge driver has no location where the program is:

System.setProperty("webdriver.Edge.driver2", "none"); # -< "None"
driver = new EdgeDriver();

Unlike your definition of Chrome which specifies it

System.setProperty("webdriver.chrome.driver",  
"C:\\Users\\thaq2\\Desktop\\chromedriver.exe"); -< specifies it
driver2 = new ChromeDriver();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.