Not able to access Selenium.SetSpeed() method - selenium

Not able to access any methods in the Selenium class
import org.openqa.selenium.server.SeleniumServer;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;
public class login
{
public Selenium selenium;
public SeleniumServer seleniumserver;
#Before
public void setUp() throws Exception
{
seleniumserver=new SeleniumServer();
selenium=new DefaultSelenium("localhost",4444,"*iexplore","http://");
selenium.start();
}
#Test
public void testlogin() throws Exception
{
selenium.setSpeed("2000");
}
}
when i say selenium dot,the intellisense is not working,and not able to access any of the methods.
{

You have not given any URL. selenium.setSpeed('1000') provide 1 sec time delay between two selenium command. I dont know what you are trying to do.

Related

Getting as "Cannot invoke "org.openqa.selenium.WebDriver.findElement(org.openqa.selenium.By)" because "this.driver" is null."

I am trying to run a page object methods by cucumber. I am getting error out with driver null NPE errpr. Could you please help. I created Page Object Model file. A feature file describing scenario outline. And then in Test, I am trying to call the method by creating a object of Page Model java class
POM class:
package pages;
import javax.imageio.IIOException;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
public class Pom {
static WebDriver driver;
By username=By.xpath("//*[#id='user-name']");
By password=By.xpath("//*[#id='password']");
By loginbutton=By.xpath("//*[#id='login-button']");
By logout=By.xpath("//*[contains(text(),'Logout')]");
By open_menu=By.xpath("//*[contains(text(),'Open Menu')]");
public Pom(WebDriver driver)
{
this.driver=driver;
//if (!driver.getTitle().equals("Swag Labs")) {
//throw new IIOException("This is not the login page. The current url is " +driver.getCurrentUrl());
}
//}
public void enter_username(String username1)
{
driver.findElement(username).sendKeys(username1);
}
public void enter_password(String password1)
{
driver.findElement(password).sendKeys(password1);
}
public void click_login()
{
driver.findElement(loginbutton).click();
}
public void check_logout()
{
driver.findElement(logout).isDisplayed();
}
public void click_open_menu()
{
driver.findElement(open_menu).click();
}
}
StepDefination:
package StepDefinations;
import java.time.Duration;
import javax.imageio.IIOException;
import org.junit.BeforeClass;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import io.cucumber.java.en.*;
import io.github.bonigarcia.wdm.WebDriverManager;
import pages.Pom;
public class PomTest {
public WebDriver driver;
Pom pom=new Pom(driver);
#Given("User launches the browser")
public void user_launches_the_browser() {
// Write code here that turns the phrase above into concrete actions
WebDriverManager.chromedriver().setup();
driver=new ChromeDriver();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(3));
driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(6));
driver.manage().window().maximize();
}
#Given("user navigate to the Login landing Page")
public void user_navigate_to_the_login_landing_page() throws InterruptedException {
// Write code here that turns the phrase above into concrete actions
driver.navigate().to("https://www.saucedemo.com/");
Thread.sleep(3000);
}
#When("^User enters the credentials as (.+) and (.+) $")
public void user_enters_the_credentials_as_and(String username, String password) throws Throwable {
// Write code here that turns the phrase above into concrete actions
// pom=new Pom(driver);
pom.enter_username(username);
Thread.sleep(3000);
pom.enter_password(password);
Thread.sleep(3000);
}
#And("User clicks on the login button after entering credentials")
public void user_clicks_on_the_login_button_after_entering_credentials() {
pom.click_login();
}
#Then("User lands on the user account home page and checks the logout button")
public void user_lands_on_the_user_account_home_page_and_checks_the_logout_button() {
// Write code here that turns the phrase above into concrete actions
pom.click_open_menu();
pom.check_logout();
}
#Then("the user closes the browser")
public void the_user_closes_the_browser() {
// Write code here that turns the phrase above into concrete actions
driver.close();
}
}
Faeture File:
Feature: Login functionality Test
Scenario Outline: Verify the login of the user on the particvular website
Given User launches the browser
And user navigate to the Login landing Page
When User enters the credentials as <username> and <password>
And User clicks on the login button after entering credentials
Then User lands on the user account home page and checks the logout button
And the user closes the browser
Examples:
|username|password|
|standard_user|secret_sauce|
|locked_out_user|secret_sauce|
|problem_user|secret_sauce|
|performance_glitch_user|secret_sauce|
I am expecting this code to run in a data driven way.
#user3857859 , in your step definition file, move the initialization of pom object to inside #Given("User launches the browser"), after you initialize the driver. so after changes your #Given should look like below:
public WebDriver driver;
Pom pom;
#Given("User launches the browser")
public void user_launches_the_browser() {
// Write code here that turns the phrase above into concrete actions
WebDriverManager.chromedriver().setup();
driver=new ChromeDriver();
pom=new Pom(driver);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(3));
driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(6));
driver.manage().window().maximize();
}
this way, you not sending the driver without initializing to your Pom constructor.

Cannot create ExtentReport for Selenium 3.5.1

I have tried with almost all jar files with extentreport from 2.41.2 to
3.13.0 but whenever I try to write the command: extent.loadConfig(new
File(System.getProperty("user.dir")+"//ReportsConfig.xml")); it throws error on multiple lines but for instance i have put up one example
showing as "The method loadConfig(File) is undefined for the type
ExtentReports".
My code for ExtentReport Class is `enter code here`:
package TestNG_package;
import java.io.File;
import java.util.Date;
import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.reporter.AbstractReporter;
import com.aventstack.extentreports.reporter.ExtentHtmlReporter;
import com.aventstack.extentreports.reporter.configuration.ChartLocation;
import com.aventstack.extentreports.reporter.configuration.Theme;
public class ExtentManager
{
private static ExtentReports extent;
public static String screenshotFolderPath;
static ExtentHtmlReporter htmlReporter;
public static ExtentReports getInstance()
{
if (extent == null)
{
extent = new
ExtentReport("E:\\Selenium\\Workspace\\New_Test\\test-output\\report.html");
extent.loadConfig(new
File(System.getProperty("user.dir")+"//ReportsConfig.xml"));
extent.addSystemInfo("Selenium ver" ,
"3.5.1").addSystemInfo("Environ" , "PROD");
}
return extent;
}
}
My next part of code is to invoke ExtentReport in other class called
loginTest
public class LoginTest()
{
#Test
public void doLogin()
{
ExtentReport rep = ExtentManager.getInstance();
ExtentTest Test = rep.startTest("UATRMS start");
Test.log(LogStatus.Info,"Starting UATRMS Test");
rep.endTest(test);
rep.flush();
}
}
The correct method is
reporter.loadXMLConfig("extent-config.xml");
The method you are using is for instances where you have a properties file. See the docs for more info. This method is used by the reporter, not the core API. Reporters can be configured using these configuration items.

Intercept Error constructor with bytebuddy

For some reason I can't work out yet, my agent doesn't intercept java LinkageError instances.
Agent code:
import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.implementation.MethodDelegation;
import net.bytebuddy.implementation.SuperMethodCall;
import net.bytebuddy.matcher.ElementMatchers;
import java.lang.instrument.Instrumentation;
public class MyAgent {
public static void premain(String arguments, Instrumentation instrumentation) {
new AgentBuilder.Default()
.type(ElementMatchers.isSubTypeOf(LinkageError.class))
.transform((builder, type, classLoader, module) ->
builder.constructor(ElementMatchers.isDefaultConstructor())
.intercept(SuperMethodCall.INSTANCE.andThen(MethodDelegation.to(MyInterceptor.class)))
).installOn(instrumentation);
}
}
Interceptor code:
public class MyInterceptor {
#RuntimeType
public static void intercept(#Origin Constructor<?> constructor) throws Exception {
System.out.println("Intercepted: " + constructor.getName());
}
}
Test code:
public static void main(String[] args) {
new NoClassDefFoundError("should be intercepted!!!").toString();
new Foo("oh").toString();
}
What is puzzling is that replacing ElementMatchers.isSubTypeOf(LinkageError.class) with ElementMatchers.nameContains("Foo") gives the expected result and Foo constructor is intercepted.
The NoClassDefFoundError is loaded by the bootstrap loader. It willnot be able to see your interceptor class which is why it is never triggered.
Try using the Advice class (as a visitor) to add bytecode to matched classes which should resolve this problem.

What is Hybrid Driven and Keyword Driven in selenium?

Please give an example for Hybrid Driven and Keyword Driven using selenium. Thanks in advance!
Never heard about Hybrid driven testing, you might be referring to testing hybrid applications.
A hybrid application (hybrid app) is one that combines elements of
both native and Web applications. Native applications are developed
for a specific platform and installed on a computing device. Web
applications are generalized for multiple platforms and not installed
locally but made available over the Internet through a browser. Hybrid
apps are often mentioned in the context of mobile computing.
About Keyword driven testing, each keyword corresponds to an individual testing action like a mouse click, selection of a menu item, keystrokes, opening or closing a window or other actions. A keyword-driven test is a sequence of operations, in a keyword format, that simulate user actions on the tested application.
Posted below is a simple class for Hybrid (Modular and Data Driven) framework -
SearchData.java
Has the code for data to be used in the test.
package com.data;
public class SearchData {
private String url;
private String searchWord;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getSearchWord() {
return searchWord;
}
public void setSearchWord(String searchWord) {
this.searchWord = searchWord;
}
}
SearchPage.java
Contains modules of code.
package com.page;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import com.data.SearchData;
public class SearchPage {
WebDriver driver;
public SearchPage(WebDriver driver) {
this.driver = driver;
}
public void launchGoogle(SearchData searchData) {
driver.get(searchData.getUrl());
}
public void search(SearchData searchData) {
driver.findElement(By.name("q")).sendKeys(searchData.getSearchWord());
driver.findElement(By.name("btnG")).click();
}
}
GoogleTest.java
Contains the actual Junit Test.
package com.test;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import com.data.SearchData;
import com.page.SearchPage;
public class GoogleTest {
protected WebDriver driver;
#Before
public void setUp() {
driver = new FirefoxDriver();
}
#After
public void tearDown() {
driver.close();
driver.quit();
}
#Test
public void searchTest() throws InterruptedException {
// set the data
SearchData searchData = new SearchData();
searchData.setUrl("https://www.google.com");
searchData.setSearchWord("Selenium");
// call the methods
SearchPage searchPage = new SearchPage(driver);
searchPage.launchGoogle(searchData);
searchPage.search(searchData);
Thread.sleep(10000);
}
}
The above code is pretty basic and can be enhanced to a great extend.
As for Keyword driven framework use SELENIUM IDE / ROBOT FRAMEWORK.

Check links with getAllLinks

I´m testing application with selenium ide and rc. I need verify the links.
Usually I export file from Selenium ide to junit 4, and run file in eclipse. File is as next
package com.example.tests;
import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.regex.Pattern;
public class login_csupport extends SeleneseTestCase {
#Before
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://daisy-w2003.hi.inet/CustomerSupport");
selenium.start();
}
#Test
public void testLogin_csupport() throws Exception {
selenium.open("http://daisy-w2003.hi.inet/CustomerSupport/?ReturnUrl=%2fCustomerSupport%2fAccount");
assertEquals("Calling Cards Customer Support - Inicio", selenium.getTitle());
selenium.type("UserName", "admin");
selenium.type("Password", "admin");
selenium.click("//div[#id='content']/div/form/div[3]/a/span[2]");
selenium.waitForPageToLoad("30000");
assertEquals("Calling Cards Customer Support - Gestión", selenium.getTitle());
}
#After
public void tearDown() throws Exception {
selenium.stop();
}
}
Using getAllLinks I´d like check the links of the page. Please, anyone can to help me??
Thanks
assertAllLinks(pattern) generated from getAllLinks()
Returns:
the IDs of all links on the page
Returns the IDs of all links on the page.
If a given link has no ID, it will appear as "" in this array.